Code: Select all
[GLOBAL print_one]
[GLOBAL printk]
screen_x equ 0
screen_y equ 0
string db "Hello, World!", 0
new_line:
mov byte [screen_x], 0
add byte [screen_y], 1
ret
print_one:
; Temporarily use bx as a storage spot for the attrib/char
mov bh, 0x0F
mov bl, al
; Multiply the screen_y by 160 and put it in cx (attrib/char each column, times 80 columns per row)
mov ax, [screen_y]
mov cx, 160
mul cx
mov cx, ax
; Multiply the screen_x by 2 and put it in dx (attrib/char each x value)
mov ax, [screen_x]
mov dx, 2
mul dx
mov dx, ax
; Put the attrib/char back into ax
mov ax, bx
; Put the x and y values into bx
mov bl, dl
mov bh, cl
; Put the video memory location into edi, then add on the x and y values
mov edi, 0xb8000
mov [es:edi], bx
; Put the attrib/char into video memory (At this time - AX=ATTRIB+CHAR, BX=X+Y, ES:EDI=VIDEO MEMORY+BX, DX=X, CX=Y)
stosw
; Increment x
add byte [screen_x], 1
; If the x value is on the last value, goto a new line.
cmp byte [screen_x], 80
je new_line
ret
printk:
; Put the sring in al, increment si, which contains a pointer to a string
lodsb
inc si
; If al = 0x00, end of string
cmp al, 0
je done
; Else, print the character
call print_one
jmp printk
done:
mov al, 'D'
call print_one
call new_line