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 ; bios sets in dl the num of the drive that
22 ; loaded you so if you overwrite dl you can reuse it
23 mov [saved_drive_num], dl
25 ; service 0: set videomode ah
26 ; param: which video mode (13h: 320x200, 256 colors) al
27 ; ax: ah (high 8 bits), al (low)
28 ; call 0 = set_videomode it expects the video mode in al
29 ; ah : 0, al: 13, ax:ahal
33 ; software interrupt 10h
34 ; what's the value of ah? al=video mode when ah=0
35 ; which set which video mode
40 ; waiting for keypress
41 ; x86 has 2 special instructions to read/write from I/O
42 ; devices: in and out (because some processors have different
43 ; address spaces for devices and for memory, arm not)
45 in al, 64h ; 60h = keyb data port, 64h = keyb status port
46 and al, 1 ; 1 = OUTBUF_FULL = the keyb controller out buf is full
49 in al, 60h ; reads the keyb that was pressed to reset the flag
51 ; load 2nd sector from boot device and jump to it
52 ; bios helpers, 13h = disk io
55 mov ah, 02h ; call 2: read sectors into memory
56 mov al, 1 ; number of sectors to read
57 mov ch, 0 ; low 8 bits of cylinder number
58 mov cl, 2 ; sector number that starts from 1
59 mov dh, 0 ; head number
60 mov dl, [saved_drive_num] ; 8bits
63 ; error check: if carry flag isn't set jump to loaded code
70 ; video ram is mapped in a0000
71 ; first 64000 bytes appear immediately on screen
72 ; mem addresses in real mode have 2 parts: segment and offset
73 ; bits overlap: segment is shifted by 4 and is added to the
74 ; overlapping offset (20 bits number = x86's addressable space = 1MB)
75 ; segment register for the segment: es, ds, cs, ss (and: fs, gs)
76 ; default register = ds (data segment), es = extra segment
77 ; cs = code segment cs:ip (it points where to read instructions and is
78 ; automatically set to 7c0 (7c00h)
79 ; offset can be paired with any register
90 ; dereferrence[] address
94 ; when cx is 0, 0 flag is set
101 ; assembler trick: write as many 0 needed to fill 510 bytes
103 times 510-($-$$) db 0
108 mov ax, 0a000h ; video segment points to video memory
110 mov bx, 0 ; video offset
116 test ax, 0ff00h ; lower 8 bits 0, highest 1, Z flag is set while < 256, test = and but doesnt change ax
120 mov [bx], al ; pixel written on screen
129 ; fix palette (256 colors)