7

我使用 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 中......

代码有问题吗???

4

2 回答 2

4

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

于 2010-02-01T21:26:16.990 回答
2

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

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

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

于 2010-02-01T18:54:58.140 回答