Assembly language examples
A typical line in assembly language programme might be as follows:
LOOP: MOV.B r0, #80 ;initialise counter
This line will be assembled into a single instruction (in this case 11 0000 1000 0000 in binary, or 3080); the assembly language and the machine code correspond to each other.
It has four parts; label, mnemonic, operand, comment; not all are present in every line.
The first part (LOOP in this example) is a label ; this is a word, invented by the programmer, which identifies this point in the program. It will be set equal to the value of the address where this instruction is stored. So, for example, if later in the programme there is a statement JMP LOOP, the assembler programme will replace the label LOOP with the actual value of LOOP, which is the address at which this instruction is stored. (For the assembler to recognise this as a label, the label must begin at the first character in the line., in some assemblers a colon ":" follows the label) So if the address at which the instruction is stored is 4F, LOOP takes on the value 4F. If LOOP is used later in the programme, the assembler will give it the value 4F.
The second part is the mnemonic .This corresponds to a particular kind of instruction (opcode sent by the Dispatch Unit). The intention is that the word chosen (by the manufacturers) for the mnemonic is easy to remember, and indicates what the instruction does. In this case, the instruction moves a literal value (one byte) into the register 0, hence MOV.B r0, #80
The third part of the line is an operand (there may be two); in this case the operand is the value 80 (in Hex) and the register r0.
The last part of the line is a comment. This does not affect the actual instruction at all; it is not part of the instruction, and is not assembled; instead it helps the programmer to remember what this part of the program does. The comment is preceded by a semi-colon.
When you have written a programme in assembly language, it actually consists of lots of ASCII characters; this would be stored in a file and called "source code". This then forms the input to a program called an "assembler" (MPASM for the PIC) which can translate the "source code" into machine code. or object code. When the assembler has done its work, this line of source code will have been translated into a binary pattern, associated with a particular address in the programme memory.
You might also like
LWW ipazzport KP-810-19 Germany + English Language Mini Wireless 2.4GHz 84-Keys Keyboard - Black
PC Accessory (LWW Computers)
C Programming with The Programmable Box (Orange-Kit)
Software (Your Inner Geek, LLC)