100 likes | 186 Views
Assembler Language. Guidelines for writing assembly code suggested by Microchip Write instruction mnemonics in lower case (e.g. xorwf ) Write special register names, RAM variable names, and bit names in uppercase (STATUS, RP0). Assembler Language.
E N D
Assembler Language • Guidelines for writing assembly code suggested by Microchip • Write instruction mnemonics in lower case (e.g. xorwf ) • Write special register names, RAM variable names, and bit names in uppercase (STATUS, RP0)
Assembler Language • Write instruction and subroutine labels in the mixed case (e.g. Mainline, LoopTime) • A sample program to flash an LED is given next
Program hierarchy MainLine call Initial ; Perform necessary initializations Mainloop call Task1 ; Take care of Task1 call Task2 ; Take care of Task2 . . call LoopTime ; Force loop time to a fixed value coto MainLoop ; Repeat
SAMPLE PROGRAM • Figure 1 gives the schematic of the circuit. • Figure 2 gives some necessary power supply and output pin drive specifications • Figure 3 shows the program code.
Macros • Set of Instructions which can be inserted into source code by assembler when the code is compiled. • E.g. bcf STATUS, RP0 • Can be expressed in macro definition as: bank1 macro bcf STATUS, RP0 endm
Macros • Definition of a macro can be inserted into a source file at any place before it is invoked. • Multiple macro definitions can be defined into files (e.g. name.inc) and then included into the source code as an include file • A macro definition in an include file will only be included added to the object file if it is invoked in the program.
Macros • A macro definition can include one or more arguments • E.g. Load a literal value into a register movlf macro literal, register movlw literal movlf register Endm Usage: movlf MaxCount, BLNKCNT
Macros • Use of macro generally effects the content of W register • Local labels can be defined inside a macro • Do not precede a macro with one of the skip instructions • E.g. btfsc STATUS, C movlw 5, COUNT
Macros Macro definition without using local labels (not suggested) countdown macro COUNTREGISTER, InitialCount movlw InitialCount movwf COUNTREGISTER Again decfsz COUNTREGISTER goto Again endm
Macros Macro definition using local labels countdown macro COUNTREGISTER, InitialCount local Again movlw InitialCount movwf COUNTREGISTER Again decfsz COUNTREGISTER goto Again endm