Solved

Convert BCD to Decimal

Posted on 1998-04-12
2
3,924 Views
Last Modified: 2008-02-01
Hi,
I'm having real problems converting a BCD number to decimal.  I want to do it using assembly coding.  I have tried shifting (shl,shr) the upper 4 and lower 4 bits right out of the number to deal with them on their own.  I found out shifting doesnt work like that (it just adds on a bunch of 0's where you shifted from and keeps the numbers I thought would shift right out of the register ( would be nice to have them dropped out ) ).  
If I have a BCD number in a register (16 or 8 bit) (ie. Get Real Time Clock returns hour in BCD to CH)  how can I properly change it to decimal?

Thanks in advance
0
Comment
Question by:bod_1
2 Comments
 
LVL 1

Accepted Solution

by:
Nexial earned 20 total points
ID: 1019045
Here's how I do it, for the clock:
(a minor snippet)

     DOSCALL @GETTME ; CH<-hours, CL<-minutes
     MOV     AL,CH           ;AL<-binary hours
     AAM                     ;Convert AL to two
     XCHG    AL,AH           ; BCD digits in AX.
     OR      HOUR,AX         ;Fold into hours
     MOV     AL,CL           ;AL<-binary minutes
     AAM                     ;Convert AL to two
     XCHG    AL,AH           ; BCD digits in AX.

0
 

Author Comment

by:bod_1
ID: 1019046
Nietod... you're amazing

I haven't got the snippet working yet but youve pointed me towards the right instructions.
Thanks
0

Featured Post

Get up to 2TB FREE CLOUD per backup license!

An exclusive Black Friday offer just for Expert Exchange audience! Buy any of our top-rated backup solutions & get up to 2TB free cloud per system! Perform local & cloud backup in the same step, and restore instantly—anytime, anywhere. Grab this deal now before it disappears!

Join & Write a Comment

Moving your enterprise fax infrastructure from in-house fax machines and servers to the cloud makes sense — from both an efficiency and productivity standpoint. But does migrating to a cloud fax solution mean you will no longer be able to send or re…
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…
Illustrator's Shape Builder tool will let you combine shapes visually and interactively. This video shows the Mac version, but the tool works the same way in Windows. To follow along with this video, you can draw your own shapes or download the file…

746 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now