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.
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 '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:
j=sum>>8;
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?