【发布时间】:2013-04-05 08:40:34
【问题描述】:
我正在处理一个在程序集中实现一个在 main.c 中调用的函数的项目。 C 中的签名函数声明是void strrev(char *str) ; Ret 指令给了我一个非法指令错误。为什么?这是我第一次这样做。
尝试只发布相关代码:
SECTION .text
global strrev
strrev:
push ebp
mov ebp, esp
push esi
push edi
push ebx
// doing things with al, bl, ecx, edi, and esi registers here
// restore registers and return
mov esp, ebp
pop ebx
pop edi
pop esi
pop ebp
ret
错误:
(gdb)
Program received signal SIGILL, Illegal instruction.
0xbffff49a in ?? ()
以这种方式编译和链接:
nasm -f elf -g strrepl.asm
nasm -f elf -g strrev.asm
gcc -Wall -g -c main7.c
gcc -Wall -g strrepl.o strrev.o main7.o
【问题讨论】:
-
仔细观察调试器中弹出的内容以及返回的位置。
标签: c function assembly x86 nasm