我們加入的主要程式碼如下:
# Reset Floppy (int 0x13, ah = 0x0, dl = 0 (first floppy))
# 重設軟碟機
movb $0x0, %ah
int $0x13
# Read Number 2 (CHS) 讀取第二個磁區的東西
# (int 0x13, ah = 0x2, al = 1, ch = 0, cl = 2, dh = 0, dl = 0, ES:BX = 0x7E00)
movw $0x200, %bx
movb $0x2, %ah
movb $0x1, %al
movb $0x0, %ch
movb $0x2, %cl
movb $0x0, %dh
movb $0x0, %dl
int $0x13
jc error # 如果讀取錯誤 跳至錯誤訊息
jmp second_sector # 跳到下一個磁區的程式
error:
# Print Error 印出錯誤訊息
# (ah = 0x13, al = 0x0, bh = 0, bl = 7, cx = 12, dh:dl=row:column, es:bp=7c0:Message)
movw $0x1300, %ax
movw $0x7, %bx
movw $17, %cx
movw $0x0, %dx
movw $ERROR_MSG, %bp
ERROR_MSG:
.ascii "READ FLOPPY ERROR"
現在的整個程式就長這樣:
.code16
.section .text
# Init all the registers
xorw %ax, %ax
xorw %bx, %bx
xorw %cx, %cx
xorw %dx, %dx
movw $0x7c0, %ax
movw %ax, %es
movw %ax, %ds
movw %ax, %ss
# Reset Floppy (int 0x13, ah = 0x0, dl = 0 (first floppy))
movb $0x0, %ah
int $0x13
# Read Number 2 (CHS)
# (int 0x13, ah = 0x2, al = 1, ch = 0, cl = 2, dh = 0, dl = 0, ES:BX = 0x7E00)
movw $0x200, %bx
movb $0x2, %ah
movb $0x1, %al
movb $0x0, %ch
movb $0x2, %cl
movb $0x0, %dh
movb $0x0, %dl
int $0x13
jc error
jmp second_sector
error:
# Print Error
# (ah = 0x13, al = 0x0, bh = 0, bl = 7, cx = 12, dh:dl=row:column, es:bp=7c0:Message)
movw $0x1300, %ax
movw $0x7, %bx
movw $17, %cx
movw $0x0, %dx
movw $ERROR_MSG, %bp
ERROR_MSG:
.ascii "READ FLOPPY ERROR"
.org 0x1FE, 0x62
.byte 0x55
.byte 0xAA
second_sector:
# Print
# (ah = 0x13, al = 0x0, bh = 0, bl = 7, cx = 12, dh:dl=row:column, es:bp=7c0:Message)
movw $0x1300, %ax
movw $0x7, %bx
movw $12, %cx
movw $0x0, %dx
movw $HELLO_MESSAGE, %bp
int $0x10
Error:
jmp .
HELLO_MESSAGE:
.ascii "Hello world!"
.org 0x400, 0x62
# 繼續接上一篇文章的superblock
我們今天的程式可以讀取第二個磁區,讓我們有更大的空間可以放入我們的程式。
👉【幫我們一個忙!】👈
👋如果您喜歡這篇文章,請在下方按5個Like!
❤您的支持是我們最大的動力!
您只要登入帳號(Facebook、Google),在下方按5個Like,我們就會收到來自LikeCoin基金會的贊助。
您只需要支持我們,完全不會花到錢!