push ebp:“push"的操作数类型不匹配 [英] push ebp: operand type mismatch for `push'
问题描述
我正在尝试使用 gcc -c main.s 编译以下内容
I'm trying to compile the following using gcc -c main.s
.intel_syntax noprefix
.global main
main:
push ebp
mov ebp,esp
sub esp,0x10
mov DWORD PTR [ebp-0xc],0x0
mov eax,DWORD PTR [ebp+0xc]
mov eax,DWORD PTR [eax+0x4]
mov DWORD PTR [ebp-0x4],eax
leave
ret
我得到一个错误:
main.s:6: 错误:`push' 的操作数类型不匹配
main.s:6: Error: operand type mismatch for `push'
这不起作用的原因是什么?
What's the reason this isn't working?
推荐答案
来自 英特尔® 64 位和 IA-32 架构软件开发人员手册,7.3.1.5 64 位模式下的堆栈操作说明:
在 64 位模式下,堆栈指针大小为 64 位,不能被指令前缀覆盖.在隐式堆栈引用中,地址大小覆盖被忽略.在 64 位模式下无法在堆栈上推送和弹出 32 位值.
In 64-bit mode, the stack pointer size is 64 bits and cannot be overridden by an instruction prefix. In implicit stack references, address-size overrides are ignored. Pushes and pops of 32-bit values on the stack are not possible in 64-bit mode.
(强调我的.)
push ebp
尝试压入 32 位寄存器,这在 64 位模式下是不允许的.
push ebp
tries to push a 32-bit register, which is not allowed in 64-bit mode.
这是 32 位代码(即使 push ebp
是可编码的,也会在 64 位模式下崩溃),因此您需要将其组装成 32 位可执行文件.使用 gcc 或 clang,使用
This is 32-bit code (and would crash in 64-bit mode even if push ebp
was encodeable), so you need to assemble it into a 32-bit executable. With gcc or clang, use
gcc -m32 -no-pie -fno-pie main.s -o my_prog
(no-pie 选项不是必需的,但您可能希望它们为 32 位代码获得更简单的位置相关可执行文件.)
(The no-pie options are not necessary, but you probably want them to get a simpler position-dependent executable for 32-bit code.)
这篇关于push ebp:“push"的操作数类型不匹配的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!