Assembly Cheat Sheet
Commonly Seen Assembly Mistakes
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.
Forgetting to save a register (observe caller-save / callee-save convention)
Using mov with an immediate (e.g., you meant ldi r18, 1, but used mov r18, 1)
Using cp or cpc with immediate (e.g., cp r18, 10 is wrong); you need two registers (e.g., cp r18, r20))
Forgetting to add ret to a function.
Incorrect order or number of pop instructions after push instructions.
; task here
pop r18 ; WRONG (you needed pop r19)
pop r19 ; WRONG (you needed pop r18)
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.
Be careful with numeric labels and make sure you are jumping to the correct address.
Incorrect use of branch instruction (e.g., brlt (signed) vs. brlo (unsigned)).
Using GDB Text User Interface (TUI)
To use TUI follow these steps:
- Run the program in gdb
- Set a breakpoint in a function (e.g., main)
- tui enable
- layout asm
- layout regs
- Press c to continue
- Display the function code (l function_name)
- Use ni to execute the next instruction