Question

Consider the following C program. It calculates the remainder when i is divided by j. For...

Consider the following C program. It calculates the remainder when i is divided by j. For example, function call remainder(9,4) returns value 1.

int remainder(int i, int j){
if(i<j)
return i;
else
return remainder(i-j,j);
}

Please translate the above C code into MIPS.

0 0
Add a comment Improve this question Transcribed image text
Answer #1
.file     1 ""    .section .mdebug.abi32  .previous       .nan    legacy  .module fp=32   .module nooddspreg      .abicalls       .text   .align  2       .globl  remainder       .set    nomips16        .set    nomicromips     .ent    remainder       .type   remainder, @function remainder:         .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      sw      $4,32($fp)      sw      $5,36($fp)      lw      $3,32($fp)      lw      $2,36($fp)      nop     slt     $2,$3,$2        beq     $2,$0,$L2       nop     lw      $2,32($fp)      b       $L3     nop $L2:        lw      $3,32($fp)      lw      $2,36($fp)      nop     subu    $2,$3,$2        lw      $5,36($fp)      move    $4,$2   lw      $2,%got(remainder)($28)         nop     move    $25,$2  .reloc  1f,R_MIPS_JALR,remainder 1:     jalr    $25     nop     lw      $28,16($fp) $L3:        move    $sp,$fp         lw      $31,28($sp)     lw      $fp,24($sp)     addiu   $sp,$sp,32      j       $31     nop     .set    macro   .set    reorder         .end    remainder       .size   remainder, .-remainder  .ident  "GCC: (Ubuntu 5.4.0-6ubuntu1~16.04.9) 5.4.0 20160609" 
Add a comment
Know the answer?
Add Answer to:
Consider the following C program. It calculates the remainder when i is divided by j. For...
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
  • Consider the following code C++ like program: int i, j, arr[5]; //arr is an array starting...

    Consider the following code C++ like program: int i, j, arr[5]; //arr is an array starting at index 0 void exchange(int x, int y) { int temp:= x; x:= y; y:= temp; } main(){ for (j = 0; j < 5; j++) arr[j]:= j; i:= 1; exchange(i, arr[i+1]); output(i, arr[2]); //print i and arr[2] } What is the output of the code if both parameters in function swapping are passed by: a- value? b- reference? c- value-result?

  • 1. [2 points] Write a MIPS assembly language program of the following C function and the...

    1. [2 points] Write a MIPS assembly language program of the following C function and the code to call the function: int leaf_example (int g, h, i, j) { int f; f = (g + h) - (i + j); return f; مهه Arguments g, h, i, and j are passed to the function in registers $a0, $al, Şa2, and $a3, respectively while f in $50 (hence, need to save $50 on stack), and the result is to be stored...

  • 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.

  • Please write MIPS program that runs in QtSpim (ex: MipsFile.s) Write a MIPS program that will...

    Please write MIPS program that runs in QtSpim (ex: MipsFile.s) Write a MIPS program that will read in a base (as an integer) and a value (nonnegative integer but as an ASCII string) in that base and print out the decimal value; you must implement a function (which accepts a base and an address for a string as parameters, and returns the value) and call the function from the main program. The base will be given in decimal and will...

  • 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: if(j < k ) a[j] = 1; else j = a[j];

  • in a c# program I am trying to allow the area to be divided by a...

    in a c# program I am trying to allow the area to be divided by a set choice. the area is set as an int in another method and I am unable to call it into the method I need it in. Is there a way to call Int? I also need to set each case to have an integer value. For example if they select 1 it is set at a value of 5. This is what I have...

  • Consider the following C++ code segment: if (i j) cout << "1"; else if ((i &j)...

    Consider the following C++ code segment: if (i j) cout << "1"; else if ((i &j) < 3) cout << "2"; else if (i < (j-1)) cout << "3"; else cout << "4"; cout << "5"; If the value of iis 5and the value of jis 6, which of the options below gives the correct output? 1. 25 2. 35 3. 15 4. 45

  • I have this C program that calculates an input and converts it to a BMI calculation....

    I have this C program that calculates an input and converts it to a BMI calculation. Any idea how this would look as an LC3 program? I'm taking an LC3 programming class next semester and want an idea of what this code would even translate to, just trying to get a head start. I'm more so curious on how to get user input in a LC3 program, then I can try myself and figure it out from there. int main()...

  • C++ 4. What is a driver program? 43. Consider the following function and code segment. void...

    C++ 4. What is a driver program? 43. Consider the following function and code segment. void Onet int first, int& second first 17 secondfirst 1 int main) // other code int j4; int k3; One(j, k) // other code .. After the call to OneGi, k); what are the values ofj and k?

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