Open a browser window or tab containing the microcontroller simulator.

The AQA microcontroller contains a timer register called TMR.
This simulator memory-maps this register at address 0xFF.
There is also a prescaler register, PRE, memory-mapped at address 0xFE.
NOTE: In AQA exams, these registers might not be memory mapped.

If PRE contains zero, TMR does nothing.
If PRE contains 10 (for example), on each clock pulse, a counter is incremented. When the counter reaches 10, one is subtracted from TMR and the counter reset to zero. This decrements TMR on every eleventh clock pulse.
If PRE contains some larger number, the counter counts from zero to this larger number and then subtracts one from TMR.
In this way, the clock frequency is divided by PRE + 1 and used to decrement TMR.

When TMR reaches zero, the TMR (T) flag is set and stays set until a non zero value is assigned to TMR.

TASK: Copy and paste this code into the simulator and run the program.
Note roughly how long it takes before the code controlled by the timer runs.
Modify this code by storing 8 into PRE instead of 1.
Run the modified code and note that the timer counts far slower and the timer events are less frequent.

START:
; ===========================================
;       Initialise PRE and TMR
; ===========================================
        MOVW    0X1     ; Copy 1 into ...
        MOVWR   PRE     ; ... the prescaler
        MOVW    0X08    ; Copy 8 into ...
        MOVWR   TMR     ; ... the timer

; ===========================================
;       Poll the TMR flag (T)
; ===========================================
POLL:
        MOVRW   SR      ; Copy SR into W
        ANDW    0x02    ; Bit mask
        JPZ     POLL

; ============================================
; === This code runs when TMR reaches zero ===
; ============================================
        NOP
        NOP
        NOP
        NOP
        JMP     START
; ============================================