试图执行组装阶乘但未造成堆栈溢出 [英] Trying to perform a factorial in assembly but causing stack overflow

查看:225
本文介绍了试图执行组装阶乘但未造成堆栈溢出的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

好了,我想从我的大学书考出一个阶乘程序,当我输入正确它如图所示,它给了我一个堆栈溢出错误。

它发生在该行推EBP 。谁能告诉我什么是错?

  code
主要PROC
    MOV EBP,0
    3推
    调用析因
    调用WriteDec
    调用CRLF
    出口
主要ENDP阶乘PROC    推EBP
    MOV EBP,ESP
    CMP EAX,0
    JA L1
    MOV EAX,1
    JMP L2    L1:
        十二月EAX
        推EAX
        调用析因    ReturnFact:
        MOV EBX,[EBP + 8]
        MUL EBX    L2:
        流行EBP
        RET 4阶乘ENDP


解决方案

这只是我或其他人认为你错过了一个

MOV EAX,[EBP + 8]

在(后声明)的函数的开始?
你没有得到从堆栈的说法它和0比较之前。

Ok, so I am trying to test out a factorial program from my college book, and when I type it correctly as shown, it gives me a stack overflow error.

It happens at the line push ebp. Can anyone tell me what is wrong?

.code
main PROC
    mov ebp,0
    push 3
    call Factorial
    call WriteDec
    call Crlf
    exit
main ENDP

Factorial PROC

    push ebp
    mov ebp,esp
    cmp eax,0
    ja L1
    mov eax,1
    jmp L2

    L1:
        dec eax
        push eax
        call Factorial

    ReturnFact:
        mov ebx,[ebp+8]
        mul ebx

    L2:
        pop ebp
        ret 4

Factorial ENDP

解决方案

It is just me or anyone else think that you missed a

mov eax, [ebp+8]

at the start of the function (after the prologue)? You are not getting the argument from the stack before comparing it with 0.

这篇关于试图执行组装阶乘但未造成堆栈溢出的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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