首页 > 解决方案 > 使用 nasm 汇编程序可以正常打印的引导加载程序

问题描述

所以我试图使用 NASM 汇编器运行下面的程序。因为我想告诉汇编程序我想要一个没有任何花里胡哨的纯二进制文件,所以我使用了:

nasm -f -o boot.bin boot.asm 错误:nasm 致命:无法打开输入文件“boot.bin”

有人请帮忙。为什么我会收到这个错误以及如何解决它。

这是代码:

bits 16
start:
mov ax, 0x07C0     ;0x07C0 is where we are
add ax, 0x20       ;add 0x20 (when shifted 512)
mov ss,ax          ;set the stack segment
mov sp, 0x1000     ; set the stack pointer
mov ax, 0x07C0     ; set data segment
mov ds, ax         ;more about this later

mov si, msg        ;pointer to the message in SI
mov ah, 0x0E       ;print CHAR BIOS procedure

.next:
lodsb ;next byte to AL, increment SI
cmp al, 0 ;if the byte is zero
je .done ;jump do done
int 0x10 ;invoke the BIOS system call
jmp .next ;loop

.done:
jmp $ ;loop forever
msg: db 'ok',0  ;The string we want to print
times 510-($-$$) db 0  ;fill up to 510 bytes
dw 0xAA55 ;master boot record signature

标签: assemblynasmx86-16bootloaderreal-mode

解决方案


您可以使用NASM 中的选项指定BIN ary 。-f bin你想要的是:

nasm -f bin -o boot.bin boot.asm

如果您未指定,则默认值为二进制,-f因此这也可以:

nasm -o boot.bin boot.asm

推荐阅读