Question

Can anyone help to solve this MIPS assembly language problem? Please help. Translate the fowlowwing C...

Can anyone help to solve this MIPS assembly language problem?
Please help.

Translate the fowlowwing C code to MIPS assembly language.

void main() {
int i, sum, begin, end;
for(i=0; i < 5; i++){
scanf(“%d, %d”, &begin, &end);
sum = accum_range(begin, end);
printf(“sum[%d: %d] = %d\n”, begin, end, sum);
}

int accum_range(int a, int b){
return accum (b) - accum(a);
}

int accum(int final) {
int sum = 0;
for (int I = 1; I <= final; I = I +1)
sum = sum + I;
return sum;
}
0 0
Add a comment Improve this question Transcribed image text
Answer #1

Actually the code is wrong and herewith providing the right code as follows:

#include<stdio.h>
void main() {
int i, sum, begin, end;
for(i=0;i<5;i++)
{
scanf("%d,%d",&begin, &end);
sum = accum_range(begin,end);
printf("sum[%d:%d]=%d\n",begin,end,sum);
}
}
int accum_range(int a,int b)
{
return accum(b) - accum(a);
}
int accum(int final)
{
int sum=0;
for(int I=1;I<=final;I+1)
sum=sum+I;
return sum;
}

MIPS ASSEMBLY LANGUAGE CODE IS:

.file 1 ""

      .section .mdebug.abi32

      .previous

      .nan legacy

      .module     fp=32

      .module     nooddspreg

      .abicalls

      .section    .rodata.str1.4,"aMS",@progbits,1

      .align      2

$LC0:

      .ascii      "%d,%d\000"

      .align      2

$LC1:

      .ascii      "sum[%d:%d]=%d\012\000"

      .section    .text.startup,"ax",@progbits

      .align      2

      .globl      main

      .set nomips16

      .set nomicromips

      .ent main

      .type main, @function

main:

      .frame      $sp,64,$31        # vars= 8, regs= 6/0, args= 24, gp= 8

      .mask 0x801f0000,-4

      .fmask      0x00000000,0

      .set noreorder

      .cpload     $25

      .set nomacro

      addiu $sp,$sp,-64

      sw    $18,48($sp)

      sw    $17,44($sp)

      lw    $18,%got($LC0)($28)

      lw    $17,%got($LC1)($28)

      movz $31,$31,$0

      sw    $20,56($sp)

      sw    $19,52($sp)

      sw    $16,40($sp)

      .cprestore 24

      sw    $31,60($sp)

      li    $16,5             # 0x5

      addiu $20,$sp,36

      addiu $19,$sp,32

      addiu $18,$18,%lo($LC0)

      addiu $17,$17,%lo($LC1)

$L6:

      lw    $25,%call16(__isoc99_scanf)($28)

     

      .set macro

      .set reorder

      .end main

      .size main, .-main

      .text

      .align      2

      .globl      accum_range

      .set nomips16

      .set nomicromips

      .ent accum_range

      .type accum_range, @function

accum_range:

      .frame      $sp,0,$31         # vars= 0, regs= 0/0, args= 0, gp= 0

      .mask 0x00000000,0

      .fmask      0x00000000,0

      .set noreorder

      .set nomacro

      blez $5,$L13

      nop

$L17:

      b     $L17

      nop

$L13:

      blez $4,$L15

      nop

$L18:

      b     $L18

      nop

$L15:

      j     $31

      move $2,$0

      .set macro

      .set reorder

      .end accum_range

      .size accum_range, .-accum_range

      .align      2

      .globl      accum

      .set nomips16

      .set nomicromips

      .ent accum

      .type accum, @function

accum:

      .frame      $sp,0,$31         # vars= 0, regs= 0/0, args= 0, gp= 0

      .mask 0x00000000,0

      .fmask      0x00000000,0

      .set noreorder

      .set nomacro

      blez $4,$L20

      nop

$L22:

      b     $L22

      nop

$L20:

      j     $31

      move $2,$0

      .set macro

      .set reorder

      .end accum

      .size accum, .-accum

      .ident      "GCC: (Ubuntu 5.4.0-6ubuntu1~16.04.9) 5.4.0 20160609"

Add a comment
Know the answer?
Add Answer to:
Can anyone help to solve this MIPS assembly language problem? Please help. Translate the fowlowwing C...
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