如何将汇编文件编译为512b文件?

时间:2014-03-30 14:59:56

标签: bootloader

我想写一个小的bootloader,我使用命令"作为boot.s"编译它。我想我应该有一个512B的文件,但是我得到一个1448B的文件太大而不能成为一个bootloader。 我的代码有什么问题?谢谢。

.code16
.global _start
_start:
    movw $0x7c00, %ax
    movw %ax, %ds
    movw %ax, %es
    call Dispstr
    call loop
Dispstr:
    movw BootMessage, %ax
    movw %ax, %bp
    movw $0x1301, %ax
    movw $0x000c, %bx
    movb $0, dl
    int $0x10
    ret
loop:
    jmp loop
BootMessage:
    .asciz "Hellow World"
.org 510, 0
.word 0xaa55

2 个答案:

答案 0 :(得分:0)

尝试

times 510-($-$$) db 0   ; Pad remainder of boot sector with 0s
dw 0xAA55       ; The standard PC boot signature

而不是

.org 510, 0
.word 0xaa55

另见本文http://mikeos.berlios.de/write-your-own-os.html

答案 1 :(得分:0)

我自己解决了。 LD --oformat binary -o boot boot.o 切断ELF文件头

相关问题