Download Assembler/Linker/Librarian User's Guide
Transcript
Assembler Examples, Tips and Tricks 5.3.4 Register and Bit Assignments You can specify your own registers and bits by using the udata, res and equ directives, as is done in the following lines. udata DTEMP res 1 DFLAG res 1 ;Declare storage of RAM variables ;Reserve 1 address location ;Reserve 1 address location DFL0 ;Set flag bit - 0 bit of DFLAG equ 0x00 DTEMP and DFLAG are assigned one address location in RAM each by the linker. For illustrative purposes, suppose the locations selected by the linker are the general purpose registers (GPRs) 0x20 and 0x21. DFL0 is assigned the value 0x00 and will be used as the name for pin 0 in the DFLAG register. FIGURE 5-1: Special Function Registers General Purpose Registers PIC16F877A REGISTER FILE MAP 0x00 : ADCON0 0x1F DTEMP 0x20 DFLAG 0x21 DFL0 : 0x7F Bank 0 Bank 1 Bank 2 Bank 3 The directives udata and res are used in relocatable code to define multiple registers instead of equ. For more on these directives, see: • Section 4.62 “udata - Begin an Object File Uninitialized Data Section” • Section 4.57 “res - Reserve Memory” • Section 4.28 “equ - Define an Assembler Constant” 5.3.5 Program Memory CODE Sections and Paging The code directive is used to specify sections of relocatable code. For absolute code, the org directive is used. See Chapter 6. “Relocatable Objects” for more on the differences between relocatable and absolute code. For more on these directives, see: • Section 4.9 “code - Begin an Object File Code Section” • Section 4.51 “org - Set Program Origin” If no code directive is used, code generation will begin at address zero. For this example, code is used to specify code at 0x00 (reset address), 0x04 (interrupt address), 0x08 (interrupt service routine) and 0x1000 (Delay 2 address). It does not explicitly set the program start address, but allows the linker to place the code appropriately. Since the linker places addressed code first, and then attempts to place the relocatable code, based on size, the likely program memory usage is shown below. © 2009 Microchip Technology Inc. DS33014K-page 127