Assembly language is an alphanumeric representation of machine code. Below is an example of a AVR assembly code written in assembly language. Each line of the code is an instruction telling the microcontroller to carry out a task.
ADD R16, R17 ; Add value in R16 to value in R17 DEC R17 ; Minus 1 from the value contained in R17 MOV R18, R16 ; Copy the value in R16 to R18 END: JMP END ; Jump to the label END
The instructions used in writing programs in assembly language are not general but specific to the microcontroller. Each company provides a set of instructions for there microcontrollers. AVR 8-bits microcontrollers have a common instruction set .
Please note that not all instructions are available to all microcontrollers. The set available to each AVR microcontroller is given in its datasheet.
;Col_1 Col_2 Col_3 Col_4 ADD R16, R17 ; Add value in R16 to value in R17 DEC R17 ; Minus 1 from the value contained in R17 MOV R18, R16 ; Copy the value in R16 to R18 END: JMP END ; Jump to the label END
Column 1 (Col_1) is used for labels. Labels are basically markers use by the programmer when indicating to the microcontroller to jump to a specific location in the code.
Column 2 (Col_2) is used for the microcontroller instructions.
Column 3 (Col_3) is used for arguments operated on by the instruction in column 2.
Column 4 (Col_4) is used for comments. Note here that a semi-colon ";" is put in front of each comments. That is the semi-colon indicate that the statement that follows it in the same line is a comment.
AVR Tutorials hopes this AVR assembly tutorial was benificial to you and looks forward to your continued visits for all your microcontroller tutorial needs.