#396 Direct Byte Code Optimization

open
nobody
None
5
2013-08-07
2013-08-07
bangor077
No

The following line of C code...
P0 &= ~(1<<2 | 1<<3);
generates the following assembly:
mov r6,_P0
mov a,#0xF3
anl a,r6
mov _P0,a

The following line of C code...
P0 &= (int) ~(1<<2 | 1<<3);
generates the following assembly:
mov r5,_P0
anl ar5,#0xF3
mov _P0,r5

The following line of C code...
P0 &= (unsigned int) ~(1<<2 | 1<<3);
generates the following assembly:
mov r5,_P0
anl ar5,#0xF3
mov _P0,r5

The following line of C code...
P0 &= (char) ~(1<<2 | 1<<3);
generates the following assembly:
mov r6,_P0
mov a,#0xF3
anl a,r6
mov _P0,a

The following line of C code...
P0 &= (unsigned char) ~(1<<2 | 1<<3);
generates the following assembly:
anl _P0,#0xF3

I understand the casting rules, however, I don't understand why char and int casts are being treated differently when assembled (I think I understand the r5 vs. r6, but really confused why casting as a char requires used of the ACC). For optimal optimization I would obviously prefer the last option to be the default result, which is not the normal cast order for C, but feel that direct bytes should either be CAST as unsigned char in the preprocessor or in the assembler optimizations.

Discussion


Log in to post a comment.

Get latest updates about Open Source Projects, Conferences and News.

Sign up for the SourceForge newsletter:





No, thanks