We are running a survey to help us improve the experience for all of our members. If you see the survey appear, please take the time to tell us about your experience if you can.
Hi, The code is given below.
void CSToOut(void) { static unsigned char data bSimulate[8] ; int I; for( I = 0 ;I < 8;I ++) { bSimulate[I] = 0x01 << I ; ComOutChar( bSimulate[I] ); } }
result: 00 00 00 00 00 00 00 00
why?
I = 0 ; bSimulate[0] = 0x01 << I ; I = 1 ; bSimulate[1] = 0x01 << I; I = 2 ; bSimulate[2] = 0x01 << I; I = 3 ; bSimulate[3] = 0x01 << I; I = 4 ; bSimulate[4] = 0x01 << I; I = 5 ; bSimulate[5] = 0x01 << I; I = 6 ; bSimulate[6] = 0x01 << I; I = 7 ; bSimulate[7] = 0x01 << I; for( I = 0 ;I < 8;I ++) { // bSimulate[I] = 0x01 << I ; ComOutChar( bSimulate[I] ); }
result:01 02 04 08 10 20 40 80
I = 0 ; bSimulate[I] = 0x01 << I ; I = 1 ; bSimulate[I] = 0x01 << I; I = 2 ; bSimulate[I] = 0x01 << I; I = 3 ; bSimulate[I] = 0x01 << I; I = 4 ; bSimulate[I] = 0x01 << I; I = 5 ; bSimulate[I] = 0x01 << I; I = 6 ; bSimulate[I] = 0x01 << I; I = 7 ; bSimulate[I] = 0x01 << I; for( I = 0 ;I < 8;I ++) { // bSimulate[I] = 0x01 << I ; ComOutChar( bSimulate[I] ); }
result:00 00 00 00 00 00 00 00
unsigned char J; I = 0 ; J = 0 ; bSimulate[J] = 0x01 << I ; I = 1 ; J = 1 ; bSimulate[J] = 0x01 << I; I = 2 ; J = 2 ; bSimulate[J] = 0x01 << I; I = 3 ; bSimulate[I] = 0x01 << I; I = 4 ; bSimulate[I] = 0x01 << I; I = 5 ; bSimulate[I] = 0x01 << I; I = 6 ; bSimulate[I] = 0x01 << I; I = 7 ; bSimulate[I] = 0x01 << I; for( I = 0 ;I < 8;I ++) { // bSimulate[I] = 0x01 << I ; ComOutChar( bSimulate[I] ); }
result:80 80 80 00 00 00 00 00
tks
Why is bSimulate declared static?
What does the assembly that the compiler generates look like? I often find that looking at the assembly listing gives a lot of good information to help with debugging.