I'm using MPLabX IDE 5.4 with XC8 compiler (a C/MPASM hybrid compiler that has a driver named pic-as v.2.2 as its assembler) to compile/assemble a simple piece of assembly code and to output a listing file.
My entire assembly code:
PROCESSOR 16F84A
#include <xc.inc>
PSECT code
; a comment
org 00
addlw 01
addlw 02
addlw 03
clrw
loop: addlw 04
goto loop
end loop
Listing file:
Same result generated either from MPLab X IDE's Disassembly Listing File or through a CLI command: $pic-as -mcpu=16F84A -Wa,-a MyAssemblyFile.S -o MyFolder/MyOutputFileName):
1 processor 16F84A
2 pagewidth 132
3 psect udata,global,class=RAM,space=1,delta=1,noexec
4 psect udata_bank0,global,class=BANK0,space=1,delta=1,noexec
5 psect code,global,class=CODE,delta=2
6 psect data,global,class=STRCODE,delta=2,noexec
7 psect edata,global,class=EEDATA,space=3,delta=2,noexec
8 0089
9 psect code
10 01FA org 0
11 01FA 3E01 addlw 1
12 01FB 3E02 addlw 2
13 01FC 3E03 addlw 3
14 01FD 0103 clrw
15 01FE loop:
16 01FE 3E04 addlw 4
17 01FF 29FE goto loop
The first column contains the line number (i.e. 1,2,3...19). The second and third column list out respectively the memory (vector) addresses (0x01FA-0x01FE) and the opcode (3E08, 29FE etc.) per instruction.
Questions:
- Shouldn't the instructions be stored sequentially from 0x0000-0x03FF (PIC16F84A's Program Memory addresses). 0x0000 should always be the starting line or origin of a program, and I've also explicitly stated
org 0as the program origin. But the listing file shows instructions occupying 0x01FA-0x01FF instead - as if the assembler counted upward from the middle of the program memory (0x03FF / 2 = 0x01FF) and started off from 0x01FA. - What is
0x0089address and why is it there?
[EDIT] Mapping File (if it matters)
Name Link Load Length Selector Space Scale
Output/temp.o code 1FA 1FA 6 3F4 0
TOTAL Name Link Load Length Space
CLASS CODE
code 1FA 1FA 6 0
Microchip has made it very to hard to develop 8-bit assembly language applications using the latest release of MPLABX v5.40.
To help I have crafted a PIC16F84A example project you can find here.
This is the pic-as(v2.20) source code:
If you can please get a copy of the entire MPLABX project from my git repository. There are some things you need to learn about setting up an assembly language project in MPLABX that Microchip has not document in enough detail yet.
I am not an employee if Microchip and they could not pay me enough to do this for them.
I expect issues with the MPLABX tools to become more of a problem as schools start teaching PIC assembly language in the fall sessions. My goal with this answer is to try to help before more students get frustrated and fail because of trivial issues with lame tools.