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"
Can anyone help to solve this MIPS assembly language problem? Please help. Translate the fowlowwing C...
Translate the High order language program to assembly language and generate PEP9 assembly language code. #include <stdio.h> int main() { int number; scanf(“%d”,&number ); if (number <0) { number =- number; } printf ("%d", number); return0; }
MIPS assembly language Implement the following code in MIPS int array [ ] {2, 3, 4, 5, 6); int main) int num, position; scanf("%d",&num) ; position search(array, printf("The position is: num, 5); %d\n",positio int search(int array, int num, int size int position =-1; for(int i-0;i<size; i++) if(array [i]=num) { position-i; break; return position; Register map $s1: position $a0: array address $a1: num . $a2: size . $VO: return value
Translate the following C program to Pep/9 assembly language. #include <stdio.h> int main() { int number; scanf("%d", &number); if (number % 2 == 0) { printf("Even\n"); } else { printf("Odd\n"); } return 0; }
Translate the following C program to Pep/9 assembly language. #include <stdio.h> const int limit = 5; int main() { int number; scanf("%d",&number); while (number < limit){ number++; printf("%d",number); } return 0; }
Translate function f into MIPS assembly language. The code for function f is as follows: int func(int a, int b){ return a + b; } int f(int a, int b, int c, int d){ return func(func(a, b), c - d);
MIPS assembly language Covert this code to MIPS: #include <stdio.h> int function (int a) int main)i int x=5 ; int y: y function(x); printf "yd",y); return 0; int function (int a) return 3*a+5; Assumptions: . Place arguments in $a0-$a3 . Place return values in $vO-$v1 Return address saved automatically in $ra . lgnore the stack for this example. (Thus, the function will destroy registers used by calling function
please translate these c++ coding to the simplest QtSPIM MIPS assembly language statement #include<iostream> using namespace std; int main() { int change; int totalCredit; cout<<"Please scan your card"; cin>>totalCredit; if(totalCredit>=3) { change=totalCredit-3; cout<<"45 min"; } else { cout<<"00"; } return 0; }
Translate the following C program to Pep/9 assembly language. It multiplies two integers using a recursive shift-and-add algorithm. mpr stands for multiplier and mcand stands for multiplicand. A recursive integer multiplication algorithm #include <stdio.h> int times(int mpr, int mcand) { if (mpr == 0) { return 0; } else if (mpr % 2 == 1) { return times(mpr / 2, mcand * 2) + mcand; } else { return times(mpr / 2, mcand * 2); } } int main() { ...
C language to MIPS assembly code pleaseeeint hw_func (int num_hws, int avg_hours) {int total_hw_time;total_hw_time = num_hws x avg_hours;return total_hw_time;}int exercise_func (int num_exercises, int avg_hours) {int total_exercise_time;total_exercise_time = num_exercises x avg_hours;return total_exercise_time;}int total (int nhws, int hours, int nexercises, int ehours) {int total;total = hw_func (nhws, hours) + exercise_func (nexercises, ehours);return total;}void main( ) {int num_homeworks = 4;int average_hws_hours = 1;int num_exercises_per day = 2;int average_exercise_hours = 2;int total_time = total(num_homeworks, average_hws_hours,num_exercises_perday, average_exercises_hours);printf(“%d\n”, total_time);}
Convert the below C code to basic MIPS. Please leave comments for explanation #include <stdio.h> int main(void) { printf("Insert two numbers\n"); int a,b; scanf("%d",&a); scanf("%d",&b); a=a<<2; b=b<<2; printf("%d&%d\n",a,b); return 0; }