Please note: We are aware of an issue affecting replies on the Arm Community forums, which may not be loading as expected.

We apologize for any inconvenience and appreciate your patience while we investigate and work to resolve the issue.

Thank you for your understanding.


This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

working with right shift operators in C

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?

Parents
  • 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?

Reply
  • 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?

Children
No data