汇编程序如何在Visual Studio中输出信息 [英] How to output information in Visual Studio by assembler

查看:44
本文介绍了汇编程序如何在Visual Studio中输出信息的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I try to use assembler and when I call int 0x80 my program crash. What I should do if I want to output some information in console by assembler in my C++ code?

#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.

I was found some intresting method to output Hello world in Inline ASM using Visual Studio C++.

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

More about it is describe in this article: http://rodrigosavage.blogspot.com/2010/07/hello-world-with-inline-asm.html?m=1

这篇关于汇编程序如何在Visual Studio中输出信息的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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