nasm写hello.s

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就能运行。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值