How can i run this switch case assembly code to Winmips64 or Mips64? slt $t3 , $
ID: 669642 • Letter: H
Question
How can i run this switch case assembly code to Winmips64 or Mips64?
slt $t3 , $s5 , $zero # $t3 =1 if k < 0
bne $t3 , $zero , Exit # if k < 0 go to Exit
slt $t3 , $s5 , $t2 # Test if k < 4
beq $t3 , $zero , Exit # if k >= 4 go to Exit
add $t1 , $s5 , $s5
add $t1 , $t1 , $t1
add $t1 , $t1 , $t4 # $t1 = address of JumpTable [k]
lw $t0 , 0( $t1) # $t1 = JumpTable [k]
jr $t0
L0: add $s0 , $s3 , $s4 # f = i + j
j Exit
L1: add $s0 , $s1 , $s2 # f = g + h
j Exit
L2: sub $s0 , $s3 , $s4 # f = g - h
j Exit
L4: sub $s0 , $s1 , $s2 # f = i - j
Exit :
Explanation / Answer
Try This:
C Source Code:
assuming that I,j,k corresponds to $s3,$s4,$s5 and the base address of the array save is in $s6 (How is this example different from the previous ones?) •
MIPS assembly code:
while (save[i] == k) i=i+j; Loop: add $t1,$s3,$s3 #reg $t1 = 2*i add $t1,$t1,$t1 #reg $t1 = 4*i add $t1,$t1,$s6 #$t1 = address of save[i] lw $t0,0($t1) #$t0 = save[i] bne $t0,$s5, Exit # goto Exit if save[i]!=k add $s3,$s3,$s4 # i= i + j j Loop # goto Loop Exit:
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.