1 ; org: all instructions from now on start in 7c00h
2 ; 7c00h is where the bios loads the 1st sector
3 ; assembler formatting:
7 ; at boot: real mode (like it's 8086)
8 ; we have to tell assembler that code is 16bit mode
14 ; initialize segment registers
21 mov [saved_drive_num], dl
23 ; service 0: set videomode ah
24 ; param: which video mode (13h: 320x200, 256 colors) al
25 ; ax: ah (high 8 bits), al (low)
29 ; software interrupt 10h
34 ; load 2nd sector from boot device and jump to it
35 ; bios helpers, 13h = disk io
38 mov ah, 02h ; call 2: read sectors into memory
39 mov al, 1 ; number of sectors to read
40 mov ch, 0 ; low 8 bits of cylinder number
41 mov cl, 2 ; sector number that starts from 1
42 mov dh, 0 ; head number
43 mov dl, [saved_drive_num] ; 8bits
46 ; error check: if carry flag isn't set jump to loaded code
53 ; video ram is mapped in a0000
54 ; first 64000 bytes appear immediately on screen
55 ; mem addresses in real mode have 2 parts: segment and offset
56 ; bits overlap: segment is shifted by 4 and is added to the
57 ; overlapping offset (20 bits number = x86's addressable space = 1MB)
58 ; segment register for the segment: es, ds, cs, ss (and: fs, gs)
59 ; default register = ds (data segment), es = extra segment
60 ; cs = code segment cs:ip (it points where to read instructions and is
61 ; automatically set to 7c0 (7c00h)
62 ; offset can be paired with any register
73 ; dereferrence[] address
77 ; when cx is 0, 0 flag is set
84 ; assembler trick: write as many 0 needed to fill 510 bytes