在 MIPS 中存储 int 的字节
Store byte of an int in MIPS
我正在使用 PCSpim,但遇到了问题
我有一个字符数组,用于插入十六进制数的值,称之为 HEXARRAY。
十六进制:.byte '0','0','0','0','0','0','0','0'。
我想通过
插入一个整数
sb $t0, HEXARRAY($t1)
其中 $t0 是我想要的整数,比方说 8。
$t1 是 8,数组中的最后一个字节。
int在MIPS中有4个字节,如何将int插入到1个字节?
您可以通过执行 'sw' = store word... 来插入一个词(32 位),例如:
number: .word 8 # your number is 8
space: .space 20 # adress to save your number
la $t3, number # loading the adress of your number 8
lw $t3, 0($t3) # NOTICE that with 'lw' you are taking your WHOLE WORD = number 8
la $s1, space
sw $t3, 0($s1) # where $t3 is your number and $s1 the adress you want to save it
如果您不想保存整个数字 8,而是保存数字的单独字节...您可以在 $s1 的不同地址中进行。
类似于:
sb $t3, 0($s1) # you are storing the byte'00001000' in the 1st adress of $s1
addi $s1, $s1, 1 # adding 1 to the adress where you want to save your next byte
srl $t3, $t3, 3 # moving your number 8 (in binary) to the right... so you can
# 'sb' = store byte (a different one) again in $s1
我正在使用 PCSpim,但遇到了问题 我有一个字符数组,用于插入十六进制数的值,称之为 HEXARRAY。
十六进制:.byte '0','0','0','0','0','0','0','0'。
我想通过
插入一个整数sb $t0, HEXARRAY($t1)
其中 $t0 是我想要的整数,比方说 8。 $t1 是 8,数组中的最后一个字节。
int在MIPS中有4个字节,如何将int插入到1个字节?
您可以通过执行 'sw' = store word... 来插入一个词(32 位),例如:
number: .word 8 # your number is 8
space: .space 20 # adress to save your number
la $t3, number # loading the adress of your number 8
lw $t3, 0($t3) # NOTICE that with 'lw' you are taking your WHOLE WORD = number 8
la $s1, space
sw $t3, 0($s1) # where $t3 is your number and $s1 the adress you want to save it
如果您不想保存整个数字 8,而是保存数字的单独字节...您可以在 $s1 的不同地址中进行。
类似于:
sb $t3, 0($s1) # you are storing the byte'00001000' in the 1st adress of $s1
addi $s1, $s1, 1 # adding 1 to the adress where you want to save your next byte
srl $t3, $t3, 3 # moving your number 8 (in binary) to the right... so you can
# 'sb' = store byte (a different one) again in $s1