0

I'm writing a simply x64 assembly program in Visual Studio. Whenever the program runs, the following exception gets thrown: 0xC0000005: Access violation executing location (memory address). It's strange, because the exception only gets thrown once the code has completely finished executing.

I've narrowed the cause of the exception down to a call to a C++ function from the assembly.

The exception

Here's my code:

printNum proto C

.code

main proc

    ; Do stuff

NoBuzz:
    cmp rbp, 0
    jne NoNum
    mov rcx, rbx
    call printNum ; Removing this line prevents the exception

    ; Do stuff

    ret
main endp

end
#include <iostream>

extern "C" void printNum(int Num)
{
    std::cout << Num;
}
Peter Cordes
  • 286,368
  • 41
  • 520
  • 731
  • Looks like you didn't align the stack, and more importantly didn't reserve shadow space, so probably your return address is getting overwritten. – Peter Cordes Nov 24 '21 at 10:32

0 Answers0