Question

Translate the following code into MIPS code. Test (int i, int j)                         {        &nbsp

Translate the following code into MIPS code.

Test (int i, int j)

                        {

                        int k;

                        k = Double(i+1) + Double (j-10)

                        return k;

                        }

Sub (int m)

                        {

                        int g;

                        g = m + m;

                        return g;

                        }

Assume the compiler associates the variable k to the register $s0. Assume the compiler associates the variable g to the register $t0.

0 0
Add a comment Improve this question Transcribed image text
Answer #1

MIPS Code:

.file   1 ""
        .section .mdebug.abi32
        .previous
        .nan    legacy
        .module fp=32
        .module nooddspreg
        .abicalls
        .text
        .align  2
        .globl  Test
        .set    nomips16
        .set    nomicromips
        .ent    Test
        .type   Test, @function
Test:
        .frame  $fp,24,$31              # vars= 8, regs= 1/0, args= 0, gp= 8
        .mask   0x40000000,-4
        .fmask  0x00000000,0
        .set    noreorder
        .set    nomacro
        addiu   $sp,$sp,-24
        sw      $fp,20($sp)
        move    $fp,$sp
        sw      $4,24($fp)
        sw      $5,28($fp)
        movz    $31,$31,$0
        lw      $2,24($fp)
        nop
        addiu   $2,$2,1
        mtc1    $2,$f0
        nop
        cvt.d.w $f2,$f0
        lw      $2,28($fp)
        nop
        addiu   $2,$2,-10
        mtc1    $2,$f0
        nop
        cvt.d.w $f0,$f0
        add.d   $f0,$f2,$f0
        .set    macro
        trunc.w.d $f0,$f0,$2
        .set    nomacro
        mfc1    $2,$f0
        nop
        sw      $2,8($fp)
        lw      $2,8($fp)
        move    $sp,$fp
        lw      $fp,20($sp)
        addiu   $sp,$sp,24
        j       $31
        nop

        .set    macro
        .set    reorder
        .end    Test
        .size   Test, .-Test
        .align  2
        .globl  Sub
        .set    nomips16
        .set    nomicromips
        .ent    Sub
        .type   Sub, @function
Sub:
        .frame  $fp,24,$31              # vars= 8, regs= 1/0, args= 0, gp= 8
        .mask   0x40000000,-4
        .fmask  0x00000000,0
        .set    noreorder
        .set    nomacro
        addiu   $sp,$sp,-24
        sw      $fp,20($sp)
        move    $fp,$sp
        sw      $4,24($fp)
        lw      $3,24($fp)
        movz    $31,$31,$0
        lw      $2,24($fp)
        nop
        addu    $2,$3,$2
        sw      $2,8($fp)
        lw      $2,8($fp)
        move    $sp,$fp
        lw      $fp,20($sp)
        addiu   $sp,$sp,24
        j       $31
        nop

        .set    macro
        .set    reorder
        .end    Sub
        .size   Sub, .-Sub
        .ident  "GCC: (Ubuntu 5.4.0-6ubuntu1~16.04.9) 5.4.0 20160609"

if you like the answer please provide a thumbs up.

Add a comment
Know the answer?
Add Answer to:
Translate the following code into MIPS code. Test (int i, int j)                         {        &nbsp
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Translate the following code into MIPS code.         j=0; k=0; for (i = 1 ; i...

    Translate the following code into MIPS code.         j=0; k=0; for (i = 1 ; i < 50 ; i = i + 2) { K=k+1;            j = (i + j);             B[k] = j; } Assume the compiler associates the variables i, j, and k to the registers $t0, $t1, and $t2 respectively. Also, assume B is an array of integers and its address is stored at register $s1. PLEASE DO NOT COPY DOWN ANOTHER SOLUTION

  • 2. Translate the following code into MIPS code.         B [0] = 5; for (i =...

    2. Translate the following code into MIPS code.         B [0] = 5; for (i = 1 ; i < 50 ; i = i + 2) {                         B[i] =i + B[i-1]; } Assume the compiler associates the variable i to the register $t0. Also, assume B is an array of integers and its address is stored at register $s1.   

  • Translate the following C code to MIPS assembly code. Assume that the value of i is...

    Translate the following C code to MIPS assembly code. Assume that the value of i is in register $t0, and $s0 holds the base address of the integer MemArray if (i > 10) MemArray[i] = 0; else MemArray[i] = -MemArray[i];

  • Using beq only, not bge! Translate the following C code to MIPS assembly code. Use a...

    Using beq only, not bge! Translate the following C code to MIPS assembly code. Use a minimum number of instructions. Assume that the values of a, b, i, and j are in registers $s0, $s1, $t0, and $t1, respectively. Also, assume that register $s2 holds the base address of the integer array D. Comments are required. for(i=1; i<a; i++) for(j=1; j<b; j++) D[2*j] = i + j;

  • C to MIPS Conversion C variable h i j k x int a[] or &a[0] MIPS...

    C to MIPS Conversion C variable h i j k x int a[] or &a[0] MIPS register replacement $s0 $s1 $s2 $s3 $s4 $a0 Translate to MIPS. DO NOT USE pseudo MIPS instructions (e.g., BGE). Answer MUST use true 32-bit MIPS instructions: if(j < k ) a[j] = 1; else j = a[j];

  • For C to MIPS Conversion C variable h i j k x int a[] or &a[0]...

    For C to MIPS Conversion C variable h i j k x int a[] or &a[0] MIPS register replacement $s0 $s1 $s2 $s3 $s4 $a0 Translate to MIPS. No credit for pseudo-MIPS instructions (e.g., BGE). The answer MUST use true 32-bit MIPS instructions: if(j < k ) a[j] = 1; else j = a[j];

  • C to MIPS Conversion C variable h i j k x int a[] or &a[0] MIPS...

    C to MIPS Conversion C variable h i j k x int a[] or &a[0] MIPS register replacement $s0 $s1 $s2 $s3 $s4 $a0 Translate to MIPS. DO NOT USE pseudo MIPS instructions (e.g., BGE). Answer MUST use true 32-bit MIPS instructions: Note that all variables (h,i,j,x,a[]) are 32-bit signed integers. while ( h < 3 ) { a[j++]= 0; x = i >> 3; }

  • Translate the following C code to MIPS assembly. Assume that the values of a, b, i,...

    Translate the following C code to MIPS assembly. Assume that the values of a, b, i, and j are in registers $s0, $s1, $t0, and $t1, respectively. Also assume that $s2 holds the base address of the array D. for (i = 0: i < a: i++) for (j = 0: j < b: j++) D[2 * j] = i + j;

  • Translate the following C code to MIPS assembly code. Use a minimum number of instructions. Register...

    Translate the following C code to MIPS assembly code. Use a minimum number of instructions. Register allocations - i $s0 - j $s1 - base of A[] $s2 - base of B[] $s3 2) A[3] = B[i] + B[j]; 3) i = 0; while (j != A[i]) { i++; }

  • IN MIPS AND MUST RUN IN QTSPIM Translate the following C code to MIPS assembly code....

    IN MIPS AND MUST RUN IN QTSPIM Translate the following C code to MIPS assembly code. Use a minimum number of instructions. Assume that the values of a, b, i and j are stored in registers Ss0, Ss1, St0 and Stl, respectively. Also assume that register Ss2 holds the base address of the array D. for (i=0; i<a; itt) for (i-0j<b:jt+)

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT