Linux 用气拼装时push指令后缀无效
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/6268745/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Invalid instruction suffix for push when assembling with gas
提问by vitaut
When assembling a file with GNU assembler I get the following error:
使用 GNU 汇编器组装文件时,出现以下错误:
hello.s:6: Error: invalid instruction suffix for `push'
hello.s:6: 错误:`push' 的指令后缀无效
Here's the file that I'm trying to assemble:
这是我试图组装的文件:
.text
LC0:
.ascii "Hello, world!movl , %eax # 32-bit instruction
movq , %rax # 64-bit instruction
pushl %eax # Illegal instruction
pushq %rax # 1 byte instruction encoded as pushl %eax in 32 bits
pushq %r10 # 2 byte instruction encoded as pushl preceeded by REX
"
.globl _main
_main:
pushl %ebp
movl %esp, %ebp
subl , %esp
andl $-16, %esp
movl example.s:6:suffix or operands invalid for `push'
, %eax
movl %eax, -4(%ebp)
movl -4(%ebp), %eax
call __alloca
call ___main
movl $LC0, (%esp)
call _printf
movl ##代码##, %eax
leave
ret
What is wrong here and how do I fix it?
这里有什么问题,我该如何解决?
The problem is somewhat related to this questionalthough errors and instructions in questions are different.
采纳答案by Anu
64bit instructions
64位指令
By default most operations remain 32-bit and the 64-bit counterparts are invoked by the fourth bit in the REX prefix. This means that each 32-bit instruction has it's natural 64-bit extension and that extended registers are for free in 64-bit instructions
默认情况下,大多数操作保持 32 位,而 64 位对应操作由 REX 前缀中的第四位调用。这意味着每条 32 位指令都有其自然的 64 位扩展,并且扩展寄存器在 64 位指令中是免费的
##代码##回答by Carl Norum
Are you assembling with a 64-bit assembler? Your code looks like it's 32-bit. I get this error with your code when using a 64-bit assembler:
你是用 64 位汇编器组装的吗?您的代码看起来像是 32 位的。使用 64 位汇编器时,我的代码出现此错误:
##代码##But it works fine with a 32-bit assembler.
但它在 32 位汇编器上运行良好。
回答by rem
You have to use a "64 bit syntax", or you can use the " --32 " option: by this way the assembler chages its target to the i386 platform.
您必须使用“64 位语法”,或者您可以使用“--32”选项:通过这种方式,汇编器将其目标更改为 i386 平台。
回答by Xiao Jia
Prepend .code32
as your first line.
前置.code32
为您的第一道防线。
--32
option will change the target to 32 bit platform.
--32
选项会将目标更改为 32 位平台。