Reputation: 43
I don't understand why the C51 compiler (in Keil) convert C source to this assembly language code: (As p is a pointer to unsigned char)
; p++;
; SOURCE LINE # 216
MOV R3,pDisplay?253
INC pDisplay?253+02H
MOV A,pDisplay?253+02H
MOV R2,pDisplay?253+01H
JNZ ?C0090
INC pDisplay?253+01H
As R3
and R2
wasn't used in the next lines of the program.
Why do compiler make these linesMOV R3,pDisplay?253
,
MOV R2,pDisplay?253+01H
?
Upvotes: 3
Views: 136
Reputation: 4069
Welcome to 1980s "state of the art" code generation for 8-bit target processors. What the code is doing is "noting the value" of p before incrementing it. That's necessary when the postincrement operator is used in a surrounding expression; and not optimized away by subsequent passes of the compiler.
Try p += 1;
, or even ++p;
instead. Odds are that one or both of those will generate better code because there is no "note the value before" semantics to get in the code generator's way.
[This is how I got into the minority, by the way, using ++i
in for ()
loops rather than the more common i++
.]
Upvotes: 9