• AVR Freaks

Helpful ReplyHot!Pic Programming Language

Page: < 1234 > Showing page 3 of 4
Author
NorthGuy
Super Member
  • Total Posts : 5544
  • Reward points : 0
  • Joined: 2014/02/23 14:23:23
  • Location: Northern Canada
  • Status: offline
Re: Pic Programming Language 2018/11/06 08:37:20 (permalink)
0
Brane2
BY that I mean something that is effectively an assembler but with convenient macro-like tools that would make it possible for one to not spell-out directly the name of every register on machine ( if/when that can be avoided) and to be able to use some symbolics, like " a = b/c +2 " etc.



This is essentially what C is. It has assemler's flow. You can insert manual assembler everywhere. The output of the C compiler is nothing more than the assembler code which you feed to the compiler.
 
The reason it is hard to use as "human assembly" on PIC16, is that the compiler brings in too much of an infrastructure to cope with C standard, so it hinders the idea. On PIC32 (MIPS), there's no such problem, if you have any reason to use assembler on PIC32 that is.
 
#41
Brane2
Senior Member
  • Total Posts : 175
  • Reward points : 0
  • Joined: 2011/09/29 19:56:29
  • Location: Ljubljana, Slovenia
  • Status: offline
Re: Pic Programming Language 2018/11/06 08:52:26 (permalink)
0
Not really.
 
For example, how does C optimize the code across compile units ?
It doesn't, ofcourse. Make is done so that it compile each .c into .o, which it then links together.
Which inevitably means some glue between linked parts. Unless they are linked with flto, but that also doesn't eliminate, just reduce the bloat.
 
Take for example int variable that gets to be used from several contexts ( like main and INT routine )
 
In assembler, you can tell if there is danger that one context might spoil it for another.
 
In C, all you can do is declare it as "volatile". In assembly, you can do rotations etc.
 
In C, all you can do is >> and << etc etc.
 
PIC32 is nice machine and its assembler looks nice. There is no great need to have a compiler inbetween the machine and you, hoping for optimisations but most of the time fretting of f***ps.
 
x86/x86_64 is another matter. But these small and simple MIPS cores with nice ISA aren't too complicated for assembly.
 
For projects that are a bit more complex, all I would need is a more intelligent assembler...
 
 
 
 
#42
NKurzman
A Guy on the Net
  • Total Posts : 17618
  • Reward points : 0
  • Joined: 2008/01/16 19:33:48
  • Location: 0
  • Status: offline
Re: Pic Programming Language 2018/11/06 09:10:04 (permalink)
+2 (2)
Now you are taking in generalities XC8 does compile across the entire program. (OCG)
C has a trade off between ASM control and portibity. If you want ASM it is always there. But the original ASM programmers wanted more. They made HLL like C.
#43
NorthGuy
Super Member
  • Total Posts : 5544
  • Reward points : 0
  • Joined: 2014/02/23 14:23:23
  • Location: Northern Canada
  • Status: offline
Re: Pic Programming Language 2018/11/06 09:12:39 (permalink)
0
Brane2
For example, how does C optimize the code across compile units ?

 
The assembler doesn't optimize anything. You probably wouldn't get much optimization in your "human assembly". And I'm sure, your "human assembly" would definitely had problems what other people wouldn't like - just the same as you don't like things in C.
 
BTW: XC8 does optimize across the entire program
 
Brane2
But these small and simple MIPS cores with nice ISA aren't too complicated for assembly.

 
The problem is that ISA is built in such a way that using assembler won't get you much gain compared to C. For comparison, PIC24 is good for humans while XC16 doesn't take full advantage of the ISA.


#44
1and0
Access is Denied
  • Total Posts : 9509
  • Reward points : 0
  • Joined: 2007/05/06 12:03:20
  • Location: Harry's Gray Matter
  • Status: offline
Re: Pic Programming Language 2018/11/06 09:15:17 (permalink)
+1 (1)
Brane2
In assembly, you can do rotations etc.
 
In C, all you can do is >> and << etc etc.

The C language does not have a rotate operator, but rotations can be performed using the shift and bitwise OR operators. Depending on the compiler, the compiler will look for code expressions that implement rotates and use the rotate instruction, if the PIC devices have a rotate instruction. For examples in XC8,
foo = (foo << 1) | (foo >> 7);

generates
rlncf   foo,f

and
foo = (foo << 4) | (foo >> 4);

generates
swapf   foo,f

#45
Brane2
Senior Member
  • Total Posts : 175
  • Reward points : 0
  • Joined: 2011/09/29 19:56:29
  • Location: Ljubljana, Slovenia
  • Status: offline
Re: Pic Programming Language 2018/11/06 09:29:18 (permalink)
0
NKurzman
Now you are taking in generalities XC8 does compile across the entire program. (OCG)
C has a trade off between ASM control and portibity.



Which was great deal on desk machines.On big machines, which evolved in big part into off-the-shelf 32 and 64-bitters with shitloads of memory and multi GHz ultacomplex cores and infrastructure.
Even in Linux kernel, not many will care that some variable takes int32_t in memory while it uses perhaps only 8 bits.
Even if someone  would care, there are many other concerns like memory and cache alignment etc etc.
 
