本文介绍了简单的"Hello World" C/C ++中的内联汇编语言程序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

i use devcpp and borland c compiler....

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
}

在上面的代码片段中,我想借助汇编语言来打印字符串...但是我怎么能把字符串的地址放到寄存器cx中呢?...

in the above code snippets i want to print a string with the help of assembly language...but how can i put the address of the string in register cx....

代码中有什么问题吗?

推荐答案

我手头没有Borland编译器,因此我可能记错了它的语法,但是您是否尝试过这种方法:

I don't have the Borland compiler on hand, so I might be misremembering its syntax, but have you tried this:

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),但仍会在运行时引发错误.我会再试一次...

edit: although this will compile (now that I've changed MOV to LDS), it will still throw an error at runtime. I'll try again...

这篇关于简单的"Hello World" C/C ++中的内联汇编语言程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-24 10:52