Renesas Technology, Tools FAQs
Last Updated: March 21, 2000
Document Number: 01051276_e
Q.
In the example program, why does the right side of the equation [aaa = (signed long)( BBB << CCC );] become 0x0000f000? When
I use VISUAL C++, it becomes 0x0ffff000.
Example program Compiled assembly code
#define BBB (unsigned short)0xffff
#define CCC (unsigned char)12
signed long aaa;
test( void )
{
aaa = (signed long)( BBB << CCC );
}
_test:
mov.w #0f000H,_aaa
mov.w #00000H,_aaa+2
rts
A.
The compiler processes the equation in the following order:
Convert BBB to int type
(If the original can be expressed in int, signed type int is used.)
(If the original can not be expressed in int, unsigned int (or bigger) is used.)
1.
Shift the intermediate data using CCC.2.
Convert the data to signed long type, then store the data to aaa.3.
However, NC30 handles an int type variable as 16-bit data. Therefore, NC30 processes the equation [aaa = (signed long)( BBB <<
CCC );] in the following ways:
0xffff -> 0xffff (the data can not be expressed with int type, so it is converted to unsigned int)1.
0xffff <<12 -> 0xf0002.
0xf000 is unsigned type. (signed long) cast processes the data to 0x0000f000 -> aaa3.
Therefore, the resulting value becomes 0x0000f000.
If you want to set the result as 0x0ffff000 by using NC30, you must cast variable BBB instead of casting the sifted result to long
type: aaa = (signed long)( BBB << CCC );.
#define BBB (unsigned short)0xffff
#define CCC (unsigned char)12
signed long aaa;
test( void )
{
aaa = (signed long)BBB<<CCC;
}
Compiled assembler codes for the above results are as follows:
;## # C_SRC : aaa = (signed long)BBB << CCC;
mov.w #0f000H,_aaa
mov.w #00fffH,_aaa+2
(For reference)
Comentários a estes Manuais