Assembly coding tips.

Topics related to the API, programming discussions & questions, coding tips, bugs, etc. should go here.
Post Reply
DavidEtherton
Posts: 252
Joined: Tue Dec 02, 2008 12:38 am
Location: Carlsbad, California (USA)

Assembly coding tips.

Post by DavidEtherton »

Shove the tricks you've figured out so far into this thread (many of mine were learned by staring at Alec's code)

Timing:

nop ; 1 cycle
rjmp . ; 2 cycles
lpm ; 3 cycles - but destroys r0 and can cause warning spew in emulator if Z is pointing past code.

To kill off 3N cycles: (N>0)

.macro delay3N value
ldi r19, \value
dec r19
brne .-4
.endm

You can use any register r16 or above for the counter. The branch costs one less cycle on the last iteration, but that is "paid for" by the ldi instruction up front.

Tired of the verbose way to send a pixel out? I always cut/paste another one myself. Here's a better way:

.macro pixel reg
out _SFR_IO_ADDR(DATA_PORT),\reg ; 1
.endm

-Dave
Post Reply