How to wr开发者_开发技巧ite the following into MIPS instructions?
$t0=$t1
if ($t6<$t7) go to Label.
$t0 is not reserved for zero. $t0 is a temporary register that can store any value. The register $zero is reserved/hard-wired to zero. We would want to "branch" to "Label" if $t6 is "less than" $t7, so use the branch on less than instruction blt. The code would look like:
add $t0,$zero,$t1
blt $t6,$t7,Label
your following rubbish:
$t0=$t1
if ($t6 less than $t7) go to Label
would be converted to MIPS like:
move $t0,$t1 # or use instruction instead (add $t0,$zero,$t1)|(addi $t0,$t1,0)
slt $t2,$t6,$t7 # if $t6less than $t7 set $t2=1
bgtz $t2,foo # if $t2=0 goto foo, and foo is the label that you want to move to
Assuming that the registers are already loaded with the right data.
So for $t2 = $t3
, adding $t3
to register zero and storing it in $t2
will work so this is how it would look like :
add $t2,$t3,$t0
- assuming $t0 is reserved for zero like most versions of mips.
for if $t4
, we need a branch statement, not sure what you want to compare it to, but look at this guide - should give enough instructions about how to write it.
精彩评论