

[BITS 16]     ;WE TELL TSM THAT THE CODE SHOULD BE COMPILED as 16BIT code
[ORG 0X7C00] ; WE TELL NASM WE WANT PROGY LOADED AT OFFSETT 0X700 INTO MEMORY
               ; so its loaded at 0x7C00 bytes from the segment 0000

main:		

			
	mov ax, 0x0000 
	mov ds, ax

	mov si, String1       
	call PrintMsg  



PrintMsg:
	mov ah, 0x0e    ;ah= video function mode. of 256 modes we want teletype mode which is 0x0E. The mode requires values in al (character value), bh (bh=page number or type of screen, wel use visible page 0), and bl registers
	mov bh, 0x00
	mov bl,0x07	 ; Text attribute (Controls the background and foreground colour (07 = White text, black background)

.NextChar:
	mov al, [ds:Si] 
		        
	inc si		;Increments the offsett of si to refence the next byte/character in the string
		        ;The aboe two lines can be replaced with lodsb which Loads [si] into al and increment si
	or al, al       ;If al=0(meaning weve gotten to the last character of the string then the Zero flag is set
	jz .Break       ;Jum on zero (jumps wen the flag is 0)
	int 0x10	
	jmp .NextChar   
		        ;Make sure bh and bl are out of the loop cuz they don have to be reloaded.
.Break:
	ret             ;Return to wherever function was called from

;JMP $   ; jumping to the same line of code in never ending loop



	mov si, String2  ;THis stores Strings offsett into si (index register) 
	call PrintMsg

LoadBootstrap:    ;befor bios interupt 0x13 can be run follwing registers must be set
	mov ah, 0x02 ;Read disk sectors
	mov al, 0x01 ;# of sectors to read (1)
	mov ch, 0x00 ;Track 0
	mov cl, 0x02 ;sector 2
	mov dh, 0x00 ;head 0
	mov dl, 0x00 ;drive 0 (floppy 1)  floppy drive ex 0x00 0x01 etc hardrive 0x80 or 0x81...
		     ;most bioses can only load first driver of floppy
	mov bx, 0x1000 ;segment 0x1000
	;the memory lcoation (seg:off) to copy to is es:bx
	mov es, bx ;loading segment into segment register
	mov bx, 0x0000 ;loading the offsett (start of segment)
.readsector
	int 0x13 ;making the bios call
	;when function returns it will make carryflag 0 if sucess or 1 if failure
	jc .readsector ;If there was an error (carryflag=1) try again

	mov ax, 0x1000
	mov ds, ax     ;getting bootstraps segment into segment refister
			;because well be refencing that segment from now on in the bootstrap

	jmp 0x1000:0x0000 ;Jump to bootstraps memory location!



String1: db "Boot loader V0.01A", 13, 10, 0    ; DECLARING a varialbe with A DOUBLE BYTE
String2: db "Just befor loading bootstrap",13,10, 0    ; DECLARING a varialbe with A DOUBLE BYTE


times 510-($-$$) db 0   ;From current location to offset 510 tasm/nasm repeats instruction db (declare byte)
dw 0xAA55               ;0x55 and 0xAA are the two last bytes
			; BECAUSE THATS A BOOTSIGNITURE THAT DEFINES A PROPER
			;BOOT SECTOR
                        ;OUR PROGGY IS NOW EXACTLY 512KB LONG

;New BIOSes seem to ignore the 0xAA55, but you should leave it in
;so your code works OK on old PCs. Also, the Master Boot Record
;(MBR) will not load the bootsector if this value is missing.
