format COFF

public Boot_Sector
Boot_Sector:

use16	    ; We need 16-bit intructions for Real Mode

ORG 0x7C00  ; The BIOS loads the boot sector into this memory location

; Main program
main:
mov ax,0x0000	     ; Setup the Data Segment register
		     ; Location of data in DS:Offset
mov ds,ax	     ; This can not be loaded directly. Is has to be in two steps.
		     ; "mov ds,0x0000" will NOT work due to limitations on CPU.
mov si,HelloWorld    ; Load the string into position for the procedure.

call PutStr	     ; Run the procedure

;Procedures
PutStr: 	     ; Set up the register for the interrupt call

mov ah,0x0E	     ; The function to display a character
mov bh,0x00	     ; Page number
mov bl,0x07	     ; Normal attribute

;****************************************************************************************
nextchar:	; Internal label (needed to loop round for the next character)
lodsb		; I think of this as LOaD String Block

;Check for end of string '0'. The or instruction in this context is just to
;put 0 or 1 on ZF (zero flag). If is the end of string, put 1, 0 otherwise.
or al,al

jz return	; If the zero flag has been set go to the end of the procedure.
		; Zero flag gets set when an instruction returns 0 as the answer.

int 10h ; Run the BIOS video interrupt

jmp nextchar	; Loop back round to the top
;****************************************************************************************

;****************************************************************************************
return: 	; Label at the end to jump when complete
ret		; Return to main program
;****************************************************************************************

; Data

HelloWorld db 'Hello World',13,10,0

; End matter
times 510-($-$$) db 0 ; Boot loader MUST have 512 bytes long.
dw 0xAA55 ; Boot loader signature