- 论坛徽章:
- 0
|
下面是《自己动手写操作系统》的第一个例子,开机引导时打印一条语句;
用的是nasm,intel格式。
org 07c00h ; 告诉编译器程序加载到7c00处
mov ax, cs
mov ds, ax
mov es, ax
call DispStr ; 调用显示字符串例程
jmp $ ; 无限循环
DispStr:
mov ax, BootMessage
mov bp, ax ; ES:BP = 串地址
mov cx, 16 ; CX = 串长度
mov ax, 01301h ; AH = 13, AL = 01h
mov bx, 000ch ; 页号为0(BH = 0) 黑底红字(BL = 0Ch,高亮)
mov dl, 0
int 10h ; 10h 号中断
ret
BootMessage: db "Hello, OS world!"
times 510-($-$$) db 0 ; 填充剩下的空间,使生成的二进制代码恰好为512字节
dw 0xaa55 ; 结束标志
|
下面是我改的at&t格式。
.code16
movw %cs, %ax
movw %ax, %ds
movw %ax, %es
movw $bootMessage, %ax
movw %ax, %bp
movw $bmLength, %cx
movw $0x1301, %ax
movw $0x0c, %bx
movb $0, %dl
int $0x10
jmpw *(.)
bootMessage:
.ascii "Hello, OS world! I'm comming!^_^!"
.equ bmLength, . - bootMessage
.org 510
.word 0xaa55
|
下面是at&t格式代码的编译方法。
as boot.s -o boot.o
ld boot.o -o boot.bin -s --oformat binary -Ttext 0x7c00
|
|