Hi all I write a sample code like a = 1 << b; when b = 0 , The result for a will get 2 If I uncheck "Enable ANSI integer promotion rules " ,It will get correct answer 1 can anyone tell me why ?? Thanks a lot
Hi Noone know this ?? why a = 1 << b when b = 0 , a is not always equal 1 why??
"Noone know this ??" I don't think anyone is convinced that b=0. Try compiling a simple test case in isolation, if it gives the correct result take another look at 'b' to see whether it is actually 1.
The section of your code that does the shifting is this bit:
0024 7401 MOV A,#01H 0026 A807 MOV R0,AR7 0028 08 INC R0 0029 8002 SJMP ?C0181 002B ?C0180: 002B C3 CLR C 002C 33 RLC A 002D ?C0181: 002D D8FC DJNZ R0,?C0180 002F FF MOV R7,A
Thanks for replay I have a ready to this ,Please see it #define ENABLE 1 uchar volatile xdata *ptr_reg=0x8000; bug0 =0; bug1 =0; uchar b = pre_reg[0]; a = (ENABLE << b); if ( b != 0 ) bug0++; if ( a != 1 ) bug1++; after I run this ,bug0 is zero ,but bug1 is nonzero. I also have run this code in VC60,and it work fine. Thanks for your kind help
Thank to Graham I also think the asm code is fine, but I realy got a wrong answer >< maybe I have setting something wrong。 For now,I just use switch-case to do this sample work.
uchar volatile xdata *ptr_reg=0x8000; bug0 =0; bug1 =0; uchar b = pre_reg[0];
Thanks for correct my type error^^""" Sorry,I have already delete the code so i just type it again. It is ptr_reg not pre_reg。 Thanks a lot
Do you call the function from an interrupt service routine. The code that you have posted works correct for registerbank 0, but will fail if you call it from an interrupt service routine that uses a different register bank. See also: http://www.keil.com/support/docs/2201.htm Reinhard