In: Computer Science
procedure:
addi $s0,$zero,0
loop:
slti $t1, $s0, 7
beq $t1, $zero, exit
addi $s0,$s0,1
j loop
exit:
add $v0, $zero, $s0
jr $ra
What is the corresponding high-level programming language code? Write a code in your preferred language. What is the result? (5 pts)
int add(int a, int b) {
return a+b;
}
int sub(int a, int b) {
return a-b;
}
void main(){
int x=11, y=4;
add(x, y);
sub(x, y);
}
What is the corresponding MIPS code? (5 pts)
1. Following image contains the explanation of mips instruction used in the above code and it's corresponding C code with in line comments.
The result is 7.
2.Following mips code perform addition and subtraction but it is performed through a function. And the value is returned in registery v0 and v1
The output will be,
V0= s0+s1
V0=11+4
V0=15
V1=s0-s1=11-4
V1=7
Thanks and kindly upvote.