我正在使用PCSpim而且我遇到了问题 我有一个用于插入十六进制数值的字符数组,称之为HEXARRAY。
HEXARRAY:.byte' 0'' 0',' 0',' 0',' 0&#39 ;,' 0'' 0'' 0&#39 ;.
我想通过
插入一个整数sb $ t0,HEXARRAY($ t1)
其中$ t0是我想要的int,比方说8。 并且$ t1是8,即数组中的最后一个字节。
int在MIPS中有4个字节,如何将int插入1个字节?
答案 0 :(得分:0)
您可以通过执行' sw'来插入一个字(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