当我编译我的汇编文件(下面的代码)时,我收到消息错误:"mov"的指令后缀无效,指向我的 movw 指令行。 现在,我已经谷歌了一下,仍然不明白这一点。 我的 CPU 是 64 位的,但由于我清楚地告诉 gcc 生成 32 位代码,移动不应该是移动寄存器较低 16 位的有效指令吗? 我几乎逐字复制了我手头的书中的例子。
remnux@remnux:~/Assembly$ gcc -o zx zx.s -gstabs -m32zx.s: 汇编程序消息:zx.s:10:错误:"mov"的指令后缀无效
.code32
.section .data
myString:
.asciz "eax is now %dn"
.section .text
.globl main
main:
movl $9999, %ebx
movl $3, %eax
movw %ax, %ebx
pushl %ebx
pushl %eax
pushl %ebx
pushl $myString
call printf
add $8, %esp
popl %eax
popl %ebx
movzx %ax, %ebx
pushl %ebx
pushl %eax
pushl %ebx
pushl $myString
call printf
add $8, %esp
call printf
call exit
但发表了评论而不是答案。 由于每个答案都应该有结束,所以我正在回答我自己的问题。
我使用的是 16 位 movw 和 32 位 %ebx,书中的示例不正确。 Movw 将使用 16 位寄存器(如 %bx 或 movl)将 32 位移动到 %ebx 中。