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

Back to Subject List

Old thread has been locked -- no new posts accepted in this thread
???
03/13/02 16:48
Read: times


 
#20802 - RE: 16 bit shift left
Given a value between 0 and 15 (decimal) in the accumulator and given that you want to set one of the 16 bits contained in IRAM 20h and 21h (bits 00-0Fh) you could use the following code:

MOV R0,#20h ;IRAM address that contains the bit
CJNE A,#08h,$+3 ;Is A < 08h?
JC SKIP ;If A < 08h, jump to SKIP
INC R0 ;A >= 08h so we increment IRAM address to 21h
SKIP:
ANL A,#07h ;Only keep the 4 least-significant bits
MOV R1,A ;Move the new value (0-7) into R1 counter
MOV A,#80h ;Initialize accumulator to binary 10000000
LOOP:
RL A ;Rotate the accumulator left one bit (not through carry)
DJNZ R1,LOOP ;Loop 1-8 times depending on initial value of R1
ORL A,@R0 ;OR the result value and the current value of IRAM address
MOV @R0,A ;Store the final result in correct IRAM address

The above solution requires only 18 bytes, although Erik's solution is probably better from a speed-standpoint since it does a direct table-lookup and this solution executes a loop up to 8 times.

Craig Steiner


List of 16 messages in thread
TopicAuthorDate
16 bit shift left            01/01/70 00:00      
RE: 16 bit shift left            01/01/70 00:00      
RE: 16 bit shift left            01/01/70 00:00      
RE: 16 bit shift left            01/01/70 00:00      
RE: 16 bit shift left            01/01/70 00:00      
RE: 16 bit shift left            01/01/70 00:00      
RE: 16 bit shift left            01/01/70 00:00      
RE: 16 bit shift left            01/01/70 00:00      
RE: 16 bit shift left            01/01/70 00:00      
RE: 16 bit shift left            01/01/70 00:00      
RE: 16 bit shift left            01/01/70 00:00      
But why not the carry bit?            01/01/70 00:00      
RE:16 bit shift left            01/01/70 00:00      
RE: RE:16 bit shift left            01/01/70 00:00      
RE: RE:16 bit shift left            01/01/70 00:00      
RE: RE:16 bit shift left            01/01/70 00:00      

Back to Subject List