I've seen a lot of questions doing the same thing as me but didn't really find an answer that helped me.
Like the title says, I'm trying to make a simple print function that takes an address of a string that was pushed to the stack and print it.
General criticism of my code is obviously more then welcome.
[bits 16]
[global _start]
org 0x7c00 ;set origin to smthn idk someone recommanded it
;globals
buffer: db "Hello World!", 0x0a, 0 ;null terminated string
eop: db "End of program", 0
_start:
xor ax, ax
mov ds, ax ;set data segment to 0
push buffer
call print ;call print with addr of buffer in the stack
mov al, 'F' ;debug
mov ah, 0x0e
int 0x10
jmp $ ;end of program (loop forever)
print:
.prepare:
push bp
mov bp, sp
pusha ;save all registers
mov si, [bp+4] ;use si so save index of string
.char_loop:
mov al, [si] ;offset from added data
add si, 1
cmp al, 0x0 ;string is terminated by null
je .return
mov ah, 0x0e
int 0x10
jmp .char_loop
.return:
popa
pop bp
ret
times 510-($-$$) db 0 ;fill dead space with 0
db 0x55, 0xaa
;end boot sector with 0x55 0xaa