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

Back to Subject List

Old thread has been locked -- no new posts accepted in this thread
???
04/09/03 09:18
Read: times


 
#43111 - RE: how to swap the bit in C
Responding to: ???'s previous message
Michael,

I do agree that swapping bits in C is less econimical than doing it in assembly; the code I presented was not intended to be as economical as possible, it was merely intended as to demonstrate how it could be done using less RAM memory. Using a look-up table may not always be possible, especially in the smaller controllers.

Here's a somewhat more economical piece of code in assembly (16 bytes):
;R0 holds the byte to be manipulated.
;Result is returned in R1

swap_bits:	mov	R2,#9
nxt_shift:	djnz	R2,shift
		jmp	end_shift
shift:		mov	A,R0
		rrc	A
		mov	R0,A
		mov	A,R1
		rlc	A
		mov	R1,A
		jmp	nxt_shift
end_shift:      ret



List of 24 messages in thread
TopicAuthorDate
how to swap the bit,,,urgent            01/01/70 00:00      
   RE: how to swap the bit,,,urgent            01/01/70 00:00      
      RE:8051 how to swap the bit,,,urgent            01/01/70 00:00      
         RE: RE:8051 how to swap the bit,,,urgent            01/01/70 00:00      
         RE: 8051 how to swap the bits...            01/01/70 00:00      
            RE: 8051 how to swap the bits...            01/01/70 00:00      
   RE: how to swap the bit,,,urgent            01/01/70 00:00      
      RE: how to swap the bit,,,urgent            01/01/70 00:00      
         RE: how to swap the bit,,,urgent - Hans            01/01/70 00:00      
            RE: how to swap the bit,,,urgent - Hans            01/01/70 00:00      
               RE: how to swap the bit,,,urgent - Hans            01/01/70 00:00      
                  RE: how to swap the bit,,,urgent - Hans            01/01/70 00:00      
   RE: how to swap the bit,,,urgent            01/01/70 00:00      
      RE: how to swap the bit,,,Menno            01/01/70 00:00      
         RE: how to swap the bit,,,Michael            01/01/70 00:00      
         RE: how to swap the bit in C            01/01/70 00:00      
            RE: how to swap the bit in C            01/01/70 00:00      
   RE: how to swap the bit if 64 bits            01/01/70 00:00      
      RE: how to swap the bit if 64 bits            01/01/70 00:00      
         RE: how to swap the bit if 64 bits            01/01/70 00:00      
         RE: how to swap the bit if 64 bits            01/01/70 00:00      
   RE: how to swap the bit,,,urgent            01/01/70 00:00      
      RE: how to swap the bit,,,/...Vivek            01/01/70 00:00      
      RE: how to swap the bit,,,urgent            01/01/70 00:00      

Back to Subject List