gpt4 book ai didi

assembly - BIOS 读取扇区

转载 作者:行者123 更新时间:2023-12-02 06:55:56 27 4
gpt4 key购买 nike

为了学习,我考虑制作一个小型操作系统,现在正在使用引导加载程序。我希望能够使用 int 0x13 从软盘驱动器读取扇区,将它们放入内存,然后跳转到该代码。这是我目前所拥有的:

org 0x7c00
bits 16

main:
call setup_segments

mov ah, 2 ; function
mov al, 1 ; num of sectors
mov ch, 1 ; cylinder
mov cl, 2 ; sector
mov dh, 0 ; head
mov dl, 0 ; drive
mov bx, 0x1000 ;
mov es, bx ; dest (segment)
mov bx, 0 ; dest (offset)
int 0x13 ; BIOS Drive Interrupt

jmp 0x1000:0 ; jump to loaded code

times 510 - ($-$$) db 0 ; fluff up program to 510 B
dw 0xAA55 ; boot loader signature




LoadTarget: ; Print Message, Get Key Press, Reboot

jmp new_main

Greeting: db "Hello, welcome to the bestest bootloader there ever was!", 0
Prompt: db "Press any key to reboot...", 0

Println:
lodsb ; al <-- [ds:si], si++

or al, al ; needed for jump ?
jz PrintNwl ; if null is found print '\r\n'
mov ah, 0x0e ; function
mov bh, 0 ; page number ?
mov bl, 7 ; text attribute ?
int 0x10 ; BIOS Interrupt
jmp Println

PrintNwl: ; print \r\n
; print \r
mov ah, 0x0e ; function
mov al, 13 ; char (carriage return)
mov bh, 0 ; page number ?
mov bl, 7 ; text attribute ?
int 0x10

; print \n
mov ah, 0x0e ; function
mov al, 20 ; char (line feed)
mov bh, 0 ; page number ?
mov bl, 7 ; text attribute ?
int 0x10

ret ; return

GetKeyPress:
mov si, Prompt ; load prompt
call Println ; print prompt

xor ah, ah ; clear ah
int 0x16 ; BIOS Keyboard Service

ret ; return

setup_segments:
cli ;Clear interrupts
;Setup stack segments
mov ax,cs
mov ds,ax
mov es,ax
mov ss,ax
sti ;Enable interrupts

ret

new_main:
call setup_segments

mov si, Greeting ; load greeting
call Println ; print greeting

call GetKeyPress ; wait for key press

jmp 0xffff:0 ; jump to reboot address

times 1024 - ($-$$) db 0 ; fluff up sector

我想将 LoadTarget 之后的扇区加载到地址 0x1000:0 中,然后跳转到它。到目前为止,我只是得到一个空白屏幕。我觉得这个错误在 main 和行 times 510 - ($-$$) db 0 之间。也许我只是没有得到正确的寄存器值?请帮忙!谢谢

最佳答案

您应该将第一个 call setup_segments 替换为完成该工作的实际指令。也正如 Jester 指出的那样,在更改 SS 寄存器时总是更新 SP 寄存器。

当前您正在从柱面 1 读取。它应该是柱面 0。

换行代码是 10(不是你写的 20)。

PrintNwl 中的两个 BIOS 调用都不需要 BL 寄存器,因为 CR 和 LF 都是不可显示的 ascii。

关于assembly - BIOS 读取扇区,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31344628/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com