I am facing a problem in using the right shift operator in C with keil. The instruction is:for(i=0;i<=8;i++) { j=sum>>i; } where sum= 32 bit no. the instruction is not executed if the syntax is as shown above. but if i write a numerical value instead of using the variable name 'sum' then the instruction is easily executed. i need to use the variable name only. how do i fix this problem?
"the above instruction is not executed"
How have you confirmed that it is actually "not executed"?
Have you examined the generated code?
Have you stepped through it in the simulator?
yes i have confirmed that it is not executed. yes i have examined the generated code. i did single stepping and found that these instructions are not executed.
and i have done away with the for loop and instead just used:
j=sum>>8;
"yes i have examined the generated code."
And what did you observe?
"i did single stepping and found that these instructions are not executed."
Again, what did you observe?
This should tell you why they weren't executed!
"i have done away with the for loop and instead just used..."
Again, you still haven't explained why you wanted the for loop in the first place!
The 'for' loop is to right shift the contents of the variable 'sum'. 'sum' holds my 16 bit result. now i want to move this result in two 8 bits registers of the microcontroller. for that moving the lsb 8 bits of the result is simple. but the msb 8 bits have to be brought to the lsb position first to move it into an 8 bit reg. hence i used the for loop. but now as per your advice i have done away with the for loop and simply used:
But still the instruction is not executed. is there any other alternate way of moving the 16 bit result in 'sum' to the registers of the microcontroller?