Convert the following conditional statement to MARS assembly

Convert the following conditional statement to MARS assembly language. You may assume that a is in $s0 and b is in $s1. if (a > b) {a = a - b;}else{b = b - a;}

Solution

slt $5,$s1,$s0 # test a<b

beq $5,$0,Else # if false goto Else

subu $s0,$s0,$s1 # a=a-b

j Endif # goto Endif

Else :

subu $s1,$s1,$s0 #b=b-a

Endif

 Convert the following conditional statement to MARS assembly language. You may assume that a is in $s0 and b is in $s1. if (a > b) {a = a - b;}else{b = b -

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site