On micros. I have a feeling that is much less so.
Here I have machine that accesses more or less all data directly. I don't have to worry about TLB hit/miss, caches etc etc, but data footprint still is important, especially on machine that works at 25 MHz tops
 
NKurzman
If you want ASM it is always there.

ASM in C sucks even as a form of medieval capital punishment. It's so awkward that it can practically be done just for showrt snippets and even then one would be well adviced to d**k around and check how the C<-->ASM is connected.
If whole point of using ASM is efficiency, one wouldn't want wastage durign data transfer...
 
In C, I can't have simple function with multiple entries or exits, unless compiler sees an oportunity to do so etc.
On complex dual-issue machine with MMU and several cache levels and RAM banks , It can be hard to keep track of all hazards and dependencies. On PIC32MM, this is far less of a concern.
 
 
 
 
 
#46
Brane2
Senior Member
  • Total Posts : 175
  • Reward points : 0
  • Joined: 2011/09/29 19:56:29
  • Location: Ljubljana, Slovenia
  • Status: offline
Re: Pic Programming Language 2018/11/06 09:31:11 (permalink)
0
1and0
 For examples in XC8,
foo = (foo << 1) | (foo >> 7);

generates
rlncf   foo,f

and
foo = (foo << 4) | (foo >> 4);

generates
swapf   foo,f





Which is so much easier in "HLL" than one friggin assembly instruction ? ;o)
#47
1and0
Access is Denied
  • Total Posts : 9509
  • Reward points : 0
  • Joined: 2007/05/06 12:03:20
  • Location: Harry's Gray Matter
  • Status: offline
Re: Pic Programming Language 2018/11/06 09:41:12 (permalink)
0
Brane2
 
Which is so much easier in "HLL" than one friggin assembly instruction ? ;o)

I'm a little slow today. What do you mean?
 
#48
Brane2
Senior Member
  • Total Posts : 175
  • Reward points : 0
  • Joined: 2011/09/29 19:56:29
  • Location: Ljubljana, Slovenia
  • Status: offline
Re: Pic Programming Language 2018/11/06 09:47:14 (permalink)
0
My point was that C is often far to awkward and that the same thing can often be done much more elegrantly in assembler.
 
I know that one can achieve var rotation in C. That was never in dispute.
BUt your example gave weight to my point.
 
many lines and guessing what will compiler actually do vs one simple asm statement...
 
 
 
 
#49
Gort2015
Klaatu Barada Nikto
  • Total Posts : 3148
  • Reward points : 0
  • Joined: 2015/04/30 10:49:57
  • Location: 0
  • Status: offline
Re: Pic Programming Language 2018/11/06 10:00:04 (permalink)
0
What is HLL?

MPLab X playing up, bug in your code? Nevermind, Star Trek:Discovery will be with us soon.
https://www.youtube.com/watch?v=Iu1qa8N2ID0
+ ST:Continues, "What Ships are Made for", Q's back.
#50
1and0
Access is Denied
  • Total Posts : 9509
  • Reward points : 0
  • Joined: 2007/05/06 12:03:20
  • Location: Harry's Gray Matter
  • Status: offline
Re: Pic Programming Language 2018/11/06 10:01:52 (permalink)
0
Gort2015
What is HLL?

High Level Language ;)
#51
Gort2015
Klaatu Barada Nikto
  • Total Posts : 3148
  • Reward points : 0
  • Joined: 2015/04/30 10:49:57
  • Location: 0
  • Status: offline
Re: Pic Programming Language 2018/11/06 10:02:29 (permalink)
0
High Level Language?

MPLab X playing up, bug in your code? Nevermind, Star Trek:Discovery will be with us soon.
https://www.youtube.com/watch?v=Iu1qa8N2ID0
+ ST:Continues, "What Ships are Made for", Q's back.
#52
mbrowning
Just a Member
  • Total Posts : 1462
  • Reward points : 0
  • Joined: 2005/03/16 14:32:56
  • Location: Melbourne, FL
  • Status: offline
Re: Pic Programming Language 2018/11/06 10:04:59 (permalink)
0
You know - like Prolog or Lisp. Cause C is certainly not a high level language.

Oh well - there's always next year
#53
1and0
Access is Denied
  • Total Posts : 9509
  • Reward points : 0
  • Joined: 2007/05/06 12:03:20
  • Location: Harry's Gray Matter
  • Status: offline
Re: Pic Programming Language 2018/11/06 10:05:35 (permalink)
+1 (1)
Brane2
My point was that C is often far to awkward and that the same thing can often be done much more elegrantly in assembler.
 
I know that one can achieve var rotation in C. That was never in dispute.
BUt your example gave weight to my point.
 
many lines and guessing what will compiler actually do vs one simple asm statement...

Depending on your view and the code, C can be elegant too. Try coding something as simple as this in assembly:
float a, b, c, x;
x = (-b + sqrt(b*b - 4*a*c)) / (2*a);

