Convering 2 Bytes of binary to BCD
CASTalk.com Forum Index CASTalk.com
Discussion of DSP, FPGA, storage and embedded system.
 
 FAQFAQ   MemberlistMemberlist     RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 
 
Google
 
Web castalk.com
Convering 2 Bytes of binary to BCD

 
Post new topic   Reply to topic    CASTalk.com Forum Index -> Computer Architecture
Author Message
CTG
Guest





Posted: Tue Mar 01, 2005 5:36 am    Post subject: Convering 2 Bytes of binary to BCD Reply with quote

I have a value (in BC -2 bytes) and need to convert that to its BCD form
Has anyone got any piece of code to get this done ?

Thanks
Back to top
toby
Guest





Posted: Tue Mar 01, 2005 7:56 am    Post subject: Re: Convering 2 Bytes of binary to BCD Reply with quote

CTG wrote:
Quote:
I have a value (in BC -2 bytes) and need to convert that to its BCD
form
Has anyone got any piece of code to get this done ?

Here's one interesting discussion
http://cbfalconer.home.att.net/download/dubldabl.txt

Quote:

Thanks
Back to top
glen herrmannsfeldt
Guest





Posted: Wed Mar 02, 2005 7:55 am    Post subject: Re: Convering 2 Bytes of binary to BCD Reply with quote

CTG wrote:

Quote:
I have a value (in BC -2 bytes) and need to convert that to its BCD form
Has anyone got any piece of code to get this done ?

Is this on an 8080?

-- glen
Back to top
Charles Krug
Guest





Posted: Wed Mar 02, 2005 8:57 pm    Post subject: Re: Convering 2 Bytes of binary to BCD Reply with quote

On Tue, 01 Mar 2005 21:20:32 -0800, glen herrmannsfeldt
<gah@ugcs.caltech.edu> wrote:
Quote:
CTG wrote:

I have a value (in BC -2 bytes) and need to convert that to its BCD form
Has anyone got any piece of code to get this done ?

Is this on an 8080?


Careful. The answer is subtly different if he really has a Z-80
instead of an actual 8080.

You can also find the book "Logic and Computer Design Fundamentals"
helpful.
Back to top
George Neuner
Guest





Posted: Thu Mar 03, 2005 3:30 am    Post subject: Re: Convering 2 Bytes of binary to BCD Reply with quote

On Wed, 02 Mar 2005 15:57:28 GMT, Charles Krug
<cdkrug@worldnet.att.net> wrote:

Quote:
On Tue, 01 Mar 2005 21:20:32 -0800, glen herrmannsfeldt
gah@ugcs.caltech.edu> wrote:
CTG wrote:

I have a value (in BC -2 bytes) and need to convert that to its BCD form
Has anyone got any piece of code to get this done ?

Is this on an 8080?

Careful. The answer is subtly different if he really has a Z-80
instead of an actual 8080.

And really different if he has a 6500, 6800 or 68000.

George
--
for email reply remove "/" from address
Back to top
toby
Guest





Posted: Thu Mar 03, 2005 7:57 am    Post subject: Re: Convering 2 Bytes of binary to BCD Reply with quote

George Neuner wrote:
Quote:
On Wed, 02 Mar 2005 15:57:28 GMT, Charles Krug
cdkrug@worldnet.att.net> wrote:

On Tue, 01 Mar 2005 21:20:32 -0800, glen herrmannsfeldt
gah@ugcs.caltech.edu> wrote:
CTG wrote:

I have a value (in BC -2 bytes) and need to convert that to its
BCD form
Has anyone got any piece of code to get this done ?

Is this on an 8080?

Careful. The answer is subtly different if he really has a Z-80
instead of an actual 8080.

And really different if he has a 6500, 6800 or 68000.

Not if written in C :-)

Quote:

George
--
for email reply remove "/" from address
Back to top
George Neuner
Guest





Posted: Fri Mar 04, 2005 7:56 am    Post subject: Re: Convering 2 Bytes of binary to BCD Reply with quote

On 2 Mar 2005 18:59:51 -0800, "toby" <toby@telegraphics.com.au> wrote:

Quote:
Not if written in C :-)

Touche`.

George
--
for email reply remove "/" from address
Back to top
del cecchi
Guest





Posted: Sat Mar 05, 2005 7:34 am    Post subject: Re: Convering 2 Bytes of binary to BCD Reply with quote

"George Neuner" <gneuner2/@comcast.net> wrote in message
news:0stf21pt6fv1f9239hbic6u0ssh2ugp4pl@4ax.com...
Quote:
On 2 Mar 2005 18:59:51 -0800, "toby" <toby@telegraphics.com.au> wrote:

Not if written in C :-)

Touche`.

George
--
for email reply remove "/" from address

Doesn't System/360, 370,......z have a convert to decimal/packed decimal
opcode?
Back to top
Guest






Posted: Sun Mar 06, 2005 3:44 am    Post subject: Re: Convering 2 Bytes of binary to BCD Reply with quote

