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

Back to Subject List

Old thread has been locked -- no new posts accepted in this thread
???
01/23/04 09:43
Read: times


 
#63185 - RE: 24bit Hex to decimal
Responding to: ???'s previous message
Hi,

See if this helps...

; Description: binary to bcd conversion for 24 bit binary. Only lower 6
; digits are produced in this routine

; Modification history:


; -----------------------------------------------------------
; convert 24-bit binary to 6 digit BCD
; input: r5,r6,r7 - low byte, mid, high byte
; output: r4,r3,r2 - packed bcd r4 is MSD, r2 is LSD
; ____________________________________________________
; | R4 H nib| R4 L nib| r3 H | r3 L | r2 H | r2 L |
; |_______d5_______d4___|__d3_____d2__|__d1____d0______|
;
; same logic as used in '85 except for inputs / outputs

bin24bcd:
mov r1,#19h ;set bit counter to 25decimal
call cnvt1_24 ;produce 2 ls bcd digits in r5
mov r2,r4 ;save in r2

mov r1,#19h
call cnvt1_24 ;produce next 2 digits
mov r3,r4 ;save in r3

mov r1,#19h
call cnvt1_24 ;last 2 more digits
ret ;the msd's in r4

cnvt1_24:
mov r4,#00 ;set r4 to 0, to hold the present BCD
cnvt2_24:
clr a
clr c
djnz r1,cnvt3_24 ;done, return if 0
ret

cnvt3_24:
mov a,r5 ;shift r7,r6,r5 left 1 bit msb to cy
rlc a
mov r5,a
mov a,r6
rlc a ;add only the carry
mov r6,a
mov a, r7
rlc a
mov r7,a
mov a,r4 ;mov bcd digit into a
addc a,r4 ;double a and add carry from r7
da a ;maintain bcd format
mov r4,a ;save in r4
jnc cnvt2_24 ;no carry from daa continue
clr a ;clear acc keep carry
addc a,r5 ;if carry add back to r5
mov r5,a ;restore r5
clr a ;clear acc keep carry
addc a,r6 ;propagate carry to r6
mov r6,a ;restore r6
clr a
addc a,r7
mov r7,a
jmp cnvt2_24

; - end of special edition of bin to bcd

Rgds
Raj Shetgar

List of 21 messages in thread
TopicAuthorDate
24bit Hex to decimal            01/01/70 00:00      
   RE: 24bit Hex to decimal            01/01/70 00:00      
   RE: 24bit Hex to decimal            01/01/70 00:00      
      RE: 24bit Hex to decimal            01/01/70 00:00      
         RE: 24bit Hex to decimal            01/01/70 00:00      
      RE: 24bit Hex to decimal            01/01/70 00:00      
         RE: 24bit Hex to decimal            01/01/70 00:00      
            RE: 24bit Hex to decimal            01/01/70 00:00      
   RE: 24bit Hex to decimal            01/01/70 00:00      
      RE: 24bit Hex to decimal            01/01/70 00:00      
      RE: 24bit Hex to decimal            01/01/70 00:00      
         RE: 24bit Hex to decimal            01/01/70 00:00      
   RE: 24bit Hex to decimal            01/01/70 00:00      
   RE: 24bit Hex to decimal            01/01/70 00:00      
   RE: 24bit Hex to decimal            01/01/70 00:00      

Back to Subject List