Monday, May 30, 2016

8051 Program - convert 12bit binary to bcd

; Description:
; Convert Value In Acc From Hex To BCD.
;
; Entry Requirements:
; Acc Has Value To Convert To BCD
;
; On Exit:
; DPTR Has Value Of Acc In BCD
;
; Affected:
; PSW.CY, PSW.Z, PSW.P, Acc, DPTR
;
; Stack:
; 2 Bytes, Not Including Space Used By Called Routines
;
; Comments:
; Values Greater Than 255 Will Not Work Properly. If Acc == 12, DPTR
; == 0012. If Acc = 255, DPTR = 0255.
;
UTIL_BINTOBCD12:
push b ; Save B
push acc ; Save Acc
mov b,#100 ; Divide By 100
div ab ; Do Divide
mov dph,a ; Store In DPH
pop acc ; Recover Acc
mov b,#10 ; Divide By 10
div ab ; Do Divide
swap a ; Move Result To High Of A
orl a,b ; OR In Remainder
mov dpl,a ; Move To DPL
pop b ; Recover B
ret ; Return To Caller


Source: Assorted Utilities, John C. Wren 11/23/96



Related topics:
8051 Program - convert 8bit binary to bcd   |   8051 Program - convert dptr to signed string   |   8051 Program - convert dptr to unsigned string   |   8051 Program - memory subroutines   |   8051 Program - math subroutines   |   8051 Program - conversion subroutines

List of topics: 8051

No comments:

Post a Comment