Upload
dotuyen
View
228
Download
0
Embed Size (px)
Citation preview
Introduction to the PIC Assembly Language
CP316Assembly Language Programming
Terry Sturtevant
Wilfrid Laurier University
November 8, 2017
Terry Sturtevant CP316 Assembly Language Programming
Introduction to the PIC Assembly Language Program Elements
Introduction to the PIC Assembly Language
instruction fields→ Section 2.3→ Section 20.0language operands→ Section 1.10→ Section 1.8→ Section 1.9assembler directives→ Section 2.4assembler directives vs. language instructions
Terry Sturtevant CP316 Assembly Language Programming
Introduction to the PIC Assembly Language Program Elements
Introduction to the PIC Assembly Language
instruction fields
→ Section 2.3→ Section 20.0language operands→ Section 1.10→ Section 1.8→ Section 1.9assembler directives→ Section 2.4assembler directives vs. language instructions
Terry Sturtevant CP316 Assembly Language Programming
Introduction to the PIC Assembly Language Program Elements
Introduction to the PIC Assembly Language
instruction fields→ Section 2.3
→ Section 20.0language operands→ Section 1.10→ Section 1.8→ Section 1.9assembler directives→ Section 2.4assembler directives vs. language instructions
Terry Sturtevant CP316 Assembly Language Programming
Introduction to the PIC Assembly Language Program Elements
Introduction to the PIC Assembly Language
instruction fields→ Section 2.3→ Section 20.0language operands
→ Section 1.10→ Section 1.8→ Section 1.9assembler directives→ Section 2.4assembler directives vs. language instructions
Terry Sturtevant CP316 Assembly Language Programming
Introduction to the PIC Assembly Language Program Elements
Introduction to the PIC Assembly Language
instruction fields→ Section 2.3→ Section 20.0language operands→ Section 1.10
→ Section 1.8→ Section 1.9assembler directives→ Section 2.4assembler directives vs. language instructions
Terry Sturtevant CP316 Assembly Language Programming
Introduction to the PIC Assembly Language Program Elements
Introduction to the PIC Assembly Language
instruction fields→ Section 2.3→ Section 20.0language operands→ Section 1.10→ Section 1.8
→ Section 1.9assembler directives→ Section 2.4assembler directives vs. language instructions
Terry Sturtevant CP316 Assembly Language Programming
Introduction to the PIC Assembly Language Program Elements
Introduction to the PIC Assembly Language
instruction fields→ Section 2.3→ Section 20.0language operands→ Section 1.10→ Section 1.8→ Section 1.9
assembler directives→ Section 2.4assembler directives vs. language instructions
Terry Sturtevant CP316 Assembly Language Programming
Introduction to the PIC Assembly Language Program Elements
Introduction to the PIC Assembly Language
instruction fields→ Section 2.3→ Section 20.0language operands→ Section 1.10→ Section 1.8→ Section 1.9assembler directives
→ Section 2.4assembler directives vs. language instructions
Terry Sturtevant CP316 Assembly Language Programming
Introduction to the PIC Assembly Language Program Elements
Introduction to the PIC Assembly Language
instruction fields→ Section 2.3→ Section 20.0language operands→ Section 1.10→ Section 1.8→ Section 1.9assembler directives→ Section 2.4
assembler directives vs. language instructions
Terry Sturtevant CP316 Assembly Language Programming
Introduction to the PIC Assembly Language Program Elements
Introduction to the PIC Assembly Language
instruction fields→ Section 2.3→ Section 20.0language operands→ Section 1.10→ Section 1.8→ Section 1.9assembler directives→ Section 2.4assembler directives vs. language instructions
Terry Sturtevant CP316 Assembly Language Programming
Introduction to the PIC Assembly Language Program Elements
assembler directives vs. language instructions
assembler directivesfor the compilerdo not become lines of codelanguage instructionsfor the microprocessorbecome lines of code
Terry Sturtevant CP316 Assembly Language Programming
Introduction to the PIC Assembly Language Program Elements
assembler directives vs. language instructions
assembler directives
for the compilerdo not become lines of codelanguage instructionsfor the microprocessorbecome lines of code
Terry Sturtevant CP316 Assembly Language Programming
Introduction to the PIC Assembly Language Program Elements
assembler directives vs. language instructions
assembler directivesfor the compiler
do not become lines of codelanguage instructionsfor the microprocessorbecome lines of code
Terry Sturtevant CP316 Assembly Language Programming
Introduction to the PIC Assembly Language Program Elements
assembler directives vs. language instructions
assembler directivesfor the compilerdo not become lines of code
language instructionsfor the microprocessorbecome lines of code
Terry Sturtevant CP316 Assembly Language Programming
Introduction to the PIC Assembly Language Program Elements
assembler directives vs. language instructions
assembler directivesfor the compilerdo not become lines of codelanguage instructions
for the microprocessorbecome lines of code
Terry Sturtevant CP316 Assembly Language Programming
Introduction to the PIC Assembly Language Program Elements
assembler directives vs. language instructions
assembler directivesfor the compilerdo not become lines of codelanguage instructionsfor the microprocessor
become lines of code
Terry Sturtevant CP316 Assembly Language Programming
Introduction to the PIC Assembly Language Program Elements
assembler directives vs. language instructions
assembler directivesfor the compilerdo not become lines of codelanguage instructionsfor the microprocessorbecome lines of code
Terry Sturtevant CP316 Assembly Language Programming
Introduction to the PIC Assembly Language Program Elements
sample code
h e r e andwf SSPCON2 ,W ; s t u f faddwf TMR0LCOPY, F , A
Terry Sturtevant CP316 Assembly Language Programming
Introduction to the PIC Assembly Language Program Elements
sample code
h e r e andwf SSPCON2 ,W ; s t u f faddwf TMR0LCOPY, F , A
Terry Sturtevant CP316 Assembly Language Programming
Introduction to the PIC Assembly Language Program Elements
Instruction fields
hereoptional labelandwfcommandSSPCON2file register,Fdestination (F or W),Aaccess bank; i.e. no BSR;comment after this
Terry Sturtevant CP316 Assembly Language Programming
Introduction to the PIC Assembly Language Program Elements
Instruction fields
here
optional labelandwfcommandSSPCON2file register,Fdestination (F or W),Aaccess bank; i.e. no BSR;comment after this
Terry Sturtevant CP316 Assembly Language Programming
Introduction to the PIC Assembly Language Program Elements
Instruction fields
hereoptional label
andwfcommandSSPCON2file register,Fdestination (F or W),Aaccess bank; i.e. no BSR;comment after this
Terry Sturtevant CP316 Assembly Language Programming
Introduction to the PIC Assembly Language Program Elements
Instruction fields
hereoptional labelandwf
commandSSPCON2file register,Fdestination (F or W),Aaccess bank; i.e. no BSR;comment after this
Terry Sturtevant CP316 Assembly Language Programming
Introduction to the PIC Assembly Language Program Elements
Instruction fields
hereoptional labelandwfcommand
SSPCON2file register,Fdestination (F or W),Aaccess bank; i.e. no BSR;comment after this
Terry Sturtevant CP316 Assembly Language Programming
Introduction to the PIC Assembly Language Program Elements
Instruction fields
hereoptional labelandwfcommandSSPCON2
file register,Fdestination (F or W),Aaccess bank; i.e. no BSR;comment after this
Terry Sturtevant CP316 Assembly Language Programming
Introduction to the PIC Assembly Language Program Elements
Instruction fields
hereoptional labelandwfcommandSSPCON2file register
,Fdestination (F or W),Aaccess bank; i.e. no BSR;comment after this
Terry Sturtevant CP316 Assembly Language Programming
Introduction to the PIC Assembly Language Program Elements
Instruction fields
hereoptional labelandwfcommandSSPCON2file register,F
destination (F or W),Aaccess bank; i.e. no BSR;comment after this
Terry Sturtevant CP316 Assembly Language Programming
Introduction to the PIC Assembly Language Program Elements
Instruction fields
hereoptional labelandwfcommandSSPCON2file register,Fdestination (F or W)
,Aaccess bank; i.e. no BSR;comment after this
Terry Sturtevant CP316 Assembly Language Programming
Introduction to the PIC Assembly Language Program Elements
Instruction fields
hereoptional labelandwfcommandSSPCON2file register,Fdestination (F or W),A
access bank; i.e. no BSR;comment after this
Terry Sturtevant CP316 Assembly Language Programming
Introduction to the PIC Assembly Language Program Elements
Instruction fields
hereoptional labelandwfcommandSSPCON2file register,Fdestination (F or W),Aaccess bank; i.e. no BSR
;comment after this
Terry Sturtevant CP316 Assembly Language Programming
Introduction to the PIC Assembly Language Program Elements
Instruction fields
hereoptional labelandwfcommandSSPCON2file register,Fdestination (F or W),Aaccess bank; i.e. no BSR;
comment after this
Terry Sturtevant CP316 Assembly Language Programming
Introduction to the PIC Assembly Language Program Elements
Instruction fields
hereoptional labelandwfcommandSSPCON2file register,Fdestination (F or W),Aaccess bank; i.e. no BSR;comment after this
Terry Sturtevant CP316 Assembly Language Programming
Introduction to the PIC Assembly Language Program Elements
Program Template
sample organization→ Section 2.6→ Section 1.5.4looping→ Section 2.9meaning of “end” directive→ Section 2.11 (bad example)
Terry Sturtevant CP316 Assembly Language Programming
Introduction to the PIC Assembly Language Program Elements
Program Template
sample organization
→ Section 2.6→ Section 1.5.4looping→ Section 2.9meaning of “end” directive→ Section 2.11 (bad example)
Terry Sturtevant CP316 Assembly Language Programming
Introduction to the PIC Assembly Language Program Elements
Program Template
sample organization→ Section 2.6
→ Section 1.5.4looping→ Section 2.9meaning of “end” directive→ Section 2.11 (bad example)
Terry Sturtevant CP316 Assembly Language Programming
Introduction to the PIC Assembly Language Program Elements
Program Template
sample organization→ Section 2.6→ Section 1.5.4
looping→ Section 2.9meaning of “end” directive→ Section 2.11 (bad example)
Terry Sturtevant CP316 Assembly Language Programming
Introduction to the PIC Assembly Language Program Elements
Program Template
sample organization→ Section 2.6→ Section 1.5.4looping
→ Section 2.9meaning of “end” directive→ Section 2.11 (bad example)
Terry Sturtevant CP316 Assembly Language Programming
Introduction to the PIC Assembly Language Program Elements
Program Template
sample organization→ Section 2.6→ Section 1.5.4looping→ Section 2.9
meaning of “end” directive→ Section 2.11 (bad example)
Terry Sturtevant CP316 Assembly Language Programming
Introduction to the PIC Assembly Language Program Elements
Program Template
sample organization→ Section 2.6→ Section 1.5.4looping→ Section 2.9meaning of “end” directive
→ Section 2.11 (bad example)
Terry Sturtevant CP316 Assembly Language Programming
Introduction to the PIC Assembly Language Program Elements
Program Template
sample organization→ Section 2.6→ Section 1.5.4looping→ Section 2.9meaning of “end” directive→ Section 2.11 (bad example)
Terry Sturtevant CP316 Assembly Language Programming
Introduction to the PIC Assembly Language Program Elements
Program Template
sample organization→ Section 2.6→ Section 1.5.4looping→ Section 2.9meaning of “end” directive→ Section 2.11 (bad example)
Terry Sturtevant CP316 Assembly Language Programming
Introduction to the PIC Assembly Language Program Elements
Instructions
addressing modes→ Section 1.9FSRssample instructions→ Section 1.10result destination operands
Terry Sturtevant CP316 Assembly Language Programming
Introduction to the PIC Assembly Language Program Elements
Instructions
addressing modes
→ Section 1.9FSRssample instructions→ Section 1.10result destination operands
Terry Sturtevant CP316 Assembly Language Programming
Introduction to the PIC Assembly Language Program Elements
Instructions
addressing modes→ Section 1.9
FSRssample instructions→ Section 1.10result destination operands
Terry Sturtevant CP316 Assembly Language Programming
Introduction to the PIC Assembly Language Program Elements
Instructions
addressing modes→ Section 1.9FSRs
sample instructions→ Section 1.10result destination operands
Terry Sturtevant CP316 Assembly Language Programming
Introduction to the PIC Assembly Language Program Elements
Instructions
addressing modes→ Section 1.9FSRssample instructions
→ Section 1.10result destination operands
Terry Sturtevant CP316 Assembly Language Programming
Introduction to the PIC Assembly Language Program Elements
Instructions
addressing modes→ Section 1.9FSRssample instructions→ Section 1.10
result destination operands
Terry Sturtevant CP316 Assembly Language Programming
Introduction to the PIC Assembly Language Program Elements
Instructions
addressing modes→ Section 1.9FSRssample instructions→ Section 1.10result destination operands
Terry Sturtevant CP316 Assembly Language Programming
Introduction to the PIC Assembly Language Program Elements
Branch Instructions
bra vs. goto→ Section 2.9.2$ = current instruction1 word instructions, except for movff, goto, call,lfsrskip instructions
Terry Sturtevant CP316 Assembly Language Programming
Introduction to the PIC Assembly Language Program Elements
Branch Instructions
bra vs. goto
→ Section 2.9.2$ = current instruction1 word instructions, except for movff, goto, call,lfsrskip instructions
Terry Sturtevant CP316 Assembly Language Programming
Introduction to the PIC Assembly Language Program Elements
Branch Instructions
bra vs. goto→ Section 2.9.2
$ = current instruction1 word instructions, except for movff, goto, call,lfsrskip instructions
Terry Sturtevant CP316 Assembly Language Programming
Introduction to the PIC Assembly Language Program Elements
Branch Instructions
bra vs. goto→ Section 2.9.2$ = current instruction
1 word instructions, except for movff, goto, call,lfsrskip instructions
Terry Sturtevant CP316 Assembly Language Programming
Introduction to the PIC Assembly Language Program Elements
Branch Instructions
bra vs. goto→ Section 2.9.2$ = current instruction1 word instructions, except for movff, goto, call,lfsr
skip instructions
Terry Sturtevant CP316 Assembly Language Programming
Introduction to the PIC Assembly Language Program Elements
Branch Instructions
bra vs. goto→ Section 2.9.2$ = current instruction1 word instructions, except for movff, goto, call,lfsrskip instructions
Terry Sturtevant CP316 Assembly Language Programming
Introduction to the PIC Assembly Language Program Elements
Subroutines
call vs. rcall→ Section 2.9.2return vs. retlwhardware stack→ Section 1.5.4→ Section 4.7subroutines vs. macros
Terry Sturtevant CP316 Assembly Language Programming
Introduction to the PIC Assembly Language Program Elements
Subroutines
call vs. rcall
→ Section 2.9.2return vs. retlwhardware stack→ Section 1.5.4→ Section 4.7subroutines vs. macros
Terry Sturtevant CP316 Assembly Language Programming
Introduction to the PIC Assembly Language Program Elements
Subroutines
call vs. rcall→ Section 2.9.2
return vs. retlwhardware stack→ Section 1.5.4→ Section 4.7subroutines vs. macros
Terry Sturtevant CP316 Assembly Language Programming
Introduction to the PIC Assembly Language Program Elements
Subroutines
call vs. rcall→ Section 2.9.2return vs. retlw
hardware stack→ Section 1.5.4→ Section 4.7subroutines vs. macros
Terry Sturtevant CP316 Assembly Language Programming
Introduction to the PIC Assembly Language Program Elements
Subroutines
call vs. rcall→ Section 2.9.2return vs. retlwhardware stack
→ Section 1.5.4→ Section 4.7subroutines vs. macros
Terry Sturtevant CP316 Assembly Language Programming
Introduction to the PIC Assembly Language Program Elements
Subroutines
call vs. rcall→ Section 2.9.2return vs. retlwhardware stack→ Section 1.5.4
→ Section 4.7subroutines vs. macros
Terry Sturtevant CP316 Assembly Language Programming
Introduction to the PIC Assembly Language Program Elements
Subroutines
call vs. rcall→ Section 2.9.2return vs. retlwhardware stack→ Section 1.5.4→ Section 4.7
subroutines vs. macros
Terry Sturtevant CP316 Assembly Language Programming
Introduction to the PIC Assembly Language Program Elements
Subroutines
call vs. rcall→ Section 2.9.2return vs. retlwhardware stack→ Section 1.5.4→ Section 4.7subroutines vs. macros
Terry Sturtevant CP316 Assembly Language Programming
Introduction to the PIC Assembly Language Program Elements
Subroutines (continued)
shadow registers→ Section 4.7.1fast register stack→ Section 4.7.5return FAST
Terry Sturtevant CP316 Assembly Language Programming
Introduction to the PIC Assembly Language Program Elements
Subroutines (continued)
shadow registers
→ Section 4.7.1fast register stack→ Section 4.7.5return FAST
Terry Sturtevant CP316 Assembly Language Programming
Introduction to the PIC Assembly Language Program Elements
Subroutines (continued)
shadow registers→ Section 4.7.1
fast register stack→ Section 4.7.5return FAST
Terry Sturtevant CP316 Assembly Language Programming
Introduction to the PIC Assembly Language Program Elements
Subroutines (continued)
shadow registers→ Section 4.7.1fast register stack
→ Section 4.7.5return FAST
Terry Sturtevant CP316 Assembly Language Programming
Introduction to the PIC Assembly Language Program Elements
Subroutines (continued)
shadow registers→ Section 4.7.1fast register stack→ Section 4.7.5
return FAST
Terry Sturtevant CP316 Assembly Language Programming
Introduction to the PIC Assembly Language Program Elements
Subroutines (continued)
shadow registers→ Section 4.7.1fast register stack→ Section 4.7.5return FAST
Terry Sturtevant CP316 Assembly Language Programming
Introduction to the PIC Assembly Language Program Elements
Subroutines (continued)
shadow registers→ Section 4.7.1fast register stack→ Section 4.7.5return FAST
Terry Sturtevant CP316 Assembly Language Programming
Introduction to the PIC Assembly Language Program Elements
Data in Program Memory
tblrd vs. lfsr→ Section 2.10tblptrl, tblptrh, tblptru
Terry Sturtevant CP316 Assembly Language Programming
Introduction to the PIC Assembly Language Program Elements
Data in Program Memory
tblrd vs. lfsr
→ Section 2.10tblptrl, tblptrh, tblptru
Terry Sturtevant CP316 Assembly Language Programming
Introduction to the PIC Assembly Language Program Elements
Data in Program Memory
tblrd vs. lfsr→ Section 2.10
tblptrl, tblptrh, tblptru
Terry Sturtevant CP316 Assembly Language Programming
Introduction to the PIC Assembly Language Program Elements
Data in Program Memory
tblrd vs. lfsr→ Section 2.10tblptrl, tblptrh, tblptru
Terry Sturtevant CP316 Assembly Language Programming
Introduction to the PIC Assembly Language Program Elements
Data in Program Memory
tblrd vs. lfsr→ Section 2.10tblptrl, tblptrh, tblptru
Terry Sturtevant CP316 Assembly Language Programming
Introduction to the PIC Assembly Language Program Elements
Other Instructions
logical instructions→ Section 2.11rotate instructions; ( nc vs. c )→ Section 2.13
Terry Sturtevant CP316 Assembly Language Programming
Introduction to the PIC Assembly Language Program Elements
Other Instructions
logical instructions
→ Section 2.11rotate instructions; ( nc vs. c )→ Section 2.13
Terry Sturtevant CP316 Assembly Language Programming
Introduction to the PIC Assembly Language Program Elements
Other Instructions
logical instructions→ Section 2.11
rotate instructions; ( nc vs. c )→ Section 2.13
Terry Sturtevant CP316 Assembly Language Programming
Introduction to the PIC Assembly Language Program Elements
Other Instructions
logical instructions→ Section 2.11rotate instructions; ( nc vs. c )
→ Section 2.13
Terry Sturtevant CP316 Assembly Language Programming
Introduction to the PIC Assembly Language Program Elements
Other Instructions
logical instructions→ Section 2.11rotate instructions; ( nc vs. c )→ Section 2.13
Terry Sturtevant CP316 Assembly Language Programming
Introduction to the PIC Assembly Language Program Elements
Timing Loops
instruction time→ Section 1.7
Terry Sturtevant CP316 Assembly Language Programming
Introduction to the PIC Assembly Language Program Elements
Timing Loops
instruction time
→ Section 1.7
Terry Sturtevant CP316 Assembly Language Programming