Assembly (AVR)

References

Cheat Sheet

Assembly Cheat Sheet

Commonly Seen Assembly Mistakes

  1. Missing .text after .data. Machine code in .data instead of in .text leads to infinite resets. If you see "Initialized stdout." repeatdly or if you see the compile note: "warning: internal error: out of range error" you are missing or you have misplaced the .text directive.
  2. Forgetting to save a register (observe caller-save / callee-save convention)
  3. Using mov with an immediate (e.g., you meant ldi r18, 1, but used mov r18, 1)
  4. Using cp or cpc with immediate (e.g., cp r18, 10 is wrong); you need two registers (e.g., cp r18, r20))
  5. Forgetting to add ret to a function.
  6. Incorrect order or number of pop instructions after push instructions. For example:
                            push r18
                            push r19
                            ; task here
                            pop r18 ; WRONG (you needed pop r19)
                            pop r19 ; WRONG (you needed pop r18)
    		   
  7. Mixing up high and low bytes. For example, if you are using r24 and r25, r24 will have the low byte and r25 the high byte.
  8. Be careful with numeric labels and make sure you are jumping to the correct address.
  9. Incorrect use of branch instruction (e.g., brlt (signed) vs. brlo (unsigned)).
  10. If you need to compare a register against a constant (e.g., r25 and 0) you need to use cpi (notice the i).  For example, cpi r25, 0.  

Using GDB Text User Interface (TUI)

To use TUI follow these steps:

Reference: https://ftp.gnu.org/old-gnu/Manuals/gdb/html_chapter/gdb_19.html

Web Accessibility