I'm struggling to understand what this code does
ldi r20, 80
loop: asr r20
What is this code doing and how many clock cycles does this code take to execute?
This seems to be Atmel AVR assembly code. In a loop that continues until the carry bit of the status register is set, it shifts hexadecimal
80 arithmetically right by one position so that
r20 takes the successive values of
ff. Until now, the low bit has been
0, and this value has been shifted into the carry bit of the status register. But on the next shift, the low bit of
ff is shifted, which is a
1. This causes the loop to exit.
See http://www.atmel.com/webdoc/avrassembler/avrassembler.wb_ASR.html on the ASR instruction.
The net effect is to cause a small delay.
For clock cycles:
Gene seems to be spot on in his answer so if my count is correct a total of 17 (don't bet any money on it).
source for the clock cycles was: http://www.avr-asm-tutorial.net/avr_en/beginner/COMMANDS.html#Functions