del cecchi wrote:
Quote:
Doesn't System/360, 370,......z have a convert to decimal/packed
decimal
opcode?

convert to binary
http://publibz.boulder.ibm.com/cgi-bin/bookmgr_OS390/BOOKS/DZ9AR004/7.5.32?SHELF=EZ2HW125&DT=19970613131822

convert to decimal
http://publibz.boulder.ibm.com/cgi-bin/bookmgr_OS390/BOOKS/DZ9AR004/7.5.33?SHELF=EZ2HW125&DT=19970613131822

pack
http://publibz.boulder.ibm.com/cgi-bin/bookmgr_OS390/BOOKS/DZ9AR004/7.5.68?SHELF=EZ2HW125&DT=19970613131822

unpack
http://publibz.boulder.ibm.com/cgi-bin/bookmgr_OS390/BOOKS/DZ9AR004/7.5.98?SHELF=EZ2HW125&DT=19970613131822

also, possibly of some interest

edit
http://publibz.boulder.ibm.com/cgi-bin/bookmgr_OS390/BOOKS/DZ9AR004/8.3.4?SHELF=EZ2HW125&DT=19970613131822


edit and mark
http://publibz.boulder.ibm.com/cgi-bin/bookmgr_OS390/BOOKS/DZ9AR004/8.3.5?SHELF=EZ2HW125&DT=19970613131822


example of edit and mark
http://publibz.boulder.ibm.com/cgi-bin/bookmgr_OS390/BOOKS/DZ9AR004/A.4.5?SHELF=EZ2HW125&DT=19970613131822&CASE=

partial extract (see above for additional explanation):

The EDIT AND MARK instruction may be used, in addition to the functions
of
EDIT, to insert a currency symbol, such as a dollar sign, at
the
appropriate position in the edited result. Assume the same source
in
storage locations 1200-1203, the same pattern in locations 1000-100C,
and
the same contents of general register 12 as for the EDIT
instruction
above. The previous contents of general register 1 (GR1) are
not
significant; a LOAD ADDRESS instruction is used to set up the first
digit
position that is forced to print if no significant digits occur to
the
left.


Pattern
1000 100C
__ __ __ __ __ __ __ __ __ __ __ __ __
|40|5B|F2|6B|F5|F7|F4|4B|F2|F6|40|40|40|
|__|__|__|__|__|__|__|__|__|__|__|__|__|
b $ 2 , 5 7 4 . 2 6 b b b


This pattern field prints as:


$2,574.26

Condition code 2 is set to indicate that the number edited was greater
than zero.
Back to top
Norbert Juffa
Guest





Posted: Sun Mar 06, 2005 7:11 am    Post subject: Re: Convering 2 Bytes of binary to BCD Reply with quote

"CTG" <LONGLIVEIRAN@hotmail.coM> wrote in message news:4f67f35.0502281636.3b875e89@posting.google.com...
Quote:
I have a value (in BC -2 bytes) and need to convert that to its BCD form
Has anyone got any piece of code to get this done ?

Thanks

From the fact that you state that you have a 2-byte value in BC
I concluded that you may be using a Z80 or derivative processor.
If so, you may find the code below useful. It expects the input
in HL rather than BC, but that is easy enough to fix.

-- Norbert


;;--------------------------------------------------
;; Binary to BCD conversion
;;
;; Converts a 16-bit unsigned integer into a 6-digit
;; BCD number. 1181 Tcycles
;;
;; input: HL = unsigned integer to convert
;; output: C:HL = 6-digit BCD number
;; destroys: A,F,B,C,D,E,H,L
;;--------------------------------------------------
Bin2Bcd:
LD BC, 16*256+0 ; 16 bits, one bit per iteration
LD DE, 0
cvtLoop:
ADD HL, HL
LD A, E
ADC A, A
DAA
LD E, A
LD A, D
ADC A, A
DAA
LD D, A
LD A, C
ADC A, A
DAA
LD C, A
DJNZ cvtLoop
EX HL, DE
RET
Back to top
toby
Guest





Posted: Sun Mar 06, 2005 8:55 pm    Post subject: Re: Convering 2 Bytes of binary to BCD Reply with quote

del cecchi wrote:
Quote:
"George Neuner" <gneuner2/@comcast.net> wrote in message
news:0stf21pt6fv1f9239hbic6u0ssh2ugp4pl@4ax.com...
On 2 Mar 2005 18:59:51 -0800, "toby" <toby@telegraphics.com.au
wrote:

Not if written in C :-)

Touche`.

George
--
for email reply remove "/" from address

Doesn't System/360, 370,......z have a convert to decimal/packed
decimal
opcode?

As does VAX IIRC.
Back to top
 
Post new topic   Reply to topic    CASTalk.com Forum Index -> Computer Architecture All times are GMT
Page 1 of 1

 
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum




VoIP Electronics Powered by phpBB