簡體   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