Mateusz Jachna
Mateusz Jachna

Reputation: 49

Calling C function from masm 64

I have a problem with my assembly code (64 bit masm in Visual 2013 on win8 64). When I'm calling C function (printf), it throwing exception from ntdll.dll. What I'm doing wrong? How I can read and write data from console in 64 bit masm? Where I can find good tutorial for masm 64 bit?

extrn printf : proc
.data
format byte "Arg1: %d", 10, 0

.code
printData proc

mov rbx, 100
push rbx

lea rax, format; format address
push rax

call printf; throw unhandled exception ntdll.dll - Access violation reading location 0xFFFFFFFFFFFFFFFF.
add rsp, 16 ;2* 64bit value

ret
printData endp
end

P.S I'm calling printData from C++ code.

Upvotes: 2

Views: 4107

Answers (1)

Aaron Altman
Aaron Altman

Reputation: 1755

The Windows x64 calling convention requires you to pass arguments starting in RCX, followed by RDX, R8 and R9 if needed. In this case you probably just need RCX to store the address of format, and RDX the integer value you want to print.

Upvotes: 2

Related Questions