64 lines
1.0 KiB
PHP
64 lines
1.0 KiB
PHP
; make a char uppercase
|
|
; IN al char
|
|
; OUT al char
|
|
; do nothing if >z
|
|
ucase cmp al, 0x7B
|
|
jnc .ret
|
|
; do nothing if <a
|
|
cmp al, 0x61
|
|
jc .ret
|
|
; do it!
|
|
sub al, 0x20
|
|
.ret ret
|
|
|
|
; read integer from ascii string
|
|
; default dec but allows 0x for hex
|
|
; bogus result if larger than 16 bit
|
|
; IN ds:si source string
|
|
; cx max number of chars
|
|
; OUT ax number
|
|
; ds:si first rejected char
|
|
; cx chars ignored
|
|
lodnum xor di, di
|
|
mov bx, 10
|
|
cmp cx, 2
|
|
jc .loop
|
|
; test for 0x prefix
|
|
mov ax, [si]
|
|
cmp al, 0x30
|
|
jne .loop
|
|
mov al, ah
|
|
call ucase
|
|
cmp al, 0x58
|
|
jne .loop
|
|
; apply 0x prefix
|
|
.hex add si, 2
|
|
sub cx, 2
|
|
mov bx, 0x10
|
|
; check if there are chars left
|
|
.loop test cx, cx
|
|
jnz .do
|
|
.ret mov ax, di
|
|
ret
|
|
.do mov al, [si]
|
|
call ucase
|
|
; check if in range
|
|
sub al, 0x30
|
|
jc .ret
|
|
cmp al, 0x10
|
|
jc .skip
|
|
sub al, 7
|
|
; must be smaller than base
|
|
; necessary to prevent hex digits in decimals
|
|
.skip mov ah, 0
|
|
cmp ax, bx
|
|
jnc .ret
|
|
; mark as read
|
|
inc si
|
|
dec cx
|
|
; add digit to number
|
|
xchg ax, di
|
|
mul bx
|
|
add di, ax
|
|
jmp .loop
|