; get some chip specific definitions like the special names for ports .include "C:\Program Files\Atmel\AVR Tools\AvrAssembler\Appnotes\m16def.inc" .CSEG .org 0 main: push r16 ; just a dummy to fix a bug in the simulator ; initialize the registers prior to use ; and explain what they'll be used for. ; setup the ports for output mainLoop: ; figure out what you're going to display and then display ; it. Note that in here would be a good place for a function ; call to your decode table. Remember, when you access your ; jump table, you'll need to pass parameters via registers ; now we need to delay, you'll probably need to use several ; nested loops jmp mainLoop ;; Jump Table .cseg .org [base adress for jump table] ; insert instructions jmp whereToReturnFromJumpTable ; insert instructions jmp whereToReturnFromJumpTable ; insert instructions jmp whereToReturnFromJumpTable ; etc ;______________________________________ ; Sample function call from class: ;______________________________________ decodeValue: ;; takes the nibble that's in r16 and outputs the ;; decoded value back in r16. ; we're going to use the Z register (r31:r30) so we need ; to save the value there in case the caller is expecting ; it to be saved push r31 push r30 andi r16, 0x0f ; mask off just the bits I want from r16 to make sure I don't ; jump to somewhere that's not in the table ; lsl r16 ; I need to multiply the value by 2 (if icall) ldi r31, 04 ; load the jump adress into the Z register (r31:r30) mov r30, r16 icall ; make the jump into the jump table ;**OR**: lpm r16,Z ; Load constant from program ; at this point, I should have the return value in r16 so all that is left ; to do is restore the values in the Z register and return pop r30 pop r31 ret ;; the jump table starts here. Note that the offset is hardcoded at 1024. .cseg .org 1024 ;***THIS (icall): OR THIS (lpm):*** ldi r16, 0x81 .db 0x81 ret .db 0xf3 ldi r16, 0xf3 .db 0x49 ret ldi r16, 0x49 ret ; etc.