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

Discussion in 'Programmer's Corner' started by Robin66, Sep 14, 2016.

  1. Robin66

    Thread Starter Member

    Jan 5, 2016
    102
    3
    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.
     
  2. nsaspook

    AAC Fanatic!

    Aug 27, 2009
    2,906
    2,158
    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.
     
  3. joeyd999

    AAC Fanatic!

    Jun 6, 2011
    2,672
    2,706
    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 (ASM):
    1. pushfl x        ;put float x on stack
    2. poly   coeff    ;compute polynomial (order and coefficients defined in ROM structure coeff)
    3. popfl  y        ;get result from stack
     
    atferrari, Robin66 and OBW0549 like this.
  4. Robin66

    Thread Starter Member

    Jan 5, 2016
    102
    3
    Ah, this guy seems to have done something vaguely similar. When my C project's working correctly I might then attempt to rewrite it in asm and add a python pre-processing step before the build to wrap up the easiest and most useful wins.

    http://www.microchip.com/forums/m722494.aspx
     
  5. nsaspook

    AAC Fanatic!

    Aug 27, 2009
    2,906
    2,158
Loading...