Posted on 2015-01-08 14:34
jacky_zz 阅读(271)
评论(0) 编辑 收藏 引用 所属分类:
ASM
bootloader.asm
org 0x7c00
start:
jmp main_entry
stack:
times 128 db 0
tos:
db 0
main_entry:
mov ax, cs
mov ds, ax
mov ax, stack
mov ss, ax
mov sp, start
; initialize es:bx, read data to 0x0000:0x7e00
mov ax, 0x0000
mov es, ax
mov bx, 0x7c00+0x200
mov ah, 0x02 ; read function
mov al, 0x01 ; read 1 sectors
mov ch, 0x00 ;
mov cl, 0x02 ; read from 2nd section
mov dh, 0x00 ;
mov dl, 0x80 ; read from 1st hard disk
int 0x13
jc .die
; install interrupt 0x80
call 0x7e00
; call interrupt 0x80
mov ax, msg1
int 0x80
; call interrupt 0x80
mov ax, msg2
int 0x80
.die:
jmp $
print_char:
mov ah, 0x0e
int 0x10
ret
msg1: db "Loading system ", 0x0d, 0x0a, 0
msg2: db "Hello, World!", 0x0d, 0x0a, 0
crlf: db 0x0d, 0x0a, 0
fill_zero:
times 510-($-$$) db 0
magic:
db 0x55, 0xAA
lib16.asm
org 0x7e00
install_int:
mov ax, 0
mov es, ax
mov ax, int_0x80
mov bx, 0x80*4
mov word [es:bx], ax ; ip
mov word [es:(bx+2)], 0 ; cs
ret
int_0x80:
pusha
mov si, ax
mov ah, 0x0e
mov al, [ds:si]
.loop:
cmp al, 0
je .exit
int 0x10
inc si
mov al, [ds:si]
jmp .loop
.exit:
popa
iret
fill_zero:
times 512-($-$$) db 0
结果图: