58 lines
1.4 KiB
Text
58 lines
1.4 KiB
Text
cpu 8086
|
|
bits 16
|
|
putch: equ 2h
|
|
section .text
|
|
org 100h
|
|
mov cx,16 ; 16 lines
|
|
mov bh,32 ; Start at 32
|
|
dochar: mov al,bh ; Print number
|
|
call putnum
|
|
cmp bh,32 ; Space?
|
|
je .spc
|
|
cmp bh,127 ; Del?
|
|
je .del
|
|
mov [chr],bh ; Otherwise, print character
|
|
mov di,chr
|
|
jmp .out
|
|
.spc: mov di,spc
|
|
jmp .out
|
|
.del: mov di,del
|
|
.out: call putstr
|
|
add bh,16 ; Next column
|
|
cmp bh,128 ; Done with this line?
|
|
jb dochar
|
|
mov di,nl ; Print newline
|
|
call putstr
|
|
sub bh,95 ; Do next line
|
|
loop dochar
|
|
ret
|
|
;;; Print number in AL as ASCII, right-aligned in 3 characters
|
|
putnum: mov dx,2020h ; Put spaces in number
|
|
mov di,num ; Two spaces
|
|
mov [di],dx
|
|
inc di
|
|
inc di
|
|
mov [di],dh ; Third space
|
|
mov bl,10 ; Divisor
|
|
.div: xor ah,ah ; Write digits
|
|
div bl
|
|
add ah,'0'
|
|
mov [di],ah
|
|
dec di
|
|
test al,al
|
|
jnz .div
|
|
mov di,num ; Print number
|
|
putstr: mov ah,putch ; Use zero-terminated strings
|
|
.loop: mov dl,[di]
|
|
test dl,dl
|
|
jz .done
|
|
int 21h
|
|
inc di
|
|
jmp .loop
|
|
.done: ret
|
|
section .data
|
|
num: db ' : ',0 ; Placeholder for number string
|
|
nl: db 13,10,0 ; Newline
|
|
spc: db 'Spc ',0 ; Space
|
|
del: db 'Del ',0 ; Del
|
|
chr: db '* ',0 ; Placeholder for character
|