In: Computer Science
Translate the following C code to MIPS assembly. The main function and subfunction are translated to two separate .asm files.
Finish the assembly code segment for the above requirement.
int main() {
int x=2; int y=1; int z=0; z=Subfunc(x,y); printf(“Value of z is: %d”, z);
}
int Subfunc(int x, int y)
{ int t1=0;
t1=x+y+100; return t1;} File 1: .data
str: .asciiz "The value of z:"
.text
#.globl main main: addi $s0, $0,2 #x addi $s1, $0,1 #y addi $s2, $0,0 #z
move $a0, $s0 move $a1, $s1 jal subfunc
move $s2, $v0 # updated from $s0
la $a0, str li $v0, 4 syscall
move $a0, $s2 #print result, # updated from $s0
li $v0, 1
syscall
li $v0, 10 #exit
syscall
File 2:
.text
.globl subfunc
subfunc:
…. # your answer here
#File1
.data
str: .asciiz "The value of z:"
.text
.globl main
main:
addi $s0, $0, 2
#x
addi $s1, $0, 1
#y
addi $s2, $0, 0
#z
move $a0, $s0
move $a1, $s1
jal subfunc
move $s2, $v0
#updated
from $s0
la $a0, str
li $v0, 4
syscall
#print result
move $a0, $s2
#updated from
$s0
li $v0, 1
syscall
li $v0, 10
#exit
syscall
#File2
.text
.globl subfunc
subfunc:
add $v0, $a0, $a1
addi $v0, $v0, 100
jr $ra
#Output