Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Assembler : why BCD exists?

I know BCD is like more intuitive datatype if you don't know binary. But I don't know why to use this encoding, its like don't makes a lot of sense since its waste representation in 4bits (when representation is bigger than 9).

Also I think x86 only supports adds and subs directly (you can convert them via FPU).

Its possible that this comes from old machines, or other architectures?

like image 239
llazzaro Avatar asked Mar 01 '10 22:03

llazzaro


People also ask

What is the purpose of the BCD?

Binary-coded Decimal or BCD is a way of representing a decimal number as a string of bits suitable for use in electronic systems. Rather than converting the whole number into binary, BCD splits the number up into its digits and converts each digit to 4-bit binary.

Why data is stored in BCD?

A Binary Coded Decimal (BCD) is a type of binary representation for decimal values where each digit is represented by its 4 bit binary equivalent. Binary-coded decimals are an easy way to represent decimal values, as each digit is represented by its own 4-bit binary sequence which only has 10 different combinations.

Why the output bits are being converted into BCD?

The main advantage of the Binary Coded Decimal system is that it is a fast and efficient system to convert the decimal numbers into binary numbers as compared to the pure binary system. But the BCD code is wasteful as many of the 4-bit states (10-to-16) are not used but decimal displays have important applications.


2 Answers

BCD exists in modern x86 CPU's since it was in the original 8086 processor, and all x86 CPU's are 8086 compatible. BCD operations in x86 were used to support business applications way back then. BCD support in the processor itself isn't really used anymore.

Note that BCD is an exact representation of decimal numbers, which floating point is not, and that implementing BCD in hardware is far simpler than implementing floating point. These sort of things mattered more back when processors had less than a million transistors that ran at a few megahertz.

like image 103
Michael Avatar answered Sep 28 '22 11:09

Michael


BCD is useful at the very low end of the electronics spectrum, when the value in a register is displayed by some output device. For example, say you have a calculator with a number of seven-segment displays that show a number. It is convenient if each display is controlled by separate bits.

It may seem implausible that a modern x86 processor would be used in a device with these kinds of displays, but x86 goes back a long way, and the ISA maintains a great deal of backward compatibility.

like image 27
Jay Conrod Avatar answered Sep 28 '22 12:09

Jay Conrod