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
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
ADVERTISEMENT