Improved safe init for boot sector code
Posted: Tue Dec 22, 2015 6:51 am
OK, so putting everything together from various sources and recent discussions here's what we have for a safe initiation for boot sector code:
Of course others may be willing to point out why you wouldn't want DS or ES to 0 but to be set to some other value. So don't use this if you don't fully understand why DS or ES should be zero.
Code: Select all
BITS 16 ;put in 16 bit mode
ORG 0x7c00
; next line serves purpose other than to satisfy legacy requirement of some machines that require first instruction to be a short jump
jmp short $ + 2 ; or jmp short init ; or jmp short 0x7c02
init:
mov ax, 0 ;getting ready to zero some registers
mov ss, ax ;zero the SS
mov sp, 0x7c00 ;set the beginning of the stack to free memory before 0x07c00
mov ds, ax ;set DS to zero
mov es, ax ;set ES to zero
JMP 0x0000:start ; serves no purpose other than to set CS to zero in the correct manner
start:
...
TIMES 510 - ($ - $$) db 0
DW 0xAA55