2

VS2010 を使用していますが、「mov dword ptr [edx], eax」という行からタイトルにエラーが表示されます。これは、再帰を使用して階乗を見つけ、別の関数 factorial を呼び出して入力の階乗を取得する単純なプログラムです。入力 5 でテストしており、"call factorial" は 120 を返します (当然のことです) が、それを出力に戻そうとするとエラーが発生し、その理由がわかりません。

    push ebx
    push ecx
    push edx

    mov ebx, dword ptr[16 + esp] // input
    mov edx, dword ptr[20 + esp] // &output
    mov eax, ebx // copy ecx

    call factorial

    mov dword ptr [edx], eax
    pop edx
    pop ecx
    pop ebx

    ret

階乗 :

    sub ebx, 1 // eax - 1
    cmp ebx, 1 // if eax equals 1 then end of recursion
    je skip
    push ebx

    call factorial
    pop ebx
    skip:
    mul ebx // multiply ebx * eax
    ret
4

0 に答える 0