本文介绍了从Masm 64调用C函数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的汇编代码有问题(在Win8 64上的Visual 2013中为64位错误).当我调用C函数(printf)时,它将引发ntdll.dll的异常.我做错了什么?如何在64位错误中从控制台读取和写入数据?在哪里可以找到有关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我正在从C ++代码调用printData.

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

推荐答案

Windows x64调用约定要求您传递以RCX开头的参数,然后根据需要传递RDX,R8和R9.在这种情况下,您可能只需要RCX来存储格式的地址,而RDX则是要打印的整数值.

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.

这篇关于从Masm 64调用C函数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-19 16:25
查看更多