Menu

#188 acc = (acc>>1) & 0x7f

open
nobody
None
5
2006-12-15
2006-12-15
No

/*
this feature request was triggered by some rudimentary
compiler comparison on (sorry, german only)
http://www.mikrocontroller.net/articles/AVR_PIC_51-Vergleich
(the comparison does explicitly denote itself as
not representative, and just uses one slightly broken
code snippet so please keep expectations low)

The http page listed above currently comes out on top
of Google's search results for "8051 C Compiler" when
googling from germany. Just for the record:
www.wickenhaeuser.de comes ranks second, SDCC ranks third.
*/

unsigned char acc_uc;
signed char acc_sc;

int foo(void)
{
acc_uc = (acc_uc>>1) & 0x7f; // masking redundant for unsigned
acc_sc = (acc_sc>>1) & 0x7f; // equivalent to the logic shift below

acc_sc = (unsigned char)acc_sc>>1;

// Maybe tracking the state of the individual bits of variables
// is also attractive, so two of the operations below could be
// detected as redundant?

acc_uc |= 0x07;
acc_uc |= 0x03; // redundant (both lowermost bits already set)
acc_sc &= 0x3f; // redundant (both uppermost bits already zero)

return acc_uc | acc_sc;
}

Discussion


Log in to post a comment.