Reputation: 159
I'm teaching myself MIPS and came across this piece of code:
or $t0 $z0 $t1
srl $t0 1 $t0
sll $t0 1 $t0
sub $t0 $t0 $t1
the part here that interests me is that srl $t0 1 $t0
& sll $t0 1 $t0
is this correct? As i thought it would be srl $t0 $t0 1
with the n value last.
Also if $t1 contained 5, which is 00000101 when I do srl followed by sll would i just end up with something like this: 00000101
srl : 00000010
sll : 00000100
so $t0 would now be 4?
and then the sub part would be 5-4 which is 1?
Thanks in advance
Upvotes: 2
Views: 5248
Reputation: 1490
Yes normally it has the form:
sll $t0 $t1 n
(or srl)
and yes you are right because logical shifts introduce 0's so your 5 would end up being a 4
and finally:
sub $t0 $t0 $t1
is equivalent to t0 = t0 - t1
Upvotes: 1