[os] 打印字符串

 

第一個例子原理很簡單,但若沒有一定的彙編實踐經驗,還是很容易在各種各樣的細節上栽跟頭的。

下面是我完成任務後的一些總結:

 

1. 我學習彙編的教材是基於dos的, 裏面既介紹了bios中斷,又介紹了dos中斷,我沒有注意兩者的區別,直接調用了一個dos中斷,結果搞了半天愣是沒有結果。

所以使用中斷時要注意區分兩者, linux下不支持dos。

 

2. 寫顯存和調用int 10h(bios中斷) 可以達到一樣的效果。

 

3. 如果有一個字符串需要打印, 例如: PrintMsg: db "hello world";

此時若用ds:si 指向該字符串首地址,ds=PrintMsg, di=0 無法正確讀取字符串。

可以讓ds=cs, si=PrintMsg。 具體原因我現在也說不太清楚。

 

具體代碼如下: 

hello.asm(需要了解一下bios 10h中斷): 

----------------------------------------------------

org 07c00h

mov ax, cs

mov es, ax

 

mov bx, 000ch     ; char attribute

mov cx, 13        ; the string length

mov dh, 1         

mov dl, 1         ; row and column

 

mov bp, ScreenMsg ; the adress of string

 

mov ax, 1301h     ; show the string

int 10h

 

jmp $

ScreenMsg: db  "hello wupeng!"

times 510-($-$$) db 0

dw 0xaa55

-----------------------------------------------------

 

 

boot.sh:

-----------------------------------------------------

#!/bin/bash

nasm hello.asm -o hello.bin

dd if=hello.bin of=a.img bs=512 count=1 conv=notrunc

-----------------------------------------------------

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章