当前位置: 代码网 > it编程>编程语言>C/C++ > Visual Studio-X64汇编编写方法

Visual Studio-X64汇编编写方法

2024年09月30日 C/C++ 我要评论
纯64位汇编:includelib ucrt.libincludelib legacy_stdio_definitions.libincludelib user32.libextern printf:

纯64位汇编:

includelib ucrt.lib
includelib legacy_stdio_definitions.lib
includelib user32.lib
extern printf:proc
extern messageboxa:proc
.data
szformat db "%s",0
szhello db "helloworld",0
szrk db "123",0
.code
start proc
	sub rsp,28h
	mov rdx,offset szhello
	mov rcx,offset szformat
	call printf
	mov r9,0
	mov r8,offset szhello
	mov rdx,offset szrk
	mov rcx,0
	call messageboxa
	add rsp,28h
	ret
start endp
end 

注意:

1.平台工具集要选vs2015

2.属性->生成依赖项->masm

3.链接器->高级->入口点

64位混合编程(c++/asm):一定要严格执行代码规范,不然各种报错

1.asm:

includelib legacy_stdio_definitions.lib
includelib user32.lib
extern printf:proc
.data
	szformat db "%s\n",0
.code
myadd proc
	sub rsp,28h
	add rcx,rdx
	mov	rax,rcx
	add rsp,28h
	ret
myadd endp
myprintf proc
	sub rsp,28h
	mov rdx,rcx
	lea rcx,szformat
	call printf
	add rsp,28h
	ret
myprintf endp
end 

main.cpp:

#include <iostream>
#include <windows.h>
extern_c uint64 myadd(uint64 a, uint64 b); 
extern_c void myprintf(const char* szbuffer);
int main()
{
	uint64 num = myadd(1, 2);
	printf("%lld\r\n", num);
	myprintf("hello word");
	system("pause");
	return 0;
}

注意:

如果生成报错,并且没有属性里面没有microsoft macro assembler,换成vs2015也没有的话,

就在源文件里面找到.asm后缀的文件右键属性->常规->项类型->microsoft macro assembler即可。

到此这篇关于visual studio-x64汇编编写的文章就介绍到这了,更多相关visual studio-x64汇编内容请搜索代码网以前的文章或继续浏览下面的相关文章希望大家以后多多支持代码网!

(0)

相关文章:

版权声明:本文内容由互联网用户贡献,该文观点仅代表作者本人。本站仅提供信息存储服务,不拥有所有权,不承担相关法律责任。 如发现本站有涉嫌抄袭侵权/违法违规的内容, 请发送邮件至 2386932994@qq.com 举报,一经查实将立刻删除。

发表评论

验证码:
Copyright © 2017-2025  代码网 保留所有权利. 粤ICP备2024248653号
站长QQ:2386932994 | 联系邮箱:2386932994@qq.com