N equ 20 ; array count org $1000 ; starting address of on-chip SRAM sum rmb 2 ; array sum i rmb 1 ; array index org $1500 ; starting address of the program ldaa #0 staa i ; initialize loop (array) index to 0 staa sum ; initialize sum to 0 staa sum+1 ; " loop ldab i cmpb #N ; is i = N? beq done ; if done, then branch ldx #array ; use index register X as a pointer to the array abx ; compute the address of array[i] ldab 0,x ; place array[i] in B ldy sum ; place sum in Y aby ; compute sum <- sum + array[i] sty sum ; update sum inc i ; increment the loop count by 1 bra loop done swi ; return to D-Bug12 monitor array db 1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20 end