大会 x86 上的推送/弹出分段错误 [英] Push/Pop segmentation fault at Assembly x86
问题描述
我正在使用 elf64 来编译我的程序集 x86 代码:我有这个子程序:
I'm using elf64 to compile my assembly x86 code: I've this sub-routine:
printNumber:
mov EAX, EDX ; EDX contain some value like "35"
mov ESI, 10 ; to divide by 10
MOV ECX,0 ; counter
whileDiv:
cmp EAX, 0
je endWhileDiv
xor rdx, rdx ; clean RDX
idiv ESI ; EAX=EAX/10 and EDX = EAX%10
push rdx ; this line generate a segmentation fault
add ECX, 1; count how many items i has added into stack
jmp whileDiv
endWhileDiv:
ret
我正在尝试使用 push 将数字的所有数字推送到我的堆栈中,但我遇到了分段错误.当我评论这一行时:
I'm trying to push all digits of a number into my stack using push, but i'm getting segmentation fault. When I comment this line:
push rdx ; this line generate a segmentation fault
我不会再犯Segmentation Fault"
I'll not take "Segmentation Fault" again
我使用push rdx"而不是push EDX",因为我在 NASM 使用 64 位模式当我尝试使用:push EDX"时,出现此错误:64 位模式不支持指令"
I'm using "push rdx" instead of "push EDX" because I'm using 64-bit mode at NASM and when I try to use: "push EDX", I get this error: "instruction not supported in 64-bit mode"
请有人帮忙告诉我为什么会发生这种情况以及如何解决?
Please, somebody can help tell me why this is happening and how to solve?
PS:对不起我的英语不好
PS: Sorry for my bad english
推荐答案
我看到一个 push rdx,但没有一个 pop rdx.您不断将值压入堆栈,当您到达 RET 时,您将返回到以前 RDX 内容的地址.
I see a push rdx, but nowhere a pop rdx. You keep pushing values on stack and when you reach RET you return to the address which was previously the content of RDX.
这篇关于大会 x86 上的推送/弹出分段错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!