【问题标题】:a Simple "Hello World" Inline Assembly language Program in C/C++C/C++ 中的简单“Hello World”内联汇编语言程序
【发布时间】:2011-01-11 20:37:21
【问题描述】:

我使用 devcpp 和 borland c 编译器....

asm {
    mov ax,4       // (I/O Func.)
    mov bx,1       // (Output func)  
    mov cx,&name   // (address of the string)
    mov dx,6       // (length of the string)
    int 0x21       // system call
}

在上面的代码 sn-ps 中,我想在汇编语言的帮助下打印一个字符串... 但是我怎样才能将字符串的地址放入寄存器 cx....

代码有问题吗???

【问题讨论】:

  • 0x21 - 非常感谢您了解基础知识 :-)
  • 字符串是如何存储的?即:name 的声明是什么?
  • 我建议忽略 16 位实模式汇编,直接从 32 位汇编开始。如今,它变得更加容易和实用。
  • 好吧thanx....但是有什么方法可以获取字符串的地址并放回cx寄存器...或者您是否尝试过内联汇编...我只需要一点帮助...所以我可以从 asm 开始...任何例子???

标签: c assembly x86 inline-assembly


【解决方案1】:

只要把变量名放进去:

mov ax,4       // (I/O Func.)
mov bx,1       // (Output func)  
mov cx,name   // (address of the string)
mov dx,6       //  (lenght of the string)
int 0x21       // system call

免责声明:我不太擅长组装。

【讨论】:

    【解决方案2】:

    我手头没有 Borland 编译器,所以我可能记错了它的语法,但是你试过这个吗:

    asm {
        mov ax,4       // (I/O Func.)
        mov bx,1       // (Output func)  
        lds cx,"Hello, world" // (address of the string)
        mov dx,6       //  (length of the string)
        int 0x21       // system call
    }
    

    或者这个:

    char msg[] = "Hello, world";
    
    asm {
        mov ax,4       // (I/O Func.)
        mov bx,1       // (Output func)  
        lds cx, msg   // (address of the string)
        mov dx,6       //  (length of the string)
        int 0x21       // system call
    }
    

    编辑:虽然这会编译(现在我已将 MOV 更改为 LDS),但它仍会在运行时抛出错误。我再试一次...

    【讨论】:

    • 不,它不起作用......它给出错误......有没有其他方法可以让我得到字符串的地址......然后放回cx寄存器....
    • 据我所知,mov cx,msgmsg 的地址放入cx 寄存器。你得到了什么?
    • @vs4vijay 您不应该接受无效的解决方案作为答案,因为它具有误导性。
    猜你喜欢
    • 1970-01-01
    • 2013-03-10
    • 1970-01-01
    • 1970-01-01
    • 2013-10-29
    • 1970-01-01
    • 1970-01-01
    • 2011-02-08
    • 1970-01-01
    相关资源
    最近更新 更多