数据移动错误说明 [英] data movement error clarification
问题描述
我目前正在解决第三版计算机系统中的问题3.3:程序员的观点,我很难理解这些错误的含义...
I'm currently solving problem 3.3 from 3rd edition of Computer System: a programmer's perspective and I'm having a hard time understanding what these errors mean...
movb $0xF, (%ebx)
给出错误,因为ebx不能用作地址寄存器
movb $0xF, (%ebx)
gives an error because ebx can't be used as address register
movl %rax, (%rsp)
和
movb %si, 8(%rbp)
给出错误,指出指令后缀和寄存器I.D之间不匹配.
movl %rax, (%rsp)
and
movb %si, 8(%rbp)
gives error saying that theres a mismatch between instruction suffix and register I.D.
movl %eax, %rdx
给出错误消息,表明目标操作数的大小不正确
movl %eax, %rdx
gives an error saying that destination operand incorrect size
为什么我们不能使用ebx作为地址寄存器?是因为它的32位寄存器吗?如果不是movb $0xF, (%rbx)
,下面的行是否可以工作?因为rbx是64位寄存器?
why can't we use ebx as address register? Is it because its 32-bit register? Would the following line work if it was movb $0xF, (%rbx)
instead? since rbx is of 64bit register?
关于指令后缀和寄存器I.D之间不匹配的错误,是否出现此错误,因为它应该是movq %rax, (%rsp)
和movew %si, 8(%rbp)
而不是movl %rax, (%rsp)
和movb %si, 8(%rbp)
?
for the error regarding mismatch between instruction suffix and register I.D, does this error appear because it should've been movq %rax, (%rsp)
and movew %si, 8(%rbp)
instead of movl %rax, (%rsp)
and movb %si, 8(%rbp)
?
最后,对于与目标操作数大小不正确"有关的错误,这是因为目标寄存器是64位而不是32位吗?因此,如果代码行是movl %eax, %edx
,则不会发生该错误?
and lastly, for the error regarding "destination operand incorrect size", is this because the destination register was 64 bit instead of 32? so if the line of code was movl %eax, %edx
instead, the error wouldn't have occurred?
任何启发都会受到赞赏.
any enlightenment would be appreciated.
这是针对x86-64的
this is for x86-64
推荐答案
movb $0xF, (%ebx) gives an error because ebx can't be used as address register
确实,ebx
不能用作地址寄存器(对于x86-64),但是rbx
可以. ebx是rbx的低32位. 64位代码的全部要点是地址可以是64位,因此尝试使用32位寄存器来引用内存毫无意义.
It's true that ebx
can't be used as an address register (for x86-64), but rbx
can. ebx is the lower 32bits of rbx. The whole point of 64bit code is that addresses can be 64bits, so trying to reference memory by using a 32bit register makes little sense.
movl %rax, (%rsp) and movb %si, 8(%rbp) gives error saying that
theres a mismatch between instruction suffix and register I.D.
是的,因为您使用的是movl
,所以'l'表示long,在这种情况下,它表示32位.但是,rax是一个64位寄存器.如果要从rax写入64位,则应使用movq
.如果要写入32位,则应使用eax
.
Yes, because you are using movl
, the 'l' means long, which (in this context) means 32bits. However, rax is a 64bit register. If you want to write 64bits out of rax, you should use movq
. If you want to write 32bits, you should use eax
.
movl %eax, %rdx gives an error saying that destination operand incorrect size
您正在尝试将32位值移动到64位寄存器中.有说明可以为您执行此转换(例如,参见cdq
),但是movl并不是其中之一.
You are trying to move a 32bit value into a 64bit register. There are instructions to do this conversion for you (see cdq
for example), but movl isn't one of them.
这篇关于数据移动错误说明的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!