chezzestix wrote:Is using this Interrupt function really all that worth it? I wrote a custom string out function in nine lines... its as short as what its taking to set up the variables for the int function. All you have to do is set di to the address of the string you want to print and call the function.
Code: Select all
sb_strout:
mov al,[di]
cmp al,0
je sbstrout_end
mov ah,0Eh
int 10h
add di,1h
jmp sb_strout
sbstrout_end:
ret
Number of lines is not important. Important is the amount of code it generates, especially when it's part of the bootsector/mbr with very limited space. Instead of "mov al,[di]" and "add di,1h" you can use "lodsb".
Your function has a bug: It doesn't set BX for color attribute and page. Value of BX is uncertain in your function, so textcolor will be unpredicable.
This is my small and safe version, specially written for bootsectors:
Code: Select all
; **********************
; *** Function Print ***
; **********************
;
; Usage: The string must follow directly after the call
; to the function "Print".
;
; For example:
; call Print ; Call printfunction
; db 'Put your message here...',0
; nop ; Program execution continues..
;
Print: cld ; Directionflag=0, for lodsb
pop si ; ds:si -> string
push bp ; BP on stack, buggy bioses
lodsb ; Char from string in AL
NextChar: mov bx,7 ; Color 7 (ordinary light gray)
mov ah,0x0e ; Function 0x0e: Teletype output
int 0x10 ; Call video-BIOS with interrupt 10h
lodsb ; Char from string in AL
or al,al ; Value 0 ?
jnz NextChar ; If not, print this char
pop bp ; Restore BP
push si ; Put the right value of IP on the stack
ret ; Return from function
The way of calling is somethign different: Instead of setting SI or another register for addressing the string, you have to put the string directly after the function call. That save a MOV SI,... instruction (3 bytes of code). The function has a PUSH SI and POP SI instruction to manage the pointer to the string and a goot return from the function, but it makes a call to the function take less (3 bytes) of code macause MOV SI,.. is not necessary.