2019-04-29 00:01:30 +02:00
|
|
|
printf:
|
|
|
|
cld
|
|
|
|
pop si
|
|
|
|
push bp
|
|
|
|
mov bp, sp
|
|
|
|
.loop:
|
|
|
|
mov al, [cs:si]
|
|
|
|
inc si
|
|
|
|
cmp al, 0x00
|
|
|
|
je .end
|
|
|
|
cmp al, 0x25
|
|
|
|
je .handle_25h
|
|
|
|
.literal:
|
|
|
|
call putc
|
|
|
|
jmp .loop
|
|
|
|
.end:
|
|
|
|
pop bp
|
|
|
|
push si
|
|
|
|
ret
|
|
|
|
.handle_25h:
|
|
|
|
mov al, [cs:si]
|
|
|
|
inc si
|
|
|
|
cmp al, 0x25
|
|
|
|
je .literal
|
|
|
|
cmp al, 0x58 ; 'X'
|
|
|
|
je .printhex
|
|
|
|
cmp al, 0x55 ; 'U'
|
|
|
|
je .printdec
|
|
|
|
cmp al, 0x53 ; 'S'
|
|
|
|
je .printstr
|
|
|
|
mov al, 0x3F
|
|
|
|
jmp .literal
|
|
|
|
.printhex:
|
|
|
|
add bp, 2
|
|
|
|
mov ax, [bp]
|
|
|
|
mov bx, 0x0010
|
|
|
|
call print_number
|
|
|
|
jmp .loop
|
|
|
|
.printdec:
|
|
|
|
add bp, 2
|
|
|
|
mov ax, [bp]
|
|
|
|
mov bx, 0x000A
|
|
|
|
call print_number
|
|
|
|
jmp .loop
|
|
|
|
.printstr:
|
|
|
|
add bp, 2
|
|
|
|
mov ax, [bp]
|
|
|
|
call print_string
|
|
|
|
jmp .loop
|
|
|
|
|
2019-05-05 13:18:36 +02:00
|
|
|
; converts a integer to ascii
|
|
|
|
; in ax input integer
|
|
|
|
; bx base
|
|
|
|
; cx minimum number of digits
|
|
|
|
; out bx garbled
|
|
|
|
; dx garbled
|
|
|
|
print_number_padded:
|
|
|
|
xor dx, dx
|
|
|
|
div bx
|
|
|
|
push dx
|
|
|
|
dec cx
|
|
|
|
jz .nopad
|
|
|
|
call print_number_padded
|
|
|
|
jmp print_number.end
|
|
|
|
.nopad:
|
|
|
|
call print_number
|
|
|
|
jmp print_number.end
|
|
|
|
|
|
|
|
; converts a integer to ascii
|
|
|
|
; in ax input integer
|
|
|
|
; bx base
|
|
|
|
; out bx garbled
|
|
|
|
; dx garbled
|
2019-04-29 00:01:30 +02:00
|
|
|
print_number:
|
|
|
|
xor dx, dx
|
|
|
|
div bx ; ax = dx:ax / 10, dx = dx:ax % 10
|
|
|
|
push dx
|
2019-05-05 13:18:36 +02:00
|
|
|
and ax, ax
|
|
|
|
jz .end
|
2019-04-29 00:01:30 +02:00
|
|
|
call print_number
|
2019-05-05 13:18:36 +02:00
|
|
|
.end:
|
|
|
|
pop bx
|
|
|
|
xor bh, bh
|
|
|
|
add bx, print_chars
|
|
|
|
mov al, [cs:bx]
|
2019-04-29 00:01:30 +02:00
|
|
|
call putc
|
|
|
|
ret
|
|
|
|
|
2019-05-05 13:18:36 +02:00
|
|
|
; putc's a string
|
|
|
|
; in DS:AX null-terminated string
|
2019-04-29 00:01:30 +02:00
|
|
|
print_string:
|
|
|
|
push si
|
|
|
|
mov si, ax
|
|
|
|
.loop:
|
|
|
|
lodsb
|
|
|
|
cmp al, 0x00
|
|
|
|
je .end
|
|
|
|
call putc
|
|
|
|
jmp .loop
|
|
|
|
.end:
|
|
|
|
pop si
|
2019-05-05 13:18:36 +02:00
|
|
|
ret
|
|
|
|
|
|
|
|
print_chars:
|
|
|
|
db "0123456789ABCDEF"
|