7

私はdevcppとborlandcコンパイラを使用しています...

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 に答える