Calling C function from masm 64

余生长醉 提交于 2021-01-01 06:36:39

问题


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.


回答1:


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.



来源:https://stackoverflow.com/questions/29390886/calling-c-function-from-masm-64

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!