Error: operand size mismatch for `lea' (seems like syntax error)

Error: operand size mismatch for `lea' (seems like syntax error)

我正在尝试在 GCC 编译的汇编文件中添加函数 S_0x804853E。我正在尝试 assemble 将文件转换为可执行文件。完整的汇编文件如下。

    .file   "simple.c"
    .intel_syntax noprefix
    .text
    .globl  main
    .type   main, @function
main:
.LFB0:
    .cfi_startproc
    push    ebp
    .cfi_def_cfa_offset 8
    .cfi_offset 5, -8
    mov ebp, esp
    .cfi_def_cfa_register 5
    sub esp, 16
    call    __x86.get_pc_thunk.ax
    add eax, OFFSET FLAT:_GLOBAL_OFFSET_TABLE_
    mov DWORD PTR -4[ebp], 3
    mov eax, 0
    leave
    call S_0x804853E # note that this line is manually added.
    .cfi_restore 5
    .cfi_def_cfa 4, 4
    ret
    .cfi_endproc
.LFE0:
    .size   main, .-main
    .section    .text.__x86.get_pc_thunk.ax,"axG",@progbits,__x86.get_pc_thunk.ax,comdat
    .globl  __x86.get_pc_thunk.ax
    .hidden __x86.get_pc_thunk.ax
    .type   __x86.get_pc_thunk.ax, @function
__x86.get_pc_thunk.ax:
.LFB1:
    .cfi_startproc
    mov eax, DWORD PTR [esp]
    ret
    .cfi_endproc
.LFE1:
    .ident  "GCC: (Ubuntu 7.5.0-3ubuntu1~18.04) 7.5.0"
    .section    .note.GNU-stack,"",@progbits
# note that codes below are manually added.
.type   S_0x804853E, @function
S_0x804853E:
    push ebp
    mov esp,ebp
    push ebx
    sub [=10=]x4,esp
    call S_0x80485BB
    add $_GLOBAL_OFFSET_TABLE_,eax
    sub [=10=]xC,esp
    lea S_0x80486B8,edx
    push edx
    mov eax,ebx
    call puts
    add [=10=]x10,esp
    nop
    mov -0x4(ebp),ebx
    leave
    ret
.type   S_0x80485BB, @function
S_0x80485BB:
    mov (esp),eax
    ret

.section .rodata

S_0x80486B8:
    .byte 0x36
    .byte 0x00

我正在使用下面的命令 assemble。错误随之而来。

$ gcc  -m32 -no-pie -nostartfiles simple.s -o simple                                                                                                  
simple.s: Assembler messages:                                                                         
simple.s:49: Error: operand size mismatch for `lea'                                                   
simple.s:55: Error: junk `(ebp)' after expression

我对汇编不是很熟悉。如果问题可以通过 google 轻松解决,我们深表歉意。但是我没有找到任何相关的解释。感谢您的帮助。

主要问题是我搞混了intel和AT&T的语法。该工具生成的代码是 AT&T,没有运营商后缀('b','l','w','q')。 将 C 代码编译为 AT&T 并组成运算符后缀是有意义的。随后是编辑代码。

    .file   "simple.c"
    .text
    .globl  main
    .type   main, @function
main:
.LFB0:
    .cfi_startproc
    pushl   %ebp
    .cfi_def_cfa_offset 8
    .cfi_offset 5, -8
    movl    %esp, %ebp
    .cfi_def_cfa_register 5
    subl    , %esp
    call    __x86.get_pc_thunk.ax
    addl    $_GLOBAL_OFFSET_TABLE_, %eax
    movl    , -4(%ebp)
    movl    [=10=], %eax
    leave
    call S_0x804853E # note that this line is mannally added
    .cfi_restore 5
    .cfi_def_cfa 4, 4
    ret
    .cfi_endproc
.LFE0:
    .size   main, .-main
    .section    .text.__x86.get_pc_thunk.ax,"axG",@progbits,__x86.get_pc_thunk.ax,comdat
    .globl  __x86.get_pc_thunk.ax
    .hidden __x86.get_pc_thunk.ax
    .type   __x86.get_pc_thunk.ax, @function
__x86.get_pc_thunk.ax:
.LFB1:
    .cfi_startproc
    movl    (%esp), %eax
    ret
    .cfi_endproc
# note that codes below are mannally added
.type   S_0x804853E, @function
S_0x804853E:
    pushl %ebp
    movl %esp,%ebp
    pushl %ebx
    subl [=10=]x4,%esp
    call S_0x80485BB
    addl $_GLOBAL_OFFSET_TABLE_,%eax
    subl [=10=]xC,%esp
    lea S_0x80486B8,%edx
    pushl %edx
    movl %eax,%ebx
    call puts
    addl [=10=]x10,%esp
    nop
    movl -0x4(%ebp),%ebx
    leave
    ret
.type   S_0x80485BB, @function
S_0x80485BB:
    movl (%esp),%eax
    ret

.section .rodata

S_0x80486B8:
    .byte 0x36
    .byte 0x00

gcc 可以在没有警告和错误的情况下汇编代码。

------------------------新编辑的分割线---------------- ------

感谢@Peter Cordes 的帮助。 没有必要明确地为所有指令提供 operand-size 后缀。只有在没有声明大小的情况下指令的操作数大小看起来不明确时,我们才使用后缀。 EX:neither操作数是一个寄存器。

movl , -4(%ebp)