Download MOVLW 0x06

Survey
yes no Was this document useful for you?
   Thank you for your participation!

* Your assessment is very important for improving the workof artificial intelligence, which forms the content of this project

Document related concepts
no text concepts found
Transcript
Directives, Memory, and Stack
Directives

Special commands to the assembler

May or may not generate machine code
Categories by their function
 Programming directives

Object file directives
 Control Directives
 List Directives
 Data Directives

Data Directives
Describe data
ASCII data can be stored in memory using declare byte (DB) or DATA
Data Directives - Example
DE
"Test Data"
List Directives
Control listing process
Example:
LIST P=18F4520, F=INHX32 ;directive to define processor and file format
#include <P18F4520.INC>
;processor specific variable definitions
Object File Directives
How to generate code in the object file
Example: RESET_VECTOR CODE Ox0000
Example:
Control Directives
Control the assembly at the time of link process
ASCII TABLE
PIC18 Memory Space
Internal PIC18 Architecture
I/O
Port
s
Data
Memory
8 wires
31 x 21
Stack Memory
Timers
21 wires
Clock
Generation
8-bit CPU
8 wires
16 wires
Analog
to
Digital
Converte
r
Program
Memory
Serial
Ports
Data
EEPROM
Other
Peripherals
8 wires
Program Memory


Program memory addresses are 21bit address starting at location
0x000000.
Program memory is either PROM or
EEPROM.


The PROM version is called OTP (onetime programmable)
The EEPROM version is called Flash
memory.


If it has flash it will have 256 bytes or
1024 bytes of data EEPROM
The data EEPROM memory is
indirectly addressed through the
special function register
Program Memory

There are three important memory
locations in the program memory.
0x0000, 0x0008, and 0x0018 called
vectors.



Generally the GOTO instruction in
assembly language is placed at a vector
location.
A vector is an address that is accessed
when the reset or interrupt occurs.
The reset vector is 0x0000, the high
priority interrupt vector is 0x0008,
and the low priority interrupt vector is
0x0018.
Data Memory
Data memory is either SRAM or
EEPROM.
 SRAM data memory begins at 12-bit
address 0x000 and ends at 12-bit
address 0xFFF.



Not all PIC18 versions contain 4K or data
memory space.
Various PIC18 versions contain between
256 and 3968 bytes of data memory.
Data Memory

There are two types of registers:



general-purpose registers (GPRs)
special-function registers (SFRs)
GPRs are used to hold dynamic data when the PIC18
CPU is executing a program.
 SFRs are registers used by the CPU and peripheral
modules for controlling the desired operation of the
MCU.
 The upper 128 bytes of the data memory are used for
special function registers (SFR) at addresses 0xF80
through 0xFFF. Some versions of the PIC18 have
additional SFRs at locations below 0xF80.
Data Memory
Using BSR – Writing into file registers
a=0; access bank
0x12
a=1; bank selection
0x3 0x2F
A Typical Instruction showing the a-bit
15
10
Op-code
9
8
7
0
8-bit data memory address
a-bit
a = 0 access bank
a = 1 use BSR
d-bit
d = 0 WREG
d = 1 data memory
address
MOVLW 0x06
ADDLW 0x02
MOVWF 0x00, 0
;
;place a 0x06 into W
;add a 0x02 to W
;copy W to access bank register 0x00
OR another version using the ACCESS keyword
MOVLW 0x06
ADDLW 0x02
MOVWF 0x00, ACCESS
;place a 0x06 into W
;add a 0x02 to W
;copy W to access bank register 0x00
MOVLW
ADDLW
MOVLB
MOVWF
0x06
0x02
2
0x00, 1
;place a 0x06 into W
;add a 0x02 to W
;load BSR with bank 2
;copy W to data register 0x00
;of bank 2 or address 0x200
; OR using the BANKED keyword
MOVLW 0x06
ADDLW
0x02
MOVLB
2
MOVLF
0x00, BANKED
;place a 0x06 into W
;add a 0x02 to W
;load BSR with 2
;copy W to data register 0x00
;of bank 2 or address 0x200
; OR without any bank indication
MOVLW
ADDLW
MOVLB
MOVWF
0x06
0x02
2
0x00
;place a 0x06 into W
;add a 0x02 to W
;load BSR with bank 2
;copy W to data register 0x00
;of bank 2 or address 0x200
MOVLW
MOVWF
MOVLW
MOVWF
MOVLW
MOVWF
0x7F
ADCON1
0x00
TRISA
0x03
PORTA
;select all digital pins for ports
;place 0x00 in Port A direction register
;to select output operation
;place 0x03 on Port A
Data Memory
0xFE0
Bank Select Register (BSR)-4 bit
0xFE8
Accumulator (WREG)
0xFF4
0xFF3
Product High (PRODH)
Product Low (PRODL)
0xFEA
0xFE9
File Select Register 0 High (FSR0H)
File Select Register 0 Low (FSR0L)
0xFE2
0xFE1
File Select Register 1 High (FSR1H)
File Select Register 1 Low (FSR1L)
0xFDA
0xFD9
File Select Register 2 High (FSR2H)
File Select Register 2 Low (FSR2L)
0xFD8
Status Register (SR)
Register File (Data Memory)
0xF7F
0xF7E
0xF7D
0x004
0x003
0x002
0x001
0x000
8-Bits
Program Counter (PC)
8-Bits
Major Special
Function Registers
Note:
- The program counter is an internal 21-bit physical register
- The program counter is modified by the GOTO, CALL, RETURN, and
branch instructions. The program counter is not directly addressable.
Initializing the RAM –
indirect addressing
What is this doing?
Program Stack Memory




The PIC18 contains a program stack
that stores up to 31 return
addresses from functions.
The program stack is 21 bits in width
as is the program address.
When a function is called, the return
address (location of the next step in
a program) is pushed onto the stack.
When the return occurs within the
function, the return address is
retrieved from the stack and placed
into the program counter.