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!
It’s important to use a consistent naming convention. Here’s my convention. You can make your own.
- Functions are named as normal using
- Control flow labels start with
_and indicate what kind of control flow they’re part of e.g.
Here are some bad label names:
_blockA(I told you on the slides it was just for demonstration)
_1(you’re a human, you suck at numbers, use language)
_if3(you can’t tell these apart; you’re a human, you suck at numbers)
_andand(what’s this even mean?)
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.
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…