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

Back to Subject List

Old thread has been locked -- no new posts accepted in this thread
???
04/07/03 08:59
Read: times


 
#43005 - RE: how to swap the bit,,,Menno
Responding to: ???'s previous message
Menno:
I took your small C program example and plugged it into my Keil C compiler and told it to compile it to assembler language. I show the result of this below. Now while I agree that this solution may be suitable for situations where speed is of no importance it is hardly a small routine. For size of code space minimization one would be far better off looking at plugging in an assembly language routine like any one of the three shown at the Peters Link.

If space is not an issue and you want to with C code then use the look up table like I showed before. It will be fast and only a few bytes longer than the first of Peter's assembly language ideas.

Menno's Expanded C code byte flipper...
; testc.SRC generated from: testc.c
; COMPILER INVOKED BY:
;        C:KeilC51BINC51.EXE testc.c BROWSE DEBUG OBJECTEXTEND


NAME	TESTC

?PR?_FlipBits?TESTC  SEGMENT CODE 
	PUBLIC	_FlipBits
; #pragma SRC
; 
; unsigned char FlipBits(unsigned char InVal) 

	RSEG  ?PR?_FlipBits?TESTC
_FlipBits:
	USING	0
			; SOURCE LINE # 3
;---- Variable 'InVal?040' assigned to Register 'R7' ----
; { 
			; SOURCE LINE # 4
; 	unsigned char BitMask1=0x01; 
			; SOURCE LINE # 5
;---- Variable 'BitMask1?041' assigned to Register 'R6' ----
	MOV  	R6,#01H
; 	unsigned char BitMask2=0x80; 
			; SOURCE LINE # 6
;---- Variable 'BitMask2?042' assigned to Register 'R5' ----
	MOV  	R5,#080H
; 	unsigned char Result=0; 
			; SOURCE LINE # 7
;---- Variable 'Result?043' assigned to Register 'R4' ----
	CLR  	A
	MOV  	R4,A
?C0001:
; 
; 	while(BitMask2>=1) 
			; SOURCE LINE # 9
	MOV  	A,R5
	CLR  	C
	SUBB 	A,#01H
	JC   	?C0002
; 	{ 
			; SOURCE LINE # 10
; 		Result+=(((InVal&BitMask1)>0)*BitMask2); 
			; SOURCE LINE # 11
	MOV  	A,R7
	ANL  	A,R6
	SETB 	C
	SUBB 	A,#00H
	JC   	?C0003
	MOV  	R3,#01H
	SJMP 	?C0004
?C0003:
	MOV  	R3,#00H
?C0004:
	MOV  	A,R3
	MOV  	B,R5
	MUL  	AB
	ADD  	A,R4
	MOV  	R4,A
; 		BitMask1<<=1; 
			; SOURCE LINE # 12
	MOV  	A,R6
	ADD  	A,ACC
	MOV  	R6,A
; 		BitMask2>>=1; 
			; SOURCE LINE # 13
	MOV  	A,R5
	CLR  	C
	RRC  	A
	MOV  	R5,A
; 	} 
			; SOURCE LINE # 14
	SJMP 	?C0001
?C0002:
; 	return(Result); 
			; SOURCE LINE # 15
	MOV  	R7,AR4
; } 
			; SOURCE LINE # 16
?C0005:
	RET  	
; END OF _FlipBits

	END


Michael Karas


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