80 lines
1015 B
PHP
80 lines
1015 B
PHP
|
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
|
||
|
|
||
|
print_number:
|
||
|
xor dx, dx
|
||
|
div bx ; ax = dx:ax / 10, dx = dx:ax % 10
|
||
|
and ax, ax
|
||
|
jz .print
|
||
|
push dx
|
||
|
call print_number
|
||
|
pop dx
|
||
|
.print:
|
||
|
mov al, dl
|
||
|
add al, 0x30
|
||
|
cmp al, 0x3A
|
||
|
jl .noadj
|
||
|
add al, 0x07
|
||
|
.noadj:
|
||
|
call putc
|
||
|
ret
|
||
|
|
||
|
print_string:
|
||
|
push si
|
||
|
mov si, ax
|
||
|
.loop:
|
||
|
lodsb
|
||
|
cmp al, 0x00
|
||
|
je .end
|
||
|
call putc
|
||
|
jmp .loop
|
||
|
.end:
|
||
|
pop si
|
||
|
ret
|