|
Course Index Dr. Margush's page |
You will need to create several loops (maybe even nested loops). Here is a simple example of a loop that executes 100 times and then goes on to the next statement in memory. The BRNE instruction branches back to the label if the previous DEC yields a result that is not equal to zero.
;begin with a statement to initialize the loop counterThe above loop requires 100 * 4 cycles which is 400 microseconds if 1MHz clock is used. You need to introduce a 500 millisecond delay in your program.
ldi r20, 100 ;number of iterations (max is 256 iterations if you start at 0)
lp:
nop ;you can add or remove nops to adjust timing
dec r20 ;any free register may be used
brne lp ;this loop consumes 4 cycles per iteration
;statement to be executed on termination goes here