Program to Add Odd Numbers in a Table


Program to continually increment address 0x0000 with short delays between. Example of a program using a subroutine.


; Program using subroutine to make a time delay

prog:   equ     $0800
stack:  equ     $0A00


CODE:   section .text
        org     prog

        lds     #stack      ; initialize stack pointer
        ldaa    #$ff        ; put all ones into $0002
        staa    $02
        clr     $00         ; put $00 into $0000
loop:   jsr     delay       ; wait a bit
        inc     $00         ; add one to $0000
        bra     loop        ; repeat forever


; Subroutine to wait for 100 ms

delay:  psha
        pshx
        ldaa    #250
loop2:  ldx     #800
loop1:  dex    
        bne     loop1
        deca
        bne     loop2
        pulx
        pula
        rts