Email: Password: Remember Me | Create Account (Free)

Back to Subject List

Old thread has been locked -- no new posts accepted in this thread
???
04/02/08 17:06
Read: times


 
#152896 - use a C-compiler and r = (r15);
Responding to: ???'s previous message
Let a C-compiler (using sdcc here) do the work for you:
unsigned int r;

void f()
{
    r = (r<<1) | (r>>15);
}

void g()
{
    r = (r<<15) | (r>>1);
}
generates this code with "sdcc -c rotate16.c":

   0000           101 _f:
                  110 ;	rotate16.c:5: r = (r<<1) | (r>>15);
   0000 E5*00     111 	mov	a,_r
   0002 33        112 	rlc	a
   0003 C5*01     113 	xch	a,(_r + 1)
   0005 33        114 	rlc	a
   0006 C5*01     115 	xch	a,(_r + 1)
   0008 92 E0     116 	mov	acc.0,c
   000A F5*00     117 	mov	_r,a
   000C 22        118 	ret
                  119 ;-------------------------------------
   000D           127 _g:
                  128 ;	rotate16.c:10: r = (r<<15) | (r>>1);
   000D E5*01     129 	mov	a,(_r + 1)
   000F 13        130 	rrc	a
   0010 C5*00     131 	xch	a,_r
   0012 13        132 	rrc	a
   0013 C5*00     133 	xch	a,_r
   0015 92 E7     134 	mov	acc.7,c
   0017 F5*01     135 	mov	(_r + 1),a
   0019 22        136 	ret


List of 4 messages in thread
TopicAuthorDate
rotating a sixteen bit value            01/01/70 00:00      
   have you read about the entire instruction set?            01/01/70 00:00      
   Q: How can you eat a whole whale?            01/01/70 00:00      
   use a C-compiler and r = (r<<1) | (r>>15);            01/01/70 00:00      

Back to Subject List