MPASMtoPICAS v0.9b
MPASMtoPICAS v0.9b
MPASMtoPICAS v0.9b
Contents
What is MPASM ? ................................................................................................................................ 2
What is PIC-AS ? ................................................................................................................................. 2
Reference Documents ......................................................................................................................... 2
Context of Project ................................................................................................................................. 3
Summary ............................................................................................................................................... 3
Insights ................................................................................................................................................... 4
PIC-AS Command Line ....................................................................................................................... 7
18F specifics ......................................................................................................................................... 8
Midrange 10f, 12f and 16f specifics................................................................................................. 10
Debugging ........................................................................................................................................... 14
Version 0.9b
What is MPASM ?
The last chip added to MPASM was the 18FxxQ43. So, any chip released
after this (Q10s, Q41s etc) will not work.
What is PIC-AS ?
PIC-AS - v2.32 is the latest version of the PIC-AS assembler driver. This is
a standalone driver and you do not need MPLAB-X to assemble your
source code.
https://ww1.microchip.com/downloads/en/DeviceDoc/MPLAB%20XC8%20PIC%20As
sembler%20User%27s%20Guide%2050002974A.pdf
https://ww1.microchip.com/downloads/en/DeviceDoc/XC8-PIC-Assembler-UG-for-
EE-50002994A.pdf
https://ww1.microchip.com/downloads/en/DeviceDoc/MPASM%20to%20MPLAB%20
XC8%20PIC%20Assembler%20Migration%20Guide%2050002973A.pdf
Context of Project
Within Great Cow BASIC ( a compiler for LGT/AVR and PICs) we use
ABSOLUTE addressing and these insights therefore apply to ABSOLUTE
addressing. But, most of these insights are useful in any mode of
addressing.
Summary
You can port an existing ASM to PIC-AS just take a little care.
Insights
1. Source file: The source file has the extension of `.S`. The .S implies
the PIC-AS driver uses the -xassembler-with-cpp option. The assembly
source code will therefore be pre-processed.
The reverse lookup PIC-AS files are very easy to determine. The following
is a pic16f877a example. Note the PIC-AS version number and the
chipname.
Code:
Code:
5. Config: The config definition is strict. You just need to have the configs
one per line. As config names are strict - we complete a reverse lookup to
ensure the case is correct.
We use the EQU method - make the variable name global (for debugging).
Code:
;Set aside RAM memory locations for variables. All variables are global.
GLOBAL DELAYTEMP
DELAYTEMP EQU 112 ; 0X70
GLOBAL DELAYTEMP2
DELAYTEMP2 EQU 113 ; 0X71
GLOBAL SYSWAITTEMPMS
SYSWAITTEMPMS EQU 114 ; 0X72
GLOBAL SYSWAITTEMPMS_H
SYSWAITTEMPMS_H EQU 115 ; 0X73
The memory usage reports from PIC-AS are not very good and EQUs are
not reported in the log but you can verify in the LST file.
8. FCALL and LJMP: The PIC-AS driver is smart. Too smart. It will
reject CALL and GOTOs to another page. There is NO level of magic
coding (by you) to avoid not using FCALL and LJMP will succeed. These
two instructions are automatically expanded by PICAS (into three
instructions). You will have to change to FCALL and LJMP.
9. ALIGN: Specific to the 18F you must ensure your code is aligned
correctly. See the 18f section below for details.
10. Bugs: A number of bugs existing in the 10f, 12f and 16f PIC-AS
solution. See the 10f, 12f and 16fs section below for details.
Code:
LINE
HEX
ERROR
PIC-AS Command Line
This is the command line used:
This sections is specific to 18F chips. This covers PSECTS and Alignment
of code.
PSECTs
PSECTS - short for program sections - are containers that group and hold
related parts of the program, even though the source code for these parts
might not be physically adjacent in the source file, or may even be spread
over several modules.
Use `delta = 1, abs` and, you need to add the RESETVEC. As follows:
Code:
…
lots of code
…
;
; Declare Power-On-Reset entry point
;
END RESETVEC
Alignment
ALIGN 2;X3
GLOBAL STRINGTABLE6
STRINGTABLE6:
DB 33,69,110,100,32,111,102,32,69,69,80,114,111,109,32,80,114,111,103,114,97,109
DB 32,97,110,100,32,68,105,115,112,108,97,121
ALIGN 2;X3
;********************************************************************************
PSECTS
Use delta = 2, abs mode and you need to add the RESETVEC. As follows:
PSET per page (where a PSECT is added in the chip has that specific
page).
Code:
;********************************************************************************
…
lots of code
…
…
lots of code
…
…
lots of code
…
…
lots of code
…
;
; Declare Power-On-Reset entry point
;
END RESETVEC
Bugs
The v2.32 PIC-AS driver has some horrid bugs.
Code:
REPORTING: The error report is wrong when the PSECT delta=2. Just
divided the memory address that has the error by 2. Annoying.
My advice. Add GLOBAL to all labels and variable definitions. This makes
debugging a lot easier.