2013 Lecture Ch2 2
2013 Lecture Ch2 2
PIC
Architecture &
Assembly
Language
Programming
The WREG Register
0-2
MOVLW Instruction
0-3
ADDLW Instruction
ADDLW K
• ADD a literal value to WREG.
MOVLW 25H
ADDLW 34H
;WREG = 59H
0-4
Figure 2-1. PIC WREG and ALU
Using Literal Value
MOVLW 12H
ADDLW 16H
ADDLW 11H
ADDLW 43H
MOVLW 7F2H
MOVLW 60A5H
0-6
The PIC File Register
0-7
SFRs
0-8
GPRs
0-9
File register size for PIC chips
0-10
Figure 2-2. File Registers of
PIC12, PIC16, and PIC18
File Register and Access Bank
0-13
Figure 2-3. File Register for PIC18
Family
Figure 2-4. Special Function
Registers of the PIC18 Family.
MOVWF Instruction
• ADDWF fileReg, D
• Add together the contents of WREG and a file register
locations.
• D indicates the destination bit. If D=0, the destination
is WREG. If D=1, then the result will be placed in the
file register.
• The PIC assembler allows us to use the letters W or F
instead of 0 or 1 to indicate the destination.
0-18
Figure 2-5. WREG, fileReg, and
ALU in PIC18
COMF fileReg, d
0-21
DECF fileReg, d
MOVLW 3
MOVWF 20H
DECF 0x20, F
DECF 0x20, F
DECF 0x20, F
0-22
MOVF fileReg, d
0-23
0-24
MOVFF instruction
0-25
PIC18 Status Register
0-27
Figure 2-7. Bits of Status Register
Data Format representation
0-33
Data Format representation
0-34
Assembler Directives
0-36
PIC Assembly Programming
• Machine language
• Assembly language
• Assembler, objective code
• Low-level language
• Complier , high-level language
0-37
Structure of Assembly Language
0-38
Figure 2-8. Steps to Create a
Program
Figure 2-9. Program Counter in
PIC18
Figure 2-10. PIC18 On-Chip Program
(code) ROM Address Range
PIC18 Program ROM Space
• Big endian
Figure 2-14. von Neumann vs.
Harvard Architecture
Instruction Size
• MOVLW
• ADDLW
0-50
Instruction Size
• MOVWF
• MOVFF
0-51
Instruction Size
• GOTO
0-52
RISC Architecture
0-53
Figure 2-15. SFR Window in MPLAB
Simulator
Figure 2-16. File Register (Data RAM)
Window in MPLAB Simulator
Figure 2-17. Program (Code)
ROM Window in MPLAB Simulator