Why would the following line in C:
XRAM00 |= 0x01;
compile into this:
mov dptr, #XRAM00 movx a, @dptr mov r7, a mov a, r7 orl a, #1 mov r7, a mov dptr, #XRAM00 mov a, r7 movx @dptr, a
I would have expected this:
mov dptr, #XRAM00 movx a, @dptr orl a, #1 movx @dptr, a
Imagine you're a compiler. You see the statement
So you think to yourself, "Fine. Let's break that down."
load XRAM00 Or with 0x01 Store XRAM00
1. Load XRAM00. Hm, need a register for the temporary. R7 is free. So load XRAM00 into R7. XRAM00 is in xdata. That means I have to use the DPTR and go through the accumulator. Grumble, grumble, stupid 8051 architecture, grumble.
mov dtpr, #XRAM00 movx a, @dptr mov r7, a
Well, there's that step done.
2. Or with 0x01. Hm, where'd I leave that temporary. That's right, R7. I can't OR directly in a register, so I'll have to use the accumulator and put it back when I'm done. Grumble, grumble, stupid 8051 architecture, grumble.
mov a, r7 orl a, #1 mov r7, a
3. It was an |=, so I've got to save the temp back to allocated storage. That's in xdata. That means I have to use the DTPR and go through the accumulator. Grumble, grumble, stupid 8051 architecture, grumble.
mov dptr, #XRAM00 mov a, r7 movx @dptr, a
Finally, all done.
In short, it's exactly how most code geneators for most compilers work. Compilers have optimizers not because they have brilliant insight into the problem and can magically make the code smaller. (That's your job.) Compilers have optimizers because basic code generation is generally very focussed, even short-sighted. And it turns out it's a lot easier to generate code that's correct, if inefficient, and then optimize away inefficiency than it is to try to write a code generator that is smarter in the first place. It's a form of modularity; the code generator is responsible for semantics, the optimizer for getting rid of the silliness that occurs when you don't pay global attention to that sort of thing.
Thanks, Drew. Although I don't LIKE your answer (grumble, grumble), it makes perfect sense. Now, can I convince the optimizer to clean up this mess???
I have no idea whatsoever what problem (besides a personal one) you have with either of the two expressions above.
If you really cannot see the problem with using incorrect terminology, take a look at this thread for an example of how a whole lot of people's time is wasted dealing with someone who obstinately refuses to use the correct terminology:
http://www.keil.com/forum/docs/thread11754.asp
well, since I know of no terninology that will satisfy you I have to resort to examples. I am kind of uzzled what your problem is, many (e.g. Per) have undeerstood.
if you have a function that ends like that void a (void) { w x y z } and another function that end like this void b (void) { p x y z
the optimixer will, if you are more intersted in optimization than debuggability and select an optimization level reflecting that philosophy merge execution strings like this:
void a (void) { w optimal: x y z } void b (void) { p goto optimal
if x,y,z is too much for a sardines brain I give up, this will be my final att6epmt to make you understand what the common phrase "merging execution strings" mean
Erik
I realize a miss above
no, I am not 'uzzled', I am 'puzzled'
this will be my final att6epmt to make you understand what the common phrase "merging execution strings" mean
See my reply to you in this thread:
http://www.keil.com/forum/docs/thread11754.asp#msg57841
and, as shown there, prove that what you say is just as much 'picking apart' nonesense as the reast of your utterings.
BTW I hope that bending it in neon with an example made it penetrate the fog in your brain.
Any chance you two would consider taking this discussion to another place? My original question has been answered to my satisfaction.
but I can't leave the public insults from the smoked sardine unsanswered.
once he decides one of two a) to stop insulting me or b) come clean and not hide behing his mothers skirt as in using a pseudonym and thus made it possible to "take this discussion to another place" I'll gladly do so.
so, it is up to him.
This discussion isn't just held in this thread. There are a number of older threads drenched in similar posts.
"but I can't leave the public insults from the smoked sardine unsanswered."
Of course you can!
He only keeps winding you up because you keep reacting.
If you just ignored him, he'd go away!
Actually, you can. Or you can settle for answering: "As you wish" or "Whatever you say".
I only correct your mistakes. If you find that insulting I suggest you either stop posting or pick up some documentation and educate yourself.
If someone who should know better posts rubbish I will point it out. If you feel that my comments are inaccurate or unfair please feel free to criticise.
well, since I know of no terninology that will satisfy you I have to resort to examples.
Ok, if you don't know what the correct terminology is why don't you find out? Clue: try the Keil website.
crawl back in the can
View all questions in Keil forum