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?
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.
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?
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.
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 :-)
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.
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.
To save this item to your list of favorite Microcontroller Central content so you can find it later in your Profile page, click the "Save It" button next to the item.
If you found this interesting or useful, please use the links to the services below to share it with other readers. You will need a free account with each service to share an item via that service.