简单的MIPS问题,关于加载字节
我这里有以下问题
.data
a: .asciiz "2021"
x: .byte 7,2,12
.text
main: addi $t2, $0, 1
lb $t3, a($t2)
有人可以向我解释一下 $t3 的值是 48 吗?
谢谢 编辑这是另一个类似的问题,并且令人困惑。
.data
a: .word 12,-5,4,0
x: .byte 5
.text
main: addi $t1, $0, 8
lw $t2, a($0)
lw $t3, a($t1)
当“a”的长度为 4 时,如何从索引 8 加载单词?
I have the following question here
.data
a: .asciiz "2021"
x: .byte 7,2,12
.text
main: addi $t2, $0, 1
lb $t3, a($t2)
Can someone explain to me, HOW the value of $t3 is 48?
thanks
EDIT this is an another question which is similiar, and is confusing.
.data
a: .word 12,-5,4,0
x: .byte 5
.text
main: addi $t1, $0, 8
lw $t2, a($0)
lw $t3, a($t1)
How will you load word, from index 8, when 'a' has a length of 4?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
是的,当您添加
$0
和1
时,您会得到1
,它被放入$t2
中。然后,当您计算
a($t2)
时,这是a
的第二个字节(偏移量 1,因为它基于偏移量 0),即“0”,ASCII 代码0x30
或48
。从各种信息来看:
这些小片段应该足以解释它在做什么。
而且,关于您的编辑,您错误地认为
.word 12,-5,4,0
的长度为 4 个字节。事实上,它的长度为 16 字节,因为 MIPS 中的字为 32 位(四个字节)宽。因此,当您从偏移量 8 的字节加载时,您将获得单词
4
。Yes, when you add
$0
and1
, you get1
, which is put into$t2
.Then, when you evaluate
a($t2)
, that's the second byte (offset 1 since it's based at offset 0) ofa
which is the "0", ASCII code0x30
or48
.From various pieces of information:
Those little snippets should hopefully be enough to explain what it's doing.
And, regarding your edit, you're incorrectly thinking that
.word 12,-5,4,0
has a length of 4 bytes. In fact it has a length of 16 bytes since words in MIPS are 32 bits (four bytes) wide.So when you load from byte offset 8, you will get the word
4
.仅供参考,讲义 4 的第 11 页上有一个 ASCII 图表;)
但我不明白这个:
“当你评估 a($t2) 时,这是 a 的第二个字节(偏移量 1,因为它基于偏移量 0),即“0””
我认为“2021”的二进制表示是:
00110010001100000011001000110001
那么,当你说“哪个是“0””时,你的意思是从右边算起第二位吗?是你说的0吗?
我不明白零从何而来。
FYI there is an ASCII chart on page 11 of handout 4 ;)
But I dont get this:
"when, when you evaluate a($t2), that's the second byte (offset 1 since it's based at offset 0) of a which is the "0""
The binary representation of '2021' I believe is:
00110010001100000011001000110001
So, when you say "which is the "0"" do you mean the 2nd bit from the right? Is that the 0 you are talking about?
I dont get where the zero comes from.