繁体   English   中英

C / C ++中的简单“Hello World”内联汇编语言程序

[英]a Simple “Hello World” Inline Assembly language Program in C/C++

我用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
}

在上面的代码片段中,我想在汇编语言的帮助下打印一个字符串...但是如何将字符串的地址放在寄存器cx ....

代码中有什么问题???

我手边没有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),但它仍会在运行时抛出错误。 我会再尝试...

只需将变量名称放在那里:

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

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

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM