230 likes | 405 Views
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
E N D
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
Internal PIC18 Architecture I/O Ports Data Memory 8 wires 31 x 21 Stack Memory Timers 21 wires 8-bit CPU Clock Generation Analog to Digital Converter 8 wires 16 wires Program Memory Serial Ports Data EEPROM Other Peripherals 8 wires
Program Memory • Program memory addresses are 21-bit address starting at location 0x000000. • Program memory is either PROM or EEPROM. • The PROM version is called OTP (one-time 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
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. Program Memory
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.
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 9 8 7 0 Op-code 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 ;place a 0x06 into W ADDLW 0x02 ;add a 0x02 to W MOVWF 0x00, 0 ;copy W to access bank register 0x00 ; OR another version using the ACCESS keyword MOVLW 0x06 ;place a 0x06 into W ADDLW 0x02 ;add a 0x02 to W MOVWF 0x00, ACCESS;copy W to access bank register 0x00
MOVLW 0x06 ;place a 0x06 into W ADDLW 0x02 ;add a 0x02 to W MOVLB 2 ;load BSR with bank 2 MOVWF 0x00, 1 ;copy W to data register 0x00 ;of bank 2 or address 0x200 ; OR using the BANKED keyword MOVLW 0x06 ;place a 0x06 into W ADDLW 0x02 ;add a 0x02 to W MOVLB 2 ;load BSR with 2 MOVLF 0x00, BANKED;copy W to data register 0x00 ;of bank 2 or address 0x200 ; OR without any bank indication MOVLW 0x06 ;place a 0x06 into W ADDLW 0x02 ;add a 0x02 to W MOVLB 2 ;load BSR with bank 2 MOVWF 0x00 ;copy W to data register 0x00 ;of bank 2 or address 0x200
MOVLW 0x7F MOVWF ADCON1 ;select all digital pins for ports MOVLW 0x00 ;place 0x00 in Port A direction register MOVWF TRISA ;to select output operation MOVLW 0x03 MOVWF PORTA ;place 0x03 on Port A
Data Memory 0xFE0 Bank Select Register (BSR)-4 bit Register File (Data Memory) 0xFE8 Accumulator (WREG) 0xFF4 Product High (PRODH) 0xF7F 0xFF3 Product Low (PRODL) 0xF7E 0xFEA File Select Register 0 High (FSR0H) 0xF7D 0xFE9 File Select Register 0 Low (FSR0L) 0x004 0xFE2 File Select Register 1 High (FSR1H) 0x003 0xFE1 File Select Register 1 Low (FSR1L) 0x002 0xFDA File Select Register 2 High (FSR2H) 0x001 0xFD9 File Select Register 2 Low (FSR2L) 0x000 0xFD8 Status Register (SR) 8-Bits Major Special Function Registers Program Counter (PC) 8-Bits 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 returnaddresses 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.