We are running a survey to help us improve the experience for all of our members. If you see the survey appear, please take the time to tell us about your experience if you can.
In one of my project I am talking with MX909 Driver IC with C51 ucontroller. To initialize MX909 if I write module in Assembly language it's working fine. Once I replaced with C same module it's not working.
The only difference I can make for both assembly and C languages is NOP and _nop_() instruction. Is both instructions will take same number of machine cycles?
Thanks, Suresh Kumar Kavula
The compiler may implement a for loop by using a djnz.
And here's proof that a for loop is not the same as a djnz loop:
line level source 1 int main(void) 2 { 3 1 unsigned char loop; 4 1 5 1 for(loop = 0; loop != 128; loop++) 6 1 { 7 2 } 8 1 while(1); 9 1 return(0); 10 1 } C51 COMPILER V8.02 MAIN 08/15/2007 13:01:31 PAGE 2 ASSEMBLY LISTING OF GENERATED OBJECT CODE ; FUNCTION main (BEGIN) ; SOURCE LINE # 1 ; SOURCE LINE # 2 ; SOURCE LINE # 5 ;---- Variable 'loop' assigned to Register 'R7' ---- 0000 E4 CLR A 0001 FF MOV R7,A 0002 ?C0001: ; SOURCE LINE # 6 ; SOURCE LINE # 7 0002 0F INC R7 0003 BF80FC CJNE R7,#080H,?C0001 0006 ?C0004: ; SOURCE LINE # 8 0006 80FE SJMP ?C0004 ; FUNCTION main (END)
And another one:
line level source 1 int main(void) 2 { 3 1 unsigned char loop; 4 1 5 1 for(loop = 128; loop-- != 0; ) 6 1 { 7 2 } 8 1 while(1); 9 1 return(0); 10 1 } C51 COMPILER V8.02 MAIN 08/15/2007 13:03:32 PAGE 2 ASSEMBLY LISTING OF GENERATED OBJECT CODE ; FUNCTION main (BEGIN) ; SOURCE LINE # 1 ; SOURCE LINE # 2 ; SOURCE LINE # 5 ;---- Variable 'loop' assigned to Register 'R7' ---- 0000 7F80 MOV R7,#080H 0002 ?C0001: 0002 AE07 MOV R6,AR7 0004 1F DEC R7 0005 EE MOV A,R6 0006 70FA JNZ ?C0001 ; SOURCE LINE # 6 ; SOURCE LINE # 7 0008 ?C0003: ; SOURCE LINE # 8 0008 80FE SJMP ?C0003 ; FUNCTION main (END)
If you know the compiler and the right syntax, it is possible to get a djnz when using a for loop. There is no guarantee.
If you know the compiler and the right syntax, it is possible to get a djnz when using a for loop.
And THAT is the point!
Knowledge of what is possible and the means to achieve it along with the ability to explain things without sounding like an obnoxious teacher is the sign of a true authoritative poster.
Lots of complaints and arguments.
I read the comment
My guess is that you suffer from some fallacy that e.g. a for loop is the same as a djnz loop and nothing could be farther from the truth.
as
Don't think that a for loop is equivalent with a djnz loop.
Any people who read it as:
The compiler will never make use of a djnz in a for loop.
should maybe be a bit more careful about complaining, since Erik did not claim any such foolish thing.
and then you can HOPE (a very useful approach to design) that it will still be a djnz loop in the next release of the compiler.
Erik
re my post that caused so much reaction: assuming a for loop is the same as a djnz loop and nothing could be farther from the truth.
where doues 'is' mean 'can not be' ?
... you can HOPE (a very useful approach to design)
An example of dry wit or the approach you follow?
If you have to ask you have not read many of my posts
maybe be a bit more careful about complaining, since Erik did not claim any such foolish thing.
Maybe, if he'd been a little more correct with his punctuation, people might have been able to understand it more easily.
Hope he doesn't write his code in the same manner.
Ermmmm ... It was a rhetorical question.
I've read quite a few of your posts; and the responses they trigger!
Very entertaining ;)
Nowhere.
Your original statement:
Modified as you suggest:
My guess is that you suffer from some fallacy that e.g. a for loop can not be the same as a djnz loop and nothing could be farther from the truth.
Yes, that seems correct now.
"a for loop is the same as a djnz loop"
That is, indeed, a fallacy and very far from the truth!
It's equivalent to saying something like, "a quadruped is the same as a cat"
...by saying "nothing could be further from the truth"
But that, too, is a common rhetorical device...
wlee Mr. smoked sardine, as usual you put words in my mouth that I would never use.
if you want6 a different then here it is My guess is that you suffer from some fallacy that e.g. a for loop always is the same as a djnz loop and nothing could be farther from the truth.
Seemed fine to me originally
thanks, Andy
while there can be some that do not like my choice of words, I stand by the statement.
See my response to Mr. smoked sardine where I have added a superflous word to satify him .... naah that would not be possible, but maybe someone else will understand better.
My guess is that you suffer from some fallacy that e.g. a for loop always is the same as a djnz loop and nothing could be farther from the truth.
The crazy thing about all of this is that it was a dumb-cluck thing to say in the first place - Not necessary, not helpful, of no real relevance and demeaning.
Why not just politely re-emphasize to the OP that assembler for such a task would be the better/best option.
And who says that the OP will not feel demeaned if their decision to use C is questioned in any way ?
Some past discussions went exactly this way.
That is probably true - But to go in at such an early stage with a statement such as "...you suffer from some fallacy..." is a sure fire way of belittling most people. And has been seen, causes a lot of negative reaction!
Gentle persuasion generally works better; not the "I've got experience, I know best, any other way is stupid" attitude that seems so prevalent in most responses by the poster in question.
But also, if the OP wants to use C and/or has good reason to do it that way, then surely this forum should be capable of understanding the need and provide advice to help him achieve his goal.