Assembler Language - Wayne State University

Download Report

Transcript Assembler Language - Wayne State University

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
Mainloop
call Task1
call Task2
.
.
call LoopTime
coto MainLoop
; Perform necessary initializations
; Take care of Task1
; Take care of Task2
; Force loop time to a fixed value
; 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