从Masm 64调用C函数 [英] Calling C function from masm 64

查看:85
本文介绍了从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.

推荐答案

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函数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