**请注意,当我说引导程序时,我并不是指引导操作系统的程序。我的意思是,一个简单的程序,当您启动计算机并执行某些操作时就会运行。
好吧,所以我不是极其精通汇编/NASM,但我认为我对它有足够的掌握来编写简单的引导程序。
Well, I thought我已经掌握得足够好了。显然不是。
我尝试了在网上找到的一个简单的启动程序。它运行良好(打印字母“A”)。然后我修改它来打印存储在内存中的一封信。它失败了;它不是打印“A”,而是打印一个笑脸。 (我发誓,电脑现在正在嘲笑我。)
这是源文件中的代码:
[BITS 16] ; We start up in 16-bit real mode
[ORG 0x7C00] ; We're booted into memory at this address. (Or so I'm told)
mov ah, 0x0E ; Teletype command
mov bh, 0x00 ; Page number
mov bl, 0x07 ; Attributes (7 == white foreground, black background)
mov al, [testChar] ; Character to print; load it from the memory referenced by testChar.
int 0x10 ; Tell the BIOS to execute the teletype command.
jmp $ ; Infinite loop prevents us from going off and executing the other junk in memory
testChar db 65 ; This is the character we want to print. 'A'.
; The following code pads the rest of the outputted binary file
; and concludes it with the bootloader signature so I don't have
; to do so manually.
times 510-($-$$) db 0
dw 0xAA55
如果我替换 '移动 al,[testChar]' with '移动阿尔,65',字母“A”打印正确。我尝试过移动内存声明,尝试过在 BITS 和 ORG 周围使用方括号或不使用方括号的每种组合,并且尝试递增和递减 testChar(即 [testChar+1])。每次,它要么打印一个笑脸,一个反笑脸(当我递增 testChar 时),要么什么都不打印(当我将内存声明放在代码之前,可能是因为没有代码正在执行 =P)。我无法让这该死的东西发挥作用。
现在,对于规范(因为它们可能是相关的):
我正在运行带有 Intel Pentium II 处理器的 Dell Latitude CPi,因为这就是我要测试的全部内容(我不是用我的普通计算机测试汇编程序。当然不是。)。我很确定所说的处理器是 x86,因为我在它上面运行过 Windows XP、Ubuntu 和 Arch Linux。
我目前正在使用 NASM 在 Arch Linux 上编写和编译程序。
引导程序从软盘运行
I use 'nasm -f bin 文件名' 来编译代码。
然后,我使用 AL 的“mtools”包中的“mformat”命令,通过“将编译后的引导程序传输到软盘”mformat -f 1440 -B 引导程序 A:'.
那么,我这次又搞砸了什么?或者是我的处理器/BIOS 有问题?