Ro5bert / avra

Assembler for the Atmel AVR microcontroller family
GNU General Public License v2.0
153 stars 39 forks source link

Intermittent jmp/label address miscalculation #32

Closed jameswilddev closed 3 years ago

jameswilddev commented 3 years ago

I don't yet have a reliable repro of this, but I've found a case where seemingly unrelated changes cause a jmp to miscalculate the address of a label, and fall 27 words short. I have a structure as follows:

I found after making some unrelated changes much further down, that the program suddenly wouldn't start. I ran the hex through disassembly both before and after the changes, and the only changes seem to be the ones I'm expecting near the end and that the reset vector is jmping to different address. That address is 27 words early so at startup it's ending up in the middle of an interrupt handler instead of the setup logic.

Disassembly in Atmel Studio; RETI marks the end of the interrupt (where the main label is), CLT is where the reset vector is jmping to: image

Diffing the disassemblies of the working and non-working code; you can see that the reset vector at the very top is the only difference until much later on in the file: image

I'm going to be investigating this.

jameswilddev commented 3 years ago

Another example of where it's happened:

image

The jmp at the very end should go back to the cp at 0x346, but it's jumping 23 words too far:

image