This post explains how I style 6502, 65c02 or 45gs02 assembly language. In addition, standard patterns translated to assembly can be found in Patterns in assembly language .
The examples are in Kick Assembler format.
Code Layout
Instructions
- instructions are in lowercase.
- instructions are tabbed 16 chars to the right.
Labels
- labels do not override the instruction space, max length is 14.
- labels are on the same line as the first instruction.
Comments
- comments explaining a block of code are positioned at the beginning of the line.
- comments explaining an instruction are positioned after the instruction.
Example
Subroutines
Must explain:
- *function: one or two words naming the function
- input: which registers must be set, and what do they contain?
- output: which register is set with what return information?
- destroys: which registers are destroyed when running this routine?
- calls: which other routines are called from this one?
- description: more in-depth explanation of the function.
Operations
Binary
Binary operations use binary notation for clarity: