首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >在MIPS中存储int的字节

在MIPS中存储int的字节
EN

Stack Overflow用户
提问于 2016-10-08 14:14:10
回答 1查看 5.6K关注 0票数 0

我正在使用PCSpim,我有一个问题,我有一个字符数组插入十六进制数的值,称之为HEXARRAY。

.byte '0','0','0','0','0','0','0',‘0’,‘0’,‘0’,‘0’,‘0’,'0'.

我想通过以下操作插入一个整数

sb $t0,十六进制($t1)

其中$t0是我想要的int,比方说8,而$t1是8,数组中的最后一个字节。

int在MIPS中有4个字节,如何将int插入到1字节?

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2016-10-08 22:35:42

您可以通过执行'sw‘=存储字来插入一个单词(32位).类似于:

代码语言:javascript
复制
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的不同的广告中这样做。

类似于:

代码语言:javascript
复制
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
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/39933427

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档