Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/assembly/6.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Assembly 我遇到堆栈溢出,我';我不太确定怎么做_Assembly_64 Bit_X86 64_Masm - Fatal编程技术网

Assembly 我遇到堆栈溢出,我';我不太确定怎么做

Assembly 我遇到堆栈溢出,我';我不太确定怎么做,assembly,64-bit,x86-64,masm,Assembly,64 Bit,X86 64,Masm,当我从组合中递归调用阶乘过程时,就会发生这种情况。它在阶乘过程上抛出异常。我已经包含了我所有的代码,但问题与堆栈和阶乘过程有关。这是当我出于某种原因试图推动rax的时候。我不明白为什么会这样。这是我的密码: INCLUDELIB libcmt.lib INCLUDELIB legacy_stdio_definitions.lib EXTERN printf:PROC EXTERN scanf:PROC .DATA promt BYTE "1permutation..2)combinat

当我从组合中递归调用阶乘过程时,就会发生这种情况。它在阶乘过程上抛出异常。我已经包含了我所有的代码,但问题与堆栈和阶乘过程有关。这是当我出于某种原因试图推动rax的时候。我不明白为什么会这样。这是我的密码:

INCLUDELIB libcmt.lib
INCLUDELIB legacy_stdio_definitions.lib

EXTERN printf:PROC
EXTERN scanf:PROC
.DATA
    promt BYTE "1permutation..2)combination ",0
    inFmt BYTE "%d",0
    disp BYTE "You entered %d", 10, 0
    num QWORD ?
    fct_num QWORD ?
    num2 REAL8 1.5
    factpromt BYTE "What number do you want to find the factorial of?",0
    factFmt BYTE "%d",0
    factNum BYTE "The result is = %d", 10, 0
    n   QWORD   ?
    r   QWORD   ?
    result  QWORD   ?
    answer  QWORD   ?
    divisor QWORD   ?

   .CODE
   main PROC
 push   divisor         ;ebp+20
 push   n              ;ebp+16
 push   r              ;ebp+12
 push   result          ;ebp+8
 sub    rsp, 24
 lea    rcx, promt      ;for x64
 call   printf
 lea    rdx, num        ;for x64
 lea    rcx, inFmt      ;for x64
 call   scanf
 mov    rdx, num
 cmp    rdx, 2
 je     run_comb
 jmp    run_perm
 run_perm:
    call permutation
 run_comb:
    call combination
 ;lea   rcx, disp
 ;call  printf
 add    rsp, 24
 mov    eax,0
 ret
 main ENDP



factorial PROC 

mov     rax,qword ptr [rsp+8]
cmp     rax,1
jle     endRecursive
dec     rax
push    rax;throws exception here
call    factorial
mov     rsi,qword ptr [rsp+8]
mul     rsi
endRecursive:
    ret 8



factorial ENDP

permutation PROC 

mov ecx, 5
mov eax, ecx

ret
permutation ENDP

combination PROC 

push    rbp
mov     rbp,rsp

mov     rax, [rbp+32]   ;find (n-r)!
sub     rax, [rbp+24]
mov     rbx, rax
push    rbx
call    factorial
mov     rdx,[rbp+40]    ;move (n-r)! into result
mov     [rdx],rax

mov     rbx, [rbp+24]        ;find r!
push    rbx
call    factorial


mov     rdx,[rbp+40]
mov     rbx, [rdx]
mul     rbx         ;r!*(n-r)!, store product in eax
mov     rbx, [rbp+40]
mov     [rbx], rax          ;store product in divisor variable

mov     rbx, [rbp+32]   ;find n!
push    rbx
call    factorial
mov     rdx,[rbp+40]            
mov     rbx,[rdx]           ;move value of divisor into ebx

mov     rdx, 0
div     rbx         ;divide n! by divisor (r!*(n-r)!)
mov     rbx, [rbp+16]
mov     [rbx],rax                 ;move quotient into result

pop     rbp
ret     32
combination ENDP

END

您是否尝试过通过VisualStudio之类的调试器运行此功能?应该告诉你什么指示的东西是失败的。通过查看寄存器/堆栈/内存,您应该能够调试它。。。似乎没有初始化。如果它们包含随机值,您可能会计算一些非常大的值(例如
100000000!
)。因为每个递归调用需要16个字节的堆栈,如果堆栈小于您要计算的数字的16倍,那么堆栈将失败。