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

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

免责声明:我不太擅长集会。