reset:
    br always >main
    nop

hardfault:
    reti
    nop

memfault:
    reti
    nop

timer_interrupt:
    br >timer_interrupt_handler
    nop

.align
led_addr: .word 0x000F0000
timer_counter_addr: .word 0x000F0008
timer_status_addr: .word 0x000F000C
dmem_start_addr: .word 0x00000400
dmem_end_addr: .word 0x000004FC
priority_mask: .word 0xFFFFFF03

main:
    // Initialize stack pointer to the end of the data memory
    ldr r12, >dmem_end_addr

    // Set runtime priority
    ldr r0, >priority_mask
    and r14, r0, r14

    ldr r0,>led_addr                // LED addr
    ldr r1,>timer_status_addr      // Timer addr

    // Set some LEDs
    clr r2
    addi r2, 0x5A
    st08 r0, r2

    // Enable the timer...
    clr r2
    addi r2, 0x1 // enable bit set
    st08 r1, r2

loop:
    br >loop
    nop


timer_interrupt_handler:
    // Set LEDs to indicate we reached the timer interrupt
    clr r2
    addi r2, -1
    st08 r0, r2
    reti
