Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

NOTE: The rest of the exam involves converting Java code into MIPS. For this, yo

ID: 3713721 • Letter: N

Question

NOTE: The rest of the exam involves converting Java code into MIPS. For this, you must use real MIPS instructions (not pseudoinstructions). Additionally, assume RAM is byte-addressed (each address holds one byte) and that all data is 4-byte integers. Part II. Arrays and Arithmetic (20 pts) Translate the following statements from Java to MIPS. Assume the following register assignments, and you may use temporaries as necessary. Translate them individually (ie., do not assume problem #1 runs before problem #2) Variable starting address of arr Register $s1 $s2 1 (5 pts). 2 (5 pts). y- (x + 10) - z; addi sto, So 3 (10 pts). arr ly+1] -arr[y] + x; to add $

Explanation / Answer

$s0: Starting address
$s1: x
$s2: y
$s3: z

x=y+Z:

result: .asciiz " The result of addition is: "

.text
li $v0,$s2
la $a0,msg1
syscall

li $v0,$s3
syscall
move $t1,$v0

li $v0,$s2
la $a0,msg2
syscall

li $v0,$s3
syscall
move $t2,$v0

Add $t3,$t1,$t2

li $v0,$s2
la $s1,msg3
syscall

li $v0,1
move $a0,$t3
syscall

li $v0,10
syscall


y=(x+10)-z

data
result: .asciiz "The result is: "

.text

li $vo,$s1
syscall

li $v0,$s1
syscall
move $v0,$t1


li $vo,$s3
syscall

li $v0,$s3
syscall
move $v0,$t2

sub $t1,$t1,$t2

li $v0,$s1
la $a0,$s2
syscall