This file is a preprocessed assembly source file. The C preprocessor will be run by the compiler front-end first, resolving all #include, #define etc. directives. The resulting program text will then be passed on to the assembler.

As the C preprocessor strips all C-style comments, preprocessed assembly source files can have both, C-style (/* ... */, // ...) as well as assembly-style (; ...) comments.

At the top, the IO register definition file avr/io.h and the project declaration file project.h are included. The remainder of the file is conditionally assembled only if the target MCU type is an ATtiny13, so it will be completely ignored for the ATtiny45 option.

Next are the two interrupt service routines for timer 0 compare A match (timer 0 hits TOP, as OCR0A is set to 255) and timer 0 overflow (timer 0 hits BOTTOM). As discussed above, these are kept as short as possible. They only save SREG (as the flags will be modified by the INC instruction), increment the counter_hi variable which forms the high part of the current time counter (the low part is formed by querying TCNT0 directly), and clear or set the variable flags, respectively, in order to note the current counting direction. The RETI instruction terminates these interrupt service routines. Total cycle count is 8 CPU cycles, so together with the 4 CPU cycles needed for interrupt setup, and the 2 cycles for the RJMP from the interrupt vector to the handler, these routines will require 14 out of each 256 CPU cycles, or about 5 % of the overall CPU time.

The pin-change interrupt PCINT0 will be handled in the final part of this file. The basic algorithm is to quickly evaluate the current system time by fetching the current timer value of TCNT0, and combining it with the overflow part in counter_hi. If the counter is currently counting down rather than up, the value fetched from TCNT0 must be negated. Finally, if this pin-change interrupt was triggered by a rising edge, the time computed will be recorded as the start time only. Then, at the falling edge, this start time will be subracted from the current time to compute the actual pulse width seen (left in pwm_incoming), and the upper layers are informed of the new value by setting bit 0 in the intbits flags. At the same time, this pin-change interrupt will be disabled so no new measurement can be performed until the upper layer had a chance to process the current value.