我使用gnu作为一个简单的引导。它是这样的。
.text
.org 0x7c00
start:
movw $0x7c0, %ax
movw %ax, %ds
movw %ax, %es
leaw greeting_msg, %si
call prtstr
....
end:
.fill 510-(end - start), 1, 0
.word 0xAA55
当输出的hexdump是:
○ → hexdump bare.o
0000000 0000 0000 0000 0000 0000 0000 0000 0000
*
0007c00 c0b8 8e07 8ed8 8dc0 7f36 e87c 0046 02b8
0007c10 bb4f 4115 10cd f883 754f a133 4f01 3e8d
0007c20 7c97 15b9 cd41 8310 4ff8 2275 8b66 9b16
和nasm中的ORG不一样?如果我使用NASM,它输出的东西是这样的。
○ → hexdump test_org
0000000 c031 d88e 14be ac7c c008 0674 0eb4 10cd
0000010 f5eb feeb 6557 636c 6d6f 2065 6f74 4d20
0000020 6361 6e69 6f74 6873 0a0d 0000 0000 0000
0000030 0000 0000 0000 0000 0000 0000 0000 0000
这里有什么问题?谢谢。
你在比较一个二进制文件(来自Nasm)和一个来自(G)as的可链接的.o文件。我想如果你用ld链接你的 "bare.o"...... "ld -o bare.bin -oformat binary bare.o" (不知道语法),你会得到更接近你期望的东西。或者......直接用nasm。
使用 ld -Ttext 0x7c00 --oformat=binary boot.o -o boot.bin
.