Maarten Brock - 2026-01-04

I suggest to change the definition of CLOCK_HZ to 125000000UL to indicate it is a long integer value. For SDCC all normal integers are 16 bit wide. It looks like it is using 24 bit here.

Further, note that there are no PUSH/POP A instructions, only PUSH/POP ACC.

Those sdcc_atomic_exchange_rollback functions are needed to rollback atomic access evaluation when an interrupt occurs so it can re-evaluate the atomicity. They are generated along with the interrupt vector table when main() is compiled and must live at specificly aligned addresses. Did you forget to add a prototype for void isr_timer0(void) __interrupt(1) in the file that contains your main()?

Finally, did you notice that isr_timer0() already saves and restores ACC and PSW?