CS225, Examples of Arrays for Warford, PEP8.

;Array of characters
;Array index n in Msg[n] = offset from base address Msg[0]= n
;Outputs characters in a vertical line
     BR main
n: .block 2 ;index of array = offset from base address
Msg: .ascii "Hello\x00" ;Array of chars with sentinel
main: LDA 0, i ; clear A so upper byte = 0 for CPA
     LDX 0, i ; initialize index/offset to 0
     ;STX n, d ; store index (not needed for bytes)
while: LDBYTEA Msg, x ; A<--Mem(Msg+x), i.e. Msg[x]
     CPA 0, i ; if sentinel, leave while
     BREQ endwh
     CHARO Msg, x ; output Msg[x]
     CHARO 0x0A, i ;linefeed
     ;LDX n, d ;load index
     ADDX 1, i ; increment index
     ;STX n, d ;store index
     BR while
endwh: stop
     .end

;Array of numbers
;Array index n in Nums[n]. Offset from base address Nums[0]= 2n
;Outputs numbers in a vertical line
     BR main
n: .block 2 ;index of array = offset from base address
Nums: .word 3 ;Array of numbers with sentinel 0
     .word 7
     .word 15
     .word 31
     .word 0 ; sentinel 0
main:  LDX 0, i ; initialize index/offset to 0 ; LDA 0, i unneeded for words.
     STX n, d ; store index
while: LDA Nums, x ; A<--Mem(Nums+x), i.e. Nums[n]
     CPA 0, i ; if sentinel, leave while
     BREQ endwh
     DECO Nums, x ; output nums[n]=Mem(Nums +x)
     CHARO 0x0A, i ;linefeed
     LDX n, d ;load index
     ADDX 1, i ; increment index
     STX n, d ;store index
     aslx ; calculate offset as 2 times index
     BR while
endwh: stop
.end