Outputing text using interrupts

boot.asm

[ORG 0x7c00]
 
jmp main
 
msg   db 'The itsy bitsy spider climbed up the waterspout. Down came the rain and washed the spider out. Out came the sun and dried up all the rain and the itsy bitsy spider climbed up the spout again.',0x0

; reference
; http://en.wikipedia.org/wiki/INT_10H
main:
    mov     ah, 0xe			; 0xe is used for teletype output
    mov     edx, 0			; edx is our string offset
    ch_loop:
    mov     al, [msg + edx] ; copy character into al from string offset
    int     0x10			; call interrupt 0x10 to output character
    inc     edx				; increment edx (move to next character)
    test    al, al			; test for 0
    jnz     ch_loop			; if not 0, go to ch_loop
     
    hlt
     
    times 510-($-$$) db 0
    db 0x55
    db 0xAA

nasm -f bin -o boot.img boot.asm

Output text using video memory

boot.asm

[ORG 0x7c00]
 
jmp main
 
msg   db 'The itsy bitsy spider climbed up the waterspout. Down came the rain and washed the spider out. Out came the sun and dried up all the rain and the itsy bitsy spider climbed up the spout again.',0x0
 
main:
    mov     ax, 0xb800			; 0xb800 is starting address to Color Video Memory
    mov     es, ax				; copy 0xb800 to es register
    mov     di, 0				; set di to 0
    
	; Now we have [es:di] => 0xb800:0x0
    mov     bx, 0				; bx is going to be our string offset
    loop:
	; must be aligned as the following
	; byte 1: character
	; byte 2: the color of character
    movzx   cx, byte[msg + bx]	; copy character from msg plus offset into cx
								; NOTE: must specify to copy a byte
    mov     ax, cx				; copy into character (in cx) into ax
    stosb						; copies at AL into [ES:DI]
    mov     ax, 5				; 5 is the color Magenta
    stosb						; copies at AL into [ES:DI]
    inc     bx					; increment bx (move to next character)
    test    cx, cx				; test for 0
    jnz     loop				; if not zero, go to loop
	
    hlt
	
    times 510-($-$$) db 0
    db 0x55
    db 0xAA

nasm -f bin -o boot.img boot.asm