MPASM to MPLAB XC8 PIC Assembler - Psects

lacing Psects into Memory
  • MPASM supports absolute mode, using the ORG directive, or relocatable mode, using program sections.
  • PIC Assembler only supports the relocatable mode.

lacing Psects into Memory

MPASM XC8 Assembler
ORG PSECT
  • Since the tutorials use the absolute mode you will need to remove the ORG directive and add a program section for the code and data.
    I have just added a code section for all the instructions and used the already defined equates to access the data memory variables (user registers). So, I have just replaced the ORG directive with the PSECT directive like this:
PSECT Reset_Vec,class=CODE,delta=2

other:

PSECT   ISR_Vec,class=CODE,delta=2
  • To make sure the linker places this section at address 000h and 004h, we need to provide an additional command line parameter:
    Go to “Project Properties” > “pic-as Global Options” > “Additional Options:” and add the following parameter (without spaces!):
-Wl,-pReset_Vec=0h,-pISR_Vec=4h

About section name

Where “MyCode” is the section name, “class=CODE” tells the linker to use the default code section, “delta=2" tells the linker the number of data bytes that are associated with each address.

We can also just define a code section like this:

PSECT code

But I’d rather define my own code section “MyCode” so that I can tell the linker to specifically place this code section at the zero address.
Otherwise, the linker will place it somewhere else, and it will probably overwrite the RC oscillator calibration instruction at the top of the memory (address 0FFh).

class - psect flag

Table 5-2. Assembler-provided Psects and Linker Classes

Psect name Linker class Target device families Purpose
code CODE All To hold executable code
eedata EEDATA All To hold data in EEPROM
data STRCODE Baseline, Mid-range To hold data in program memory
udata RAM All To hold objects allocatable anywhere in GPR
udata_bankn BANKN All To hold object allocatable in a particular data memory bank
udata_shr COMMON Baseline, Mid-range To hold objects allocatable in common memory

delta - psect flag

The delta psect flag defines the size of the addressable unit.
In other words, the number of data bytes that are associated with each address.
With PIC Mid-range and Baseline devices, the program memory space is word addressable; so, psects in this space must use a delta of 2.
That is to say, each address in program memory requires 2 bytes of data in the HEX file to define their contents.
So, addresses in the HEX file will not match addresses in the program memory.
The data memory space on these devices is byte addressable; so, psects in this space must use a delta of 1.
This is the default delta value.
All memory spaces on PIC18 devices are byte addressable; so a delta of 1 (the default) should be used for all psects on these devices.
The redefinition of a psect with conflicting delta values can lead to phase errors being issued by the assembler.

global - psect flag

the global psect flag indicates that the linker should concatenate this psect with global psects in other modules and which have the same name.

Ref