My task is to write an assembly code which will store the left most byte开发者_如何转开发 of $s1 in the location pointed by $t1. Here's what I have:
lb $s4, 0($s1)
sb $s4, $t1
This is apparently wrong. Could someone help me out?
You are loading $s4 with the byte at memory address $s1, not from $s1. The solution depends on your architecture, but for getting the leftmost (most significant) byte from the register $s1 you can do something like this (assuming MIPS):
srl $s4, $s1, 24 ;shift the value in $s1 24 steps to the right and store in $s4
sb $s4, 0($t1) ;store the byte at ($t1)
精彩评论