Question

Translate the following C code to MIPS assembly code. Question 1) int counter = 0; void...

Translate the following C code to MIPS assembly code.

Question 1)

int counter = 0;

void change_global(int value)

{

counter = counter + value;

}

void main()

{

change_global(5);

change_global(10);

}

0 0
Add a comment Improve this question Transcribed image text
Answer #1
The MIPS assembly code will be: .file     1 ""    .section .mdebug.abi32  .previous       .nan    legacy  .module fp=32   .module nooddspreg      .abicalls       .globl  counter         .section        .bss,"aw",@nobits       .align  2       .type   counter, @object        .size   counter, 4 counter:     .space  4       .text   .align  2       .globl  change_global   .set    nomips16        .set    nomicromips     .ent    change_global   .type   change_global, @function change_global:         .frame  $fp,8,$31               # vars= 0, regs= 1/0, args= 0, gp= 0    .mask   0x40000000,-4   .fmask  0x00000000,0    .set    noreorder       .cpload $25     .set    nomacro         addiu   $sp,$sp,-8      sw      $fp,4($sp)      move    $fp,$sp         sw      $4,8($fp)       lw      $2,%got(counter)($28)   movz    $31,$31,$0      nop     lw      $3,0($2)        lw      $2,8($fp)       nop     addu    $3,$3,$2        lw      $2,%got(counter)($28)   nop     sw      $3,0($2)        nop     move    $sp,$fp         lw      $fp,4($sp)      addiu   $sp,$sp,8       j       $31     nop     .set    macro   .set    reorder         .end    change_global   .size   change_global, .-change_global  .align  2       .globl  main    .set    nomips16        .set    nomicromips     .ent    main    .type   main, @function main:   .frame  $fp,32,$31              # vars= 0, regs= 2/0, args= 16, gp= 8   .mask   0xc0000000,-4   .fmask  0x00000000,0    .set    noreorder       .cpload $25     .set    nomacro         addiu   $sp,$sp,-32     sw      $31,28($sp)     sw      $fp,24($sp)     move    $fp,$sp         .cprestore      16      movz    $31,$31,$0      li      $4,5                    # 0x5   lw      $2,%got(change_global)($28)     nop     move    $25,$2  .reloc  1f,R_MIPS_JALR,change_global 1: jalr    $25     nop     lw      $28,16($fp)     li      $4,10                   # 0xa   lw      $2,%got(change_global)($28)     nop     move    $25,$2  .reloc  1f,R_MIPS_JALR,change_global 1: jalr    $25     nop     lw      $28,16($fp)     nop     move    $sp,$fp         lw      $31,28($sp)     lw      $fp,24($sp)     addiu   $sp,$sp,32      j       $31     nop     .set    macro   .set    reorder         .end    main    .size   main, .-main    .ident  "GCC: (Ubuntu 5.4.0-6ubuntu1~16.04.9) 5.4.0 20160609"
Add a comment
Know the answer?
Add Answer to:
Translate the following C code to MIPS assembly code. Question 1) int counter = 0; void...
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