Zero ds, es and ss at the start of a boot sector
Start a boot sector by zeroing ds, es and ss and setting a stack, because the BIOS leaves them undefined.
The BIOS jumps to your boot sector at physical address 0x7C00, but it does not promise anything about the segment registers. Some BIOSes arrive with CS:IP as 0000:7C00 and others as 07C0:0000. If your code addresses memory through DS before setting it, you read the wrong place. So the first thing a boot sector does is establish a known state: normalise CS with a far jump, then set the other segments to zero and point the stack just below the code.
[bits 16]
[org 0x7C00]
start:
jmp 0x0000:init ; force CS = 0
init:
cli
xor ax, ax
mov ds, ax
mov es, ax
mov ss, ax
mov sp, 0x7C00 ; stack grows down, away from the code
stiCS=0000 DS=0000 ES=0000 SS=0000 SP=7C00The cli and sti pair guards against an interrupt arriving between loading SS and SP. Modern CPUs defer interrupts for one instruction after mov ss, but some 8088 chips did not, and the cost is two bytes of the 512 you have. A stack at 0x7C00 grows downward through free memory below the loader. Assembled with NASM 2.16, and the register rules are in the Intel Software Developer's Manual, volume 3.