Question

7. 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 Ss0, Ss1, St0, and St1, respectively. Also, assume that register SS2 holds the base address of the array D. for(i-0; i<a; i++) for(j=0 ; j<b; j++)

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

Answer: MIPS code:

.file   1 ""
        .section .mdebug.abi32
        .previous
        .nan    legacy
        .module fp=32
        .module nooddspreg
        .abicalls
        .text
        .align  2
        .globl  main
        .set    nomips16
        .set    nomicromips
        .ent    main
        .type   main, @function
main:
        .frame  $fp,432,$31             # vars= 416, regs= 1/0, args= 0, gp= 8
        .mask   0x40000000,-4
        .fmask  0x00000000,0
        .set    noreorder
        .set    nomacro
        addiu   $sp,$sp,-432
        sw      $fp,428($sp)
        move    $fp,$sp
        sw      $0,8($fp)
        b       $L2
        movz    $31,$31,$0
        nop

$L5:
        sw      $0,12($fp)
        b       $L3
        nop

$L4:
        lw      $2,12($fp)
        nop
        sll     $2,$2,2
        lw      $4,8($fp)
        lw      $3,12($fp)
        nop
        addu    $3,$4,$3
        sll     $2,$2,2
        addiu   $4,$fp,8
        addu    $2,$4,$2
        sw      $3,16($2)
        lw      $2,12($fp)
        nop
        addiu   $2,$2,1
        sw      $2,12($fp)
$L3:
        lw      $3,12($fp)
        lw      $2,20($fp)
        nop
        slt     $2,$3,$2
        bne     $2,$0,$L4
        nop

        lw      $2,8($fp)
        nop
        addiu   $2,$2,1
        sw      $2,8($fp)
$L2:
        lw      $3,8($fp)
        lw      $2,16($fp)
        nop
        slt     $2,$3,$2
        bne     $2,$0,$L5
        nop

        move    $2,$0
        move    $sp,$fp
        lw      $fp,428($sp)
        addiu   $sp,$sp,432
        j       $31
        nop

        .set    macro
        .set    reorder
        .end    main
        .size   main, .-main
        .ident  "GCC: (Ubuntu 5.4.0-6ubuntu1~16.04.1) 5.4.0 20160609"
Add a comment
Know the answer?
Add Answer to:
7. Translate the following C code to MIPS assembly code. Use a minimum number of instructions....
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