Ok so I have this question on a practice test for a class th
Ok so I have this question on a practice test for a class that I am having rouble figuring out. The question is below. The C code is(if(t0<0) {t0 = 42; }). And the asnwer is right below it but I do not know how they got that answer. Also attatched is the page with MIPS instructions on it but even when looking at that list I still cannot figure out how to get that answer. Any help would be greatly appreciated. Preferably a very detailed answer. Thanks!
3. Using only MIPS instructions listed on the last page of this exam, write assembly code to implement the following C code. Variables should be placed in the registers with the same name e., to is kept in the register named sto; other t registers may be used as temporaries. Comment any non-obvious things you do. if (to 0) to 42; slt St 1, St 0, $0 MIPS Instructions (a subset) beq $t1, 0, fi ori $t0, 0, 42 add rl,r2, r3 fi: addua rl, r2,r3 addi rl, r2, immediate addiu rl, r2, immediate and rl,r2, r3 andi rl, r2, immediate rl,r2, r3 Orr ori rl,r2, immediate sub rl,r2, r3 subi rl, r2, immediate rl,r2, r3 XOr xori rl, r2, immediate lui rl immediate slt rl,r2, r3 beq rl,r2, label r1,r2, label bne label label jal r1 jr rl, offset (r2 rl, offset (r2)Solution
3)
addiu $sp,$sp,-8
sw $t0,4($sp)
move $t0,$sp
sw $4,8($t0)
lw $2,8($t0)
bgez $2,$L3
nop
li $2,42 # 0x2a
sw $2,8($t0)
nop
move $sp,$t0
lw $t0,4($sp)
addiu $sp,$sp,8
j $31
nop
