Background & Hello World

My plans for this project are to make a small game for the IBM PC in 8086 assembly (using NASM as my assembler). This game would be loaded from a floppy disk and use VGA graphics. This is not intended to be a tutorial of any sort, just a record of things I learned about the IBM PC architecture while making this game.

When the IBM PC boots, it looks at each device for a disk with a valid boot sector -- one whose first sector ends with 0xaa55. This sector is loaded at 0x7c00, and execution starts there. I'll start with a hello world.

The IBM PC memory-maps the VGA text buffer to 0xb8000. This buffer has each character cell of the display as a consecutive memory word, with the even bytes representing the character and the odd bytes representing the color.

Here is my hello world program:

org 0x7c00
bits 16

  mov ax, 0xb800
  mov es, ax

  xor di, di
  xor si, si
  mov cx, msg.l
  mov al, byte [msg + si]
  mov byte [es:di], al
  add di, 2
  inc si
  loop ch_loop

  jmp halt

msg db "Hello, world!"
.l equ $ - msg

times 510 - ($ - $$) db 0
dw 0xaa55

Here is a makefile to turn this into a floppy disk image that I can use with virtualization software:

floppy: bin
	dd if=/dev/zero of=floppy.img bs=512 count=2880
	dd if=hello.bin of=floppy.img conv=notrunc

	nasm hello.asm -o hello.bin

Running this makefile and running the floppy disk image in VirtualBox gives me the following:

So we now have a hello world with a makefile and a way to test our bootsector program. Here is a tar archive of the files used for this chapter.