N equ 20 ; array count org $1000 ; starting address of on-chip SRAM max_val rmb 1 ; memory location to hold array max org $1500 ; starting address of program ldaa array ; set array[0] as the temporary array max staa max_val ; " ldx #array+N-1 ; start from the end of the array ldab #N-1 ; use B to hold variable i and initialize it to N-1 loop ldaa max_val cmpa 0,x ; compare max_val with array[i] bge chk_end ; no update if max_val is larger movb 0,x,max_val ; update max_val chk_end dex ; move the array pointer dbne b,loop ; decrement the loop count, branch if not zero yet. swi forever bra forever array db 1,3,5,6,19,41,53,28,13,42,76,14,20,54,64,74,29,33,41,45 end