MPLAB: PIC18F: Creating my own language/compiler --> asm

Thread Starter

Robin66

Joined Jan 5, 2016
275
Hello. I'm working on a pic18f project and I've recently made the transition from asm-->C in MPLAB X IDE. I've enjoyed the improvement in dev time but at the same time I feel distant from the MCU and C is wrapping up concepts that are foreign to it eg. local vs global variables. Also I'm quite surprised at how expensive compilers are and I despair when I observe the disassembly output from xc8-lite. So now I'm wondering if I could go back to writing in asm but wrap-up functionality in easy to deconstruct shorthand which would be translated to asm upon building ie. define my own language and write some script in python that passes over my code and ouputs a .asm file.

eg.
char a,b,c;
compiler would recognise a new line like "char *" and would assign registers to the csvs "a", "b", "c", knowing the address ranges of my chip​
b = 5;
Compiler would create output
movlw 5
movwf <b's assigned register>

Is this possible in MPLAB IDE? Does anyone have any experience of this or can point me to a tutorial that gives a simple example? Obviously I'd pick my battles carefully; I don't want to reinvent the wheel entirely... just bits of it with easy wins.
 

nsaspook

Joined Aug 27, 2009
13,272
My humble suggestion is to let it go unless it's a limiting factor in a real project. If you have a section of code that needs ASM then use that, for just about everything else use C. The limitations with the free XC8 is an artificial impediment to using C efficiently on small machines that shouldn't stop you from learning the language properly.
 

joeyd999

Joined Jun 6, 2011
5,283
I keep a few .inc files on hand that contain macros for common things. That, and modular code development makes .asm easy, fast, accurate, and tight.

As an extreme example, here is the code to compute y=a floating point polynomial (any order) over float x:

Code:
pushfl x        ;put float x on stack
poly   coeff    ;compute polynomial (order and coefficients defined in ROM structure coeff)
popfl  y        ;get result from stack
 
Top