Naming labels
In assembly, you must name pieces of your functions. Fortunately, if you have the “Settings > Function-local labels” setting turned on in MARS, you can start control flow labels with an underscore _
to make it “local” to that function. That way, you don’t have to uniquely name every label in your program!
Because of Function-local Labels, this is how you will name things:
- Functions are named without a leading underscore, using
snake_case
. e.g.main
check_input
update_objects
- Control flow labels start with
_
and might say what kind of control flow they’re part of e.g._loop
_loop_end
_endif
_check_L
_check_R
Here are some bad label names:
_label
(yes, it IS a label, very good! how does that help you?)_1
(you’re a human, you suck at numbers, use language)_if1
,_if2
,_if3
(you can’t tell these apart; you’re a human, you suck at numbers)_andand
(what’s this even mean?)
Indentation
asm has no control structures, but there are still rules about indentation. Well, there’s just 2.
- Labels go at the beginning of the line.
- Instructions are indented.
If you want to indent your control structures, feel free! If so, it’s okay to indent the labels, but still keep them “to the left” of the instructions they refer to.
Instead of... | Do... |
---|---|
|
|
|
|
Commenting and spacing your lines out
A single line of HLL code can be the equivalent of several asm instructions. If you write all your instructions one line after another without any spacing, it can get very difficult to read and change.
I recommend doing a few things:
- Put a comment of some HLL pseudocode before each group of instructions that correspond to it.
- Put blank lines between these groups.
- Put “divider line” comments between functions.
Combining the “control flow indentation” from the previous section with these rules…
Instead of... | Try... |
---|---|
|
|