89 lines
1.4 KiB
NASM
89 lines
1.4 KiB
NASM
org 0x100
|
|
|
|
mov ax, 0x3D00
|
|
mov dx, infile
|
|
int 0x21
|
|
jc err
|
|
|
|
mov [fd], ax
|
|
|
|
call getline
|
|
|
|
mov dx, [line_length]
|
|
call dumpdx
|
|
|
|
mov si, line_buffer
|
|
mov cx, [line_length]
|
|
mov ah, 2
|
|
l03: lodsb
|
|
mov dl, al
|
|
int 0x21
|
|
loop l03
|
|
|
|
end: ret
|
|
|
|
line_num: dw 1
|
|
|
|
err: mov dx, ax
|
|
|
|
dumpdx: ; setup bx and ah for int 10h call
|
|
xor bx, bx
|
|
mov ah, 0x0e
|
|
mov cl, 4
|
|
; this double-call is essentially a 4 times repeating loop
|
|
call dmpdx1
|
|
dmpdx1: call dmpdx2
|
|
dmpdx2: ; grab highest nibble from dx
|
|
mov al, dh
|
|
; remove highest nibble from dx
|
|
shl dx, cl
|
|
; shift away second-highest nibble that we accidentally copied
|
|
shr al, cl
|
|
; map 0-9 to ascii codes for '0' to '9'
|
|
add al, 0x30
|
|
; if result is larger than '9', ...
|
|
cmp al, 0x3a
|
|
jl dmpdx3
|
|
; ... add 7 so we continue at 'A'
|
|
add al, 7
|
|
dmpdx3: int 0x10
|
|
ret
|
|
|
|
; read a character from the input file into DL
|
|
getc: mov dl, 26
|
|
push dx
|
|
mov ah, 0x3f
|
|
mov bx, [fd]
|
|
mov cx, 1
|
|
mov dx, sp
|
|
int 0x21
|
|
pop dx
|
|
ret
|
|
|
|
getline: mov word [line_length], 0
|
|
mov di, line_buffer
|
|
mov cx, line_buflen
|
|
l02: push cx
|
|
call getc
|
|
pop cx
|
|
mov al, dl
|
|
cmp al, 0x0A
|
|
je l01
|
|
cmp al, 0x0D
|
|
je l01
|
|
cmp al, 0x1A
|
|
je l01
|
|
inc word [line_length]
|
|
loop l02
|
|
|
|
l01: ret
|
|
|
|
infile: db "com/a86.asm", 0
|
|
|
|
line_buflen: equ 0x100
|
|
line_length: dw 0 ; valid bytes in buffer
|
|
line_prefix: times 16 db " "
|
|
line_buffer: times line_buflen db 0
|
|
|
|
fd: dw 0
|