which I taught our daughter recently, even though she has not learned this in advance math class in school yet.

There is always a trade-off. Assembly is low level; other languages are high level. Each has its pros and cons. Use whatever you feel the most comfortable and knowledgeable. At the end of the day, a working project is the final goal.
#54
Brane2
Senior Member
  • Total Posts : 175
  • Reward points : 0
  • Joined: 2011/09/29 19:56:29
  • Location: Ljubljana, Slovenia
  • Status: offline
Re: Pic Programming Language 2018/11/06 10:23:59 (permalink)
0
1and0
 
[code]float a, b, c, x;
x = (-b + sqrt(b*b - 4*a*c)) / (2*a);




That wouldn't be anything drastic in assembly. A couple of calls and moves.
But you'd have plenty of room for various shortcuts that your symbolic notion lacks.
On micro, working on perhaps 20MHz off battery while doing many things in parallel, that speed and control might be worthwile.
 
Your daughter might have used the line, but would she be able to find a compiler bug or locate rounding error that f**ks up the result ?
 
 
 
#55
Antipodean
Super Member
  • Total Posts : 1724
  • Reward points : 0
  • Joined: 2008/12/09 10:19:08
  • Location: Didcot, United Kingdom
  • Status: offline
Re: Pic Programming Language 2018/11/06 10:28:34 (permalink)
+2 (2)
Brane2
1and0
 
[code]float a, b, c, x;
x = (-b + sqrt(b*b - 4*a*c)) / (2*a);

That wouldn't be anything drastic in assembly. A couple of calls and moves.
But you'd have plenty of room for various shortcuts that your symbolic notion lacks.
On micro, working on perhaps 20MHz off battery while doing many things in parallel, that speed and control might be worthwile.
 
Your daughter might have used the line, but would she be able to find a compiler bug or locate rounding error that f**ks up the result ?

 
Please feel free to present a WORKING PIC16 assembler example.
 
Quite frankly I think you are rather out of touch with modern C compilers and how good they are at optimization, even on PIC16 architecture.
 
 

Do not use my alias in your message body when replying, your message will disappear ...

Alan
#56
Jim Nickerson
User 452
  • Total Posts : 6124
  • Reward points : 0
  • Joined: 2003/11/07 12:35:10
  • Location: San Diego, CA
  • Status: offline
Re: Pic Programming Language 2018/11/06 10:35:41 (permalink)
0
missing post maybe quoted Alan's alias
#57
1and0
Access is Denied
  • Total Posts : 9509
  • Reward points : 0
  • Joined: 2007/05/06 12:03:20
  • Location: Harry's Gray Matter
  • Status: offline
Re: Pic Programming Language 2018/11/06 10:38:10 (permalink)
0
Brane2
 
That wouldn't be anything drastic in assembly. A couple of calls and moves.
But you'd have plenty of room for various shortcuts that your symbolic notion lacks.

As Alan said, please post a working PIC16 or even a PIC18 assembly example.  As for the bug you mentioned below, the floating pointing assembly routines provided by Microchip have its own bugs too -- try locating them yourself! 
 
As you said, the same can be said here, many lines of assembly code vs one simple C statement. ;)
 

On micro, working on perhaps 20MHz off battery while doing many things in parallel, that speed and control might be worthwile.
 
As I've said, each has its pros and cons. Use whatever fits your project.
 

Your daughter might have used the line, but would she be able to find a compiler bug or locate rounding error that f**ks up the result ?

As a matter of fact, she is learning coding too. She is in middle school and plans to take the college entry exam (normally for high school students) this summer.
#58
Brane2
Senior Member
  • Total Posts : 175
  • Reward points : 0
  • Joined: 2011/09/29 19:56:29
  • Location: Ljubljana, Slovenia
  • Status: offline
Re: Pic Programming Language 2018/11/06 10:43:08 (permalink)
0
IOW, that one line expressions have really bought her nothing.
 
Useful project on a micro, especially nontrivial one is far more than simple oneliner.
 
It might be amusing corner case but it is far form practicall use.
 
Especially when you consider the fact that YOU are responsible for final effect.
Underlying mechanisms might be of help, but you are the one that has to have everything under control, including your tools. If your tools do have the habit to misbehave.
 
 
 
 
#59
1and0
Access is Denied
  • Total Posts : 9509
  • Reward points : 0
  • Joined: 2007/05/06 12:03:20
  • Location: Harry's Gray Matter
  • Status: offline
Re: Pic Programming Language 2018/11/06 10:52:32 (permalink)
+1 (1)
FYI, assembler has its shares of bugs too. The floating point assembly routines I mentioned above are written for PIC16 devices; they are _not_ optimized for the PIC18 devices. Finding and fixing its bugs is no fun task. Mod them for PIC18 is no fun either. Or perhaps you'll write your own floating point assembly routines?
 
Like I said, each has its pros and cons. Use whatever you believe is the right tools for the job.
 
#60
Page: < 1234 > Showing page 3 of 4
Jump to:
© 2019 APG vNext Commercial Version 4.5