Code: Select all
bits 16
org 0x7c00
jmp 0x0000:start
start:
call init
clt
hlt
init:
mov ax, 0
mov ss, ax
mov sp, 0x7c00
mov ds, ax
mov es, ax
mov cs, ax
the above is first attempt at a safe init: to be called before doing anything in a bootloader. It's a bit of a mismatch of various pointers I've been able to find here on the wiki and elsewhere on the web. So, it probably contains errors and/or could be improved on.
It seems reasonably well known that it is good practice to set SS and SP as we have no guarantee what state the BIOS left them in. I guess it could be debated what the best value to set them to is. How large a stack do we need? Which area of memory to place the stack in?
I found elsewhere that it is a good idea to zero ES, DS and CS. For CS it seems obvious why as this has implications for segmented memory references. Anybody care to comment on the ES and DS?
I guess what I really have on my mind is whether it would be a good idea to initialise any other registers. I guess it would be good to have a well defined starting point for all registers.
0x00