开发者

Assembly code store byte/load byte

开发者 https://www.devze.com 2023-02-16 01:54 出处:网络
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:

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)
0

精彩评论

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