使用气体装配时推送的指令后缀无效

vit*_*aut 19 linux assembly compiler-errors gnu-assembler

使用GNU汇编程序组装文件时出现以下错误:

hello.s:6:错误:"push"的指令后缀无效

这是我正在尝试汇编的文件:

        .text
LC0:
        .ascii "Hello, world!\12\0"
.globl _main
_main:
        pushl   %ebp
        movl    %esp, %ebp
        subl    $8, %esp
        andl    $-16, %esp
        movl    $0, %eax
        movl    %eax, -4(%ebp)
        movl    -4(%ebp), %eax
        call    __alloca
        call    ___main
        movl    $LC0, (%esp)
        call    _printf
        movl    $0, %eax
        leave
        ret
Run Code Online (Sandbox Code Playgroud)

这里有什么问题,我该如何解决?

虽然问题中的错误和说明不同,但问题与此问题有些相关.

Xia*_*Jia 23

.code32作为您的第一行前置.

--32 选项将目标更改为32位平台.


小智 19

64位指令

默认情况下,大多数操作保持32位,并且REX前缀中的第四位调用64位对应项.这意味着每个32位指令都具有自然的64位扩展,并且扩展寄存器在64位指令中是免费的

movl $1,  %eax     # 32-bit instruction
movq $1,  %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
Run Code Online (Sandbox Code Playgroud)


Car*_*rum 13

你是用64位汇编程序组装的吗?你的代码看起来像是32位.使用64位汇编程序时,我的代码出现此错误:

example.s:6:suffix or operands invalid for `push'
Run Code Online (Sandbox Code Playgroud)

但它适用于32位汇编程序.

  • 就是这样,谢谢.当我使用--32时它可以工作. (3认同)

小智 8

您必须使用"64位语法",或者您可以使用"--32"选项:通过这种方式,汇编程序将其目标转移到i386平台.