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 0
as 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
0x0089
address 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
psect
? The linker might place the code section (ifpsect code
means this) at this other address. – the busybeepsect code,class=CODE,space=SPACE_CODE,delta=2
where SPACE_CODE is defined in#define SPACE_CODE 0
– KMC-Wl,-Map=temp.map
and what does it show intemp.map
– Michael Petch