News:

Let's find out together what makes a PIC Tick!

Main Menu

Optimised for C

Started by John Drew, Jun 07, 2023, 01:47 PM

Previous topic - Next topic

John Drew


Hello all,
Curiosity at work.
Microchip claims some PICs as optimised for C compilers.
What does that mean?
I suspect that Positron produces faster/smaller code than C or am I misunderstanding the claim for C ?
As I said, just wondering. Does anyone know the answer? I know Les prides himself on writing efficient and fast code.
John

top204

#1
They brought out that statement when they released the 18F devices all of those years ago.

It is because the 18F devices had a larger call stack and more complex indirect RAM mnemonics than the 12-bit and 14-bit core devices of the time, so the 'buzz' words were invented by them, but it is actually nonsense because C uses a lot of pointers (indirect RAM access) in programs, and the 18F devices still have a clumsy manipulation for indirect RAM and flash memory access. i.e. FSR0L\H, FSR1L\H, FSR2L\H, POSTINC0, POSTICN2, POSTINC2, Tblrd*+, TABLAT etc... So C programs that use a lot of pointers are actually not that efficient in the assembler code produced.

The PIC24 devices were the first to bring true C friendly mnemonics and architecture to the microchip family, with true linear RAM and a real RAM stack, and more indirect operation mnemonics, but still not enough for a fully "stack based" compiler to work efficiently with.

John Lawton

They said they optimised the instruction set (for compilers) by adding 'Optional extended instruction set designed to optimize re-entrant code'.

top204

#3
The extended instruction set is another set of 'buzz' words. When enabled, they actually alter the RAM bank architecture and remove some important mnemonics, all so constants can be used as an address in some indirect mnemonics.

That's why, virtually, no compiler uses it!

tumbleweed

The only compiler I know of that supported it was the old C18. XC8 doesn't.

John Lawton

I don't want to hijack this thread but it looks like I'll need to do a crash course in embedded 'C' in order to hit the contracting market as a CV without 'C' doesn't fit with most people's expectations.

Any recommendations for an online course?


John Lawton

Thanks, how is it going for you?

trastikata

Quite good, I can make a LED blink  ;D

After reading and watching most of the Microchip online guides, much became clear. My impressions so far:

- Writing your own code in C is not much different than Positron, with few particularities which are well explained in the on-line courses.

- Reading somebody else's code written in C is a nightmare.

- MPLAB X IDE looks scary only at the beginning.

- After watching the on-line courses you can easily start using basic MPLAB X functionality and build-up upon.

- Much of the functionality in MPLAB X is not documented in a single extensive guide like Les did with Positron, so you have to google your problem/question almost anytime.

- MCC is real help, actually MCC is the only reason why I started learning MPLAB X and C - because of the libraries in MCC which I need for dsPIC's.

- Header files in MPLAB and MCC are terrible experience  :D

But I am pretty encouraged as the learning curve is very steep because of the familiarity with PICs and Positron programming concepts which closely resemble C.

Yasin

The only code that all mcus understand is the hex code. I think the main reference in this case is the efficiency of the hex code. So it is the output file of the compilers. The rest could be nonsense. I think Microchip or other companies are aware of this.

John Lawton

Strictly speaking, it's the assembler program that generates the hex code from the assembly file which is in turn generated by the Positron compiler.

And therein is another tale because Microchip are changing horses from MPASM to, if I understand correctly, an open-source assembler from the gcc stable for newer devices. Les might explain further as it means he has to make compiler changes.

tumbleweed

The new assembler is PIC-ASs (the extra 's' is my reference), which is a modified version of the assembler that was originally used by the XC8 C compiler. It has a number of differences which make it unable to handle asm code written using MPASM features.

It was never really intended as a standalone assembler, but that's now what they're making do with.
XC8 is the old HiTech C compiler, and unlike the other XC compilers isn't GCC based, it's proprietary.
 

Fanie

I had to re-do a project because pics were not available, using C and the ESP32S micro.
First problem was a programmer, which I eventually found, but the standard method of programming seems to use an existing board which is simulated onto your project.
Then they stack various IDE platforms on top one another to obtain functionality.
I ended up using only the Arduino IDE.
The C was another thing.  They do have commands like goto but you cannot use them.
I ended up getting my brother doing the software together using Anydesk so I can follow and assist in the coding - in between all the daily power failures.
I can fully understand why programming in C is such a lengthy episode.  The position placement of routines is important and everything felt upside down.
The ESP32S is an awesome micro.  Just wished it can be featured in Positron  ;)
In comparison between C and Positron (Protron) I would give Les a 9/10 and C a 4/10.
I consider the C primitive.  I don't consider myself a good coder but this is my opinion.
The pics I use most have escalted in price as a result of the scamdemic, the 16F684 I use most has gone from about ZAR 20 to ZAR 75 - IF you can get them.  I have many hundreds of PCB's for the Pic's which would be a waste if...

okmn

Quote from: Fanie on Jun 14, 2023, 12:14 PMI had to re-do a project because pics were not available, using C and the ESP32S micro.
First problem was a programmer, which I eventually found, but the standard method of programming seems to use an existing board which is simulated onto your project.
Then they stack various IDE platforms on top one another to obtain functionality.
I ended up using only the Arduino IDE.
The C was another thing.  They do have commands like goto but you cannot use them.
I ended up getting my brother doing the software together using Anydesk so I can follow and assist in the coding - in between all the daily power failures.
I can fully understand why programming in C is such a lengthy episode.  The position placement of routines is important and everything felt upside down.
The ESP32S is an awesome micro.  Just wished it can be featured in Positron  ;)
In comparison between C and Positron (Protron) I would give Les a 9/10 and C a 4/10.
I consider the C primitive.  I don't consider myself a good coder but this is my opinion.
The pics I use most have escalted in price as a result of the scamdemic, the 16F684 I use most has gone from about ZAR 20 to ZAR 75 - IF you can get them.  I have many hundreds of PCB's for the Pic's which would be a waste if...


---The ESP32S is an awesome micro.  Just wished it can be featured in Positron  ;)---  I wish too.

tumbleweed

QuoteThe position placement of routines is important and everything felt upside down.
Not if you use function prototypes. If you do that then the placement shouldn't matter. Otherwise it makes assumptions about the routines and that's where you'll run into problems.

Fanie

Quote from: tumbleweed on Jun 14, 2023, 02:25 PM
QuoteThe position placement of routines is important and everything felt upside down.
Not if you use function prototypes. If you do that then the placement shouldn't matter. Otherwise it makes assumptions about the routines and that's where you'll run into problems.

What is a function prototype ? 
I would like to know how to do the routine placement so it would not matter - please.

tumbleweed

If you're asking that question your best option would be to get a book on C.