NASM是一个为可移植性与模块化而设计的一个80x86的汇编器,以前在windows下用的,没想到还能在Linux下用,比as86亲切多了。
转载:http://people.cs.nctu.edu.tw/~huangmc/works/web/Boot_x86/Boot_x86.html
[BITS 16]
ORG 0
jmp START
START:
; code located at 0x0000:7C00, adjust segment registers
cli
mov ax, 0x07C0
mov ds, ax
mov es, ax
mov fs, ax
mov gs, ax
; create stack
mov ax, 0x0000
mov ss, ax
mov sp, 0xFFFF
sti
; set_VGA_mode
mov ah, 0x00 ; set display mode
mov al, 0x02 ; 640x200, 16 color, 80x25, 8 pages
int 0x10 ; invoke BIOS
; set_cursor
mov ah, 0x02 ; set cursor
mov dh, 0x0C ; row number (12d)
mov dl, 0x1E ; col number (31d)
mov bh, 0x00 ; page number
int 0x10 ; invoke BIOS
; post message
mov si, msgHello
call DisplayMessage
; set_cursor
mov ah, 0x02 ; set cursor
mov dh, 0x0D ; row number (13d)
mov dl, 0x25 ; col number (37d)
mov bh, 0x00 ; page number
int 0x10 ; invoke BIOS
GetChar:
mov ah, 0x00 ; get keyboard char
int 0x16
cmp al, 0x03 ; if "Ctrl+C"
je END ; yes? goto end;
; print
mov ah, 0x09 ; print
mov bh, 0x00 ; page number
mov bl, 0x1E ; property 'yellow word, blue background'
mov cx, 0x01 ; times
int 0x10 ; invoke BIOS
jmp GetChar ; goto GetChar;
END:
int 0x19 ; jump to FFFF:0 (BIOS)
int 0x20 ; end
DisplayMessage:
lodsb ; load next character
or al, al ; test for NUL character
jz .DONE
mov ah, 0x0E ; BIOS teletype
mov bh, 0x00 ; display page 0
mov bl, 0x07 ; text attribute
int 0x10 ; invoke BIOS
jmp DisplayMessage
.DONE:
ret
msgHello db "Hello Jasonmel!", 0x0D, 0x0A, 0x00
TIMES 510-($-$$) DB 0
DW 0xAA55
guang@guang-laptop:~/temp/h/nasm$ ls
a.bxrc boot.bin boot.s hello.img makefile
all:
nasm -o boot.bin boot.s
dd if=boot.bin of=hello.img
bochs -q -f a.bxrc
clean:
rm -rf boot.bin
make就能运行。