47 lines
1.2 KiB
Plaintext
47 lines
1.2 KiB
Plaintext
org 100h
|
|
lxi b,0 ; Let (B)C be the array index
|
|
outer: lxi d,As ; Use DE to walk the array-of-arrays
|
|
inner: xchg ; Swap DE and HL (array-of-array pointer into HL)
|
|
mov e,m ; Load low byte of array pointer into E
|
|
inx h
|
|
mov d,m ; Load high byte of array pointer into D
|
|
inx h
|
|
xchg ; Array base in HL, array-of-array pointer in DE
|
|
mov a,h ; Is HL 0?
|
|
ora l
|
|
jz azero ; If so, we are done.
|
|
dad b ; Otherwise, add index to array base
|
|
mov a,m ; Get current item (BC'th item of HL)
|
|
call chout ; Output
|
|
jmp inner ; Next array
|
|
azero: mvi a,13 ; Print newline
|
|
call chout
|
|
mvi a,10
|
|
call chout
|
|
inr c ; Increment index (we're only using the low byte)
|
|
mvi a,Alen ; Is it equal to the length?
|
|
cmp c
|
|
jnz outer ; If not, get next item from all the arrays.
|
|
ret
|
|
;;; Print character in A, saving all registers.
|
|
;;; This code uses CP/M to do it.
|
|
chout: push psw ; CP/M destroys all registers
|
|
push b ; Push them all to the stack
|
|
push d
|
|
push h
|
|
mvi c,2 ; 2 = print character syscall
|
|
mov e,a
|
|
call 5
|
|
pop h ; Restore registers
|
|
pop d
|
|
pop b
|
|
pop psw
|
|
ret
|
|
;;; Arrays
|
|
A1: db 'a','b','c'
|
|
A2: db 'A','B','C'
|
|
A3: db '1','2','3'
|
|
Alen: equ $-A3
|
|
;;; Zero-terminated array-of-arrays
|
|
As: dw A1,A2,A3,0
|