Compiler Construction/Assembler language techniques
From Wikibooks, the open-content textbooks collection
The output of your compiler is assembly language code. However, most programming languages do not map easily to most assembler languages, so some techniques or skills may need to be understood before attempting to write code that will output assembler code. These techniques are not intended to create highly optimized code - you will learn optimizing techniques later, but are intended to make sure you have a good understanding of how data and instructions are managed in the process of compiler construction.
[edit] Managing variables
Many programs use hundreds of different variables (not counting arrays).
Most computer architectures give you less than 32 registers (MIPS architecture and ARM give nearly 32 pointer registers; i386 gives only about 4 pointer registers; PIC microcontroller only has 1 pointer register).
Since we can't squeeze 100 different variables into even 32 processor registers, we must use memory for storing most variables.
We will start by storing practically all variables in memory. Later we will cover optimizing techniques that try to keep as many variables as possible in the processor registers.
[edit] Labeling
The assembler tool that you are using may reserve the names of the mnemonics. For example, your assembler may not allow a variable named add, since this is reserved for the instruction to add.
In this case, it may be important to use a prefix for your variable labels. Some compilers use a single underscore, but you can choose whichever you wish.

