gpt4 book ai didi

c++ - Visual Studio中如何通过汇编输出信息

转载 作者:太空宇宙 更新时间:2023-11-04 12:30:50 26 4
gpt4 key购买 nike

我尝试使用汇编程序,当我调用 int 0x80 时我的程序崩溃了。如果我想在我的 C++ 代码中通过汇编程序在控制台中输出一些信息,我应该怎么做?

#include <iostream>

int main()
{
char *msg = "Hello";

__asm
{
mov eax, 4;
mov ebx, 1;
mov ecx, msg;
mov edx, 5;
//int 0x80;
}
system("pause");
return 0;
}

最佳答案

我发现了一些使用 Visual Studio C++ 在 Inline ASM 中输出 Hello world 的有趣方法。

char* hi = "Hello World\n";
char* text = "%s";
__asm
{
mov eax, hi; // load C pointer variable from memory
push eax; // function args on the stack with rightmost highest
mov eax, text;
push eax;
call DWORD ptr printf; // indirect call to DLL function
pop eax; // clean up the stack
pop eax; // with these 2 dummy pops
}

有关它的更多信息,请参阅本文:http://rodrigosavage.blogspot.com/2010/07/hello-world-with-inline-asm.html?m=1

关于c++ - Visual Studio中如何通过汇编输出信息,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58688328/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com