1

我正在学习汇编语言,我按照http://mikeos.berlios.de/write-your-own-os.html的步骤制作了一个可启动的图形游戏,但我有一个问题:我不能使用超过 512我的程序的内存字节。

我怎么解决这个问题?

我很感激任何帮助。

这是我的代码(仍然小于 512 字节): http: //pastebin.com/i6ehx8dT

编辑:我解决了我的问题,这里是用 16 位汇编语言制作的软盘引导加载程序的最小示例:http: //pastebin.com/x1SawyjN

最后这个链接很有帮助:http ://www.nondot.org/sabre/os/files/Booting/nasmBoot.txt

4

2 回答 2

2

这并不容易做到:

事实上,BIOS 只将磁盘的前 512 个字节加载到内存中。

然后您要做的就是将其余数据加载到内存中。这通常使用中断 13h(子功能 AH=2 或 AH=42h)来完成。

如果您确切知道数据在磁盘上的位置,这很容易。出于这个原因,像 GRUB 这样的引导加载程序使用众所周知的位置 - 不幸的是,这些位置有时会被其他程序(如复制保护驱动程序)覆盖。

如果您需要从定义明确的文件系统(例如 FAT 或 NTFS)加载,这将更加棘手:您只有约 450 字节的空间(因为文件系统内部使用了 512 字节中的约 60 字节)用于代码解释文件系统的数据,找到包含代码的文件并将其加载到内存中!

于 2014-02-18T19:10:33.457 回答
0

这是我制作的一个简单的引导加载程序:

[org 0x7c00]
; stack and segment setup
xor ax, ax
mov es, ax
mov ds, ax
mov bp, 0x1200  ; thank you user ecm for notifying me to not use
; 0x8000 as the stack address
mov ss, ax      ; thank you user ecm for notifying me to add this specified line of code
mov sp, bp
; load more than 512 bytes into memory
mov ah, 0x02    ; read sectors
mov al, 0x01    ; sectors to read
mov ch, 0x00    ; cylinder idx
mov dh, 0x00    ; head idx
mov cl, 0x02    ; sector idx
mov dl, 0x00    ; disk idx
mov bx, program ; address of more than 512 bytes
int 0x13

; because i'm tired you can do the error checking by checking if al is the
; same as what you set it to and checking for the carry flag

; jump to program (no error checking!)
jmp program

times 510-($-$$) db 0
dw 0xAA55

; more than 512 bytes program
program:
    mov ah, 0x0E
    mov bh, 0x00
    mov al, 'A'
    int 0x10
    jmp $

; amount of zeros = 512 + (number of sectors read * 512)
times 1024-($-$$) db 0
于 2021-10-18T21:35:49.277 回答