开发者

MIPS multiplication problem

开发者 https://www.devze.com 2023-04-05 13:02 出处:网络
In MIP开发者_C百科S, how can I tranlate this expression to MIPS? y = 2x+3z (x,y,z are variables) I use multi $t0,$s0, 2 # $s0 stores x and $s1 stores y. to show 2x. Is that correct?Assuming that:

In MIP开发者_C百科S, how can I tranlate this expression to MIPS?

y = 2x+3z (x,y,z are variables)

I use multi $t0,$s0, 2 # $s0 stores x and $s1 stores y. to show 2x. Is that correct?


Assuming that:

x is in $s0
z is in $s1
y will be in $s2

add $s2, $s0, $s0    # x*2 in $s2
add $t0, $s1, $s1    # z*2 in $t0
add $t0, $t0, $s1    # z*3 in $t0
add $s2, $s2, $t0    # x*2+z*3 in $s2

We don't actually multiply (it's slower than simple addition) and as you can see we destroy temporary register $t0 but don't touch $s0/$s1

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号