C in a uC... what were they thinking??
Re: C in a uC... what were they thinking??
These are good meaningful comments but it clearly shows the
desire to have an assembler that allowed multiple statements per line.
The comments could just as easily been put at the break comments you
had as empty lines, in many of the cases.
Dwight
desire to have an assembler that allowed multiple statements per line.
The comments could just as easily been put at the break comments you
had as empty lines, in many of the cases.
Dwight
- GARTHWILSON
- Forum Moderator
- Posts: 8774
- Joined: 30 Aug 2002
- Location: Southern California
- Contact:
Re: C in a uC... what were they thinking??
dwight wrote:
These are good meaningful comments but it clearly shows the
desire to have an assembler that allowed multiple statements per line.
desire to have an assembler that allowed multiple statements per line.
I'm not saying there's no place for HLLs, only that some of the criticisms against assembly language are often false charges.
http://WilsonMinesCo.com/ lots of 6502 resources
The "second front page" is http://wilsonminesco.com/links.html .
What's an additional VIA among friends, anyhow?
The "second front page" is http://wilsonminesco.com/links.html .
What's an additional VIA among friends, anyhow?
Re: C in a uC... what were they thinking??
As for macros, I rarely use a branch statement out side of
some type of flow structure macro.
No more L1, L2 etc labels.
Dwight
some type of flow structure macro.
No more L1, L2 etc labels.
Dwight
- BigDumbDinosaur
- Posts: 9427
- Joined: 28 May 2009
- Location: Midwestern USA (JB Pritzker’s dystopia)
- Contact:
Re: C in a uC... what were they thinking??
dwight wrote:
These are good meaningful comments but it clearly shows the desire to have an assembler that allowed multiple statements per line.
Quote:
The comments could just as easily been put at the break comments you had as empty lines, in many of the cases.
POC V1.1's firmware runs to over 12,000 lines of source code. POC V2's source code will be even larger (it's already near 14,000 lines) and more complex. Without rational formatting, it would be a reading quagmire, especially if lines contained multiple statements.
GARTHWILSON wrote:
I believe I've seen such assemblers (and Forth assemblers do it routinely); but again the power of assembly-language macros goes widely ignored, misunderstood, and unused. Used properly, macros can dramatically raise the level of the language, with, in most cases, no penalty of any kind, while improving programmer productivity and software maintainability, and reducing bugs.
Code: Select all
LDA #'a' ;char to print
TRAP _b_writsioa ;write char to consoleBy the way, the TRAP instruction itself is a macro:
Code: Select all
TRAP .macro .api
.if .api = 0 || .api > maxapi
.error ""+%1+": API index out of range"
.else
PEA #.api ;API index to stack
COP #$00 ;call API handler in BIOS
.endmx86? We ain't got no x86. We don't NEED no stinking x86!
Re: C in a uC... what were they thinking??
Oneironaut wrote:
Recently, I had the job of taking over someone's prototype development, and part of the system included C code to read RAW data from an SD card. Having recently written my own SD card code for the 6502, I figure it would be an easy project to do. It took me only a few hours to get SD access on the 6502 using assembly, and it is minimal code.
Well, after 2 days I finally gave up!
Well, after 2 days I finally gave up!
Quote:
I eventually downloaded the PIC assembly list and just coded the thing from scratch in 3 hours.
Quote:
The code went form at least 400 lines to about 30, and program memory usage was way down.
Sounds to me that the C code was simply doing more than it should, it may even be likely that the code was imported from another project (perhaps even another processor) that also needed an SD card. If the solution could be expressed with 30 lines of assembly, it could likely have been addressed with less C code. It perhaps may not have taken the C developer 3 hours to develop it either.
Quote:
I have never been able to figure out why anyone though that C on a small uC was a good idea.
Economy and efficiency of code become less and less important as the capability of the processors get better and better. At best, they're necessary for a small fraction of the overall code base, becoming a "nice to have", but "don't spend any time on it". Cue up the treatises decrying pre-optimization. The fastest, smallest code in the world may well still be stuck spinning and waiting for the next clock from the slow SD card.
Seems to me your example is more a discussion on the other developers understanding of the task at hand rather than anything to do with C. Having just done this yourself, you may have been able to bring keen insight the original developer lacked in how to pursue the problem. You said so yourself, it certainly wasn't your expertise in PIC assembly.
- GARTHWILSON
- Forum Moderator
- Posts: 8774
- Joined: 30 Aug 2002
- Location: Southern California
- Contact:
Re: C in a uC... what were they thinking??
whartung wrote:
Sounds to me that the C code was simply doing more than it should, it may even be likely that the code was imported from another project (perhaps even another processor) that also needed an SD card. If the solution could be expressed with 30 lines of assembly, it could likely have been addressed with less C code. It perhaps may not have taken the C developer 3 hours to develop it either.
http://WilsonMinesCo.com/ lots of 6502 resources
The "second front page" is http://wilsonminesco.com/links.html .
What's an additional VIA among friends, anyhow?
The "second front page" is http://wilsonminesco.com/links.html .
What's an additional VIA among friends, anyhow?
Re: C in a uC... what were they thinking??
I am not particularly a C fan. Still, for the arduino, it is reasonable.
As was mentioned, the libraries may be what you need. They also may be
over bloated and they may have bugs in them.
On the few tinker projects I've done on my arduino, I've often looked at the
source code for the library and extracted or modified the parts I needed.
In one case I even saw some bugs ( at least the code didn't properly match
the manufacture specification but didn't seem to do harm ).
One may be used to the old style of assembler and comfortable with it
but it is the major reason why many find it hard to get started in it.
The proper use of white space, both vertical and horizontal makes coding
that needs less comments and easier to maintain.
The code should say what it does. The comments should say why your doing
it. Choice of label names and routine names is the best first level of commenting.
Like the example of the FIFO. A single line comment stating that:
If the input and output pointers are different, I need to handle the data
until they are matched again.
...code...
Would clearly make the code clearer and made the code easier to maintain.
Not everyone is familiar with your coding style.
As was mentioned, the libraries may be what you need. They also may be
over bloated and they may have bugs in them.
On the few tinker projects I've done on my arduino, I've often looked at the
source code for the library and extracted or modified the parts I needed.
In one case I even saw some bugs ( at least the code didn't properly match
the manufacture specification but didn't seem to do harm ).
One may be used to the old style of assembler and comfortable with it
but it is the major reason why many find it hard to get started in it.
The proper use of white space, both vertical and horizontal makes coding
that needs less comments and easier to maintain.
The code should say what it does. The comments should say why your doing
it. Choice of label names and routine names is the best first level of commenting.
Like the example of the FIFO. A single line comment stating that:
If the input and output pointers are different, I need to handle the data
until they are matched again.
...code...
Would clearly make the code clearer and made the code easier to maintain.
Not everyone is familiar with your coding style.
- BitWise
- In Memoriam
- Posts: 996
- Joined: 02 Mar 2004
- Location: Berkshire, UK
- Contact:
Re: C in a uC... what were they thinking??
dwight wrote:
I am not particularly a C fan. Still, for the arduino, it is reasonable.
I'm always amazed that the generated code actually fits on an Arduino. The C++ libraries on UNIX and Windows generate masses of code bloat.
Andrew Jacobs
6502 & PIC Stuff - http://www.obelisk.me.uk/
Cross-Platform 6502/65C02/65816 Macro Assembler - http://www.obelisk.me.uk/dev65/
Open Source Projects - https://github.com/andrew-jacobs
6502 & PIC Stuff - http://www.obelisk.me.uk/
Cross-Platform 6502/65C02/65816 Macro Assembler - http://www.obelisk.me.uk/dev65/
Open Source Projects - https://github.com/andrew-jacobs
Re: C in a uC... what were they thinking??
Remember folks...one man's code bloat is another man's highly-optimized code.
We've all had stories of taking code someone else wrote and making it more efficient. It's fun and makes us feel good. But unless you're in the top 1% of programmers in the world, or hand assemble raw hex codes for a living, there's a good chance you're using someone else's code bloat and that's not always a bad thing.
Being a Java programmer, I'm surrounded by code bloat. Some of it's mine (I get better over the years) and some of it's from open source libraries I use.
But I'm sure as heck not going to write my own TCP/IP stack in hand-coded hex binary files for the bragging rights of saying I'm better. Sometimes, you have to use other people's code bloat to get a project done so that you can move on to something else.
The programming world is full of "Michelangelo's" of software that never seem to get anything done.
Anyway...just saying.
We've all had stories of taking code someone else wrote and making it more efficient. It's fun and makes us feel good. But unless you're in the top 1% of programmers in the world, or hand assemble raw hex codes for a living, there's a good chance you're using someone else's code bloat and that's not always a bad thing.
Being a Java programmer, I'm surrounded by code bloat. Some of it's mine (I get better over the years) and some of it's from open source libraries I use.
But I'm sure as heck not going to write my own TCP/IP stack in hand-coded hex binary files for the bragging rights of saying I'm better. Sometimes, you have to use other people's code bloat to get a project done so that you can move on to something else.
The programming world is full of "Michelangelo's" of software that never seem to get anything done.
Anyway...just saying.
Cat; the other white meat.
Re: C in a uC... what were they thinking??
Yeah, I disagree strongly with the "other people's code is slow and bloated" sentiment. And the idea that 'C' libraries are somehow intrinsically bloated is nonsense I only hear from people trying to justify their own choices or push their own preferences. Are there bloated libraries? Sure. Are there instances of other people's code that is slow? Of course. Does that apply to every language and environment since the invention of computers? Yup.
Stand on the shoulders of giants... you'll see farther.
Stand on the shoulders of giants... you'll see farther.
Re: C in a uC... what were they thinking??
sark02 wrote:
Yeah, I disagree strongly with the "other people's code is slow and bloated" sentiment. And the idea that 'C' libraries are somehow intrinsically bloated is nonsense I only hear from people trying to justify their own choices or push their own preferences.
Again, my point is that sometimes you have to choose your battles. Sometimes, you have to use bloated, garbage code because nothing else exists or it's not worth the effort to fix it. Sometimes...you just have to get something done and move on.
I try *VERY* hard to write efficient code. But I know for a fact there are better developers than me in the world that would complain how "lazy" I am. It's all relative.
sark02 wrote:
Stand on the shoulders of giants... you'll see farther.
Cat; the other white meat.
- barrym95838
- Posts: 2056
- Joined: 30 Jun 2013
- Location: Sacramento, CA, USA
Re: C in a uC... what were they thinking??
cbmeeks wrote:
... The programming world is full of "Michelangelo's" of software that never seem to get anything done.
Anyway...just saying.
Anyway...just saying.
Re: C in a uC... what were they thinking??
cbmeeks wrote:
I think you misunderstood my comments completely.
I [stand on the shoulders of giants] on a daily basis. Been doing it for over 30 years.
I [stand on the shoulders of giants] on a daily basis. Been doing it for over 30 years.
Re: C in a uC... what were they thinking??
barrym95838 wrote:
Mike B.
LMAO!!! Actually, I used Curly as my avatar for many websites for years. I've recently switched over to Larry. I have an unhealthy obsession with the Stooges. All SEVEN of them (and no, I'm not counting Ted).
sark02 wrote:
I was actually agreeing with you. I saw your post and wanted to add my own thoughts.

Cat; the other white meat.
- barrym95838
- Posts: 2056
- Joined: 30 Jun 2013
- Location: Sacramento, CA, USA
Re: C in a uC... what were they thinking??
cbmeeks wrote:
... I have an unhealthy obsession with the Stooges ...
Mike B.