Program to Add Odd Numbers in a Table


Write a program to add the odd eight-bit numbers in a table of data starting at address 0xE000 and ending at address 0xE01F. Treat the numbers as unsigned.

prog:   equ     $0800
data:   equ     $0900

array:  equ     $E000
len:    equ     $20

CODE:   section .text
        org     prog

        ldx     #array                  ; initialize pointer
        ldy     #0                      ; initialize sum to 0
loop:   ldab    0,x                     ; get number
        brclr   0,x,$01,even            ; check to see if even
        aby                             ; odd - add to sum
even:   inx                             ; point to next entry
        cpx     #(array+len)            ; more to process?
        blo     loop                    ; if so, process
        sty     answer                  ; done -- save answer
        swi

DATA:   section .data
        org     data
answer: ds.w    1               ; reserve 16-bit word for answer