Home    Bloggers    Messages    Resources
Tw  |  Fb  |  In  |  Rss
Handling the Negatives of BCD
4/9/2012

< Previous   Image 2 of 6      Next >

Signed binary

< Previous   Image 2 of 6      Next >

Return to Article

Newest First   Oldest First   Threaded View
Rich Quinnell
Rich Quinnell
4/13/2012 3:23:31 PM
User Rank
Blogger
Re: Subtracting BCD
jackever, the 80x86 had a DAA instruction, and also a DAS (decimal add after subtract) instruction for correcting the result of a binary subtraction after a BCD subtract. So, I'm guessing the Motorola device didn't handle direct subtraction of BDC but required addition of the subtrahend's 10's complement. Wonder if that would come out right if the result were a negative number? 

50%
50%
jackever
jackever
4/13/2012 12:27:42 PM
User Rank
Bit twiddler
Re: Subtracting BCD
the Motorola..FS 68XX (X) 's had a DAA instruction. Do not remember if  it handled negatives.

50%
50%
prabhakar_deosthali
prabhakar_deosthali
4/13/2012 9:22:33 AM
User Rank
Program Manager
Re: Subtracting BCD - represent BCD using excess 3 format
Rich ,

Yes you cannot use the most significant bit as a sign bit.

But I am talking about a separate nibble for sign - This nibble can be the left most nibble in a BCD number ( i.e the 5th nibble if we have 4 digit number representation) and we have freedom to represent any two combinations form 0000 to 1111 to represent the + and - sign as long as we write the supporting library routines for BCD arithmetic.

 

I hope my cards are all open!

 

50%
50%
Max The Magnificent
Max The Magnificent
4/11/2012 1:23:13 PM
User Rank
Blogger
Re: Subtracting BCD - represent BCD using excess 3 format
I'm up to my ears in alligators fighting fires without a canoe at the moment (I never metaphor I didn't like :-)

All will be revealed in the fullness of time, grasshopper :-)

50%
50%
Rich Quinnell
Rich Quinnell
4/11/2012 1:19:21 PM
User Rank
Blogger
Re: Subtracting BCD - represent BCD using excess 3 format
Not fair! No teasing! Well, if you must play your cards so close to your chest, perhaps you can answer my question about negative numbers using the excess-3 BCD format. You can't simply assign the highest bit as a sign anymore, can you?

50%
50%
prabhakar_deosthali
prabhakar_deosthali
4/11/2012 7:41:03 AM
User Rank
Program Manager
Re: Subtracting BCD - represent BCD using excess 3 format
Rich, I am not sure but my guess is that like the standard way of representing BCD, we can have a special nibble to represent the sign of an excess 3 BCD number.

50%
50%
Rich Quinnell
Rich Quinnell
4/10/2012 12:58:54 PM
User Rank
Blogger
Re: Subtracting BCD - represent BCD using excess 3 format
Prabhakar, interesting approach this excess-three representation. How does it represent negative numbers?

50%
50%
Max The Magnificent
Max The Magnificent
4/10/2012 11:57:54 AM
User Rank
Blogger
Re: Subtracting BCD - represent BCD using excess 3 format
Very good -- not many people remember Excess 3 these days -- of course nothing is simple, for example ... but no, I think we'll leave that until my next blog on this topic :-)

50%
50%
prabhakar_deosthali
prabhakar_deosthali
4/10/2012 3:48:46 AM
User Rank
Program Manager
Re: Subtracting BCD - represent BCD using excess 3 format
As per my knowledge there are three different ways to represnt the BCD numbers as two nibbles of a byte.

 

The binary values of 0000 to 1111 can represent decimal numbers 0 to 15. But in BCD arithmatic we want the numbers only from 0 to 9. so there are 6 unused combinations .

 

A method to repersent digits 0 to 9 in a nibble is called excess 3 which is as follows

binary              decimal

0011                  0

0100                  1

0101                  2

0110                  3

0111                  4

1000                  5

1001                  6

1010                  7

1011                   8

1100                   9

 

With this represntation we can do the same trick as for binary to get a negative number - just xor the bits with all ones to get 9's compliement and add 1 to get the negatiove represenation of the number

 

for example  the decimal number 23 is represnted as 0101 0110 . by xoring with all ones we get 1010 1001 which is 76 and adding 1 we get 1010 1010  which is the decimal represntation of 77 i. e 10's complement of 23.

 

 

100%
0%
Rich Quinnell
Rich Quinnell
4/9/2012 3:24:10 PM
User Rank
Blogger
Subtracting BCD
Well, if we use the same reasoning as subtracting in binary, we form the 10's complement of the subtrahend and add. In binary it would be the two's complement, which is the one's complement plus one. Easy to do because to get one's complement we simply XOR all the bits. In BCD the analog is to use the 9's complement and add one to get the 10's complement, but I don't see anything as simple as the XOR for generating the 9's complement of BCD.

DId you have a trick to share on that score?

50%
50%
More Blogs from Max Maxfield
Max concludes his tutorial on BCD arithmetic by explaining how to subtract negative numbers.
Max finds some interesting videos that play into speculations about the potential for robot domination.
Turing machines are the theoretical basis of all digital computers. Here are the basics of their operation.
Furthering his discussions of binary coded decimal, Max poses a design challenge to the community.
flash poll
MC on twitter
like us on facebook
Microcontroller Central    About Us     Contact Us     Help     Register     Twitter     Facebook     RSS