组件x86的推/弹出分段错误 [英] Push/Pop segmentation fault at Assembly x86

查看:44
本文介绍了组件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

我不会再遇到细分错误"

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

推荐答案

我看到了推送rdx,但没有弹出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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