Specifications
mikroElektronika | Free Online Book | PIC Microcontrollers | Appendix A: Programming a Microcontroller
A program written in assembly language consists of several elements being differently interpreted while compiling the
program into an executable data file. The use of these elements requires strict rules and it is necessary to pay special
attention to them during program writing in order to avoid errors.
ASSEMBLY LANGUAGE SYNTAX
As mentioned, it is necessary to observe some specific rules in order to enable the process of compiling into executive HEX
code to run without errors. Compulsory rules explaining how sequences of expressions are put together to form the
statements that make up an assembly language program are called syntax. There are only several of them:
● Every program line may consist of a maximum of 255 characters;
● Every program line that is to be compiled must start with a symbol, label, mnemonics or directive;
● Text following the mark ";" in a program line represents a comment which is ignored by the assembler (not
compiled); and
● All the elements of one program line (labels, instructions etc.) must be separated by at least one space character.
For the sake of better clearness, a push-button TAB is commonly used instead of it, so that it is easy to delimit
columns with labels, directives etc. in a program.
LABELS
A label represents a textual version of some address in ROM or RAM memory. Each label has to start in the first column
with a letter of alphabet or "_" and may consist of maximum of 32 characters. Besides, it is easily used:
● It is sufficient to enter the name of a label instead of a 16-bit address in instruction which calls some subroutine or
a jump. The label with the same name should also be written at the beginning of a program line in which a
subroutine starts or where a jump should be executed. As a general rule, labels have easily recognizable names.
During program compiling, the assembler will automatically replace the labels by the corresponding addresses.
COMMENTS
Acomment is often an explanatory text written by the programmer in order to make a program clearer and easier to
understand. It is not necessary to comment every line. When three or four lines of code work together to accomplish some
higher level task, it is better to have a single higher level comment for the group of lines. Therefore, it is added if needed
and has to start with ";". Comments added to assembly source code are not compiled into machine code.
INSTRUCTIONS
http://www.mikroe.com/en/books/picmcubook/appa/ (2 of 21)5/3/2009 11:35:35 AM