Re: how calculator works (aritmethics) Message #9 Posted by Eric Smith on 18 Mar 2005, 9:22 p.m., in response to message #8 by Diana Raměrez
Those MOSFETs I mentioned previously are wired to act as logic gates that perform logical functions on binary digits (bits). For instance, one of the most common gates is the NAND gate, which produces a '0' output only if both of its inputs are '1', and otherwise produces a '1' output.
Several of these gates wired together form a "halfadder", which can add two addends of one bit each to produce a two bit result. By itself, that's not very useful, but two halfadders together can be wired as a fulladder, which will add three bits to produce a two bit result. That is useful because you can chain fulladders together to add wider data words.
In an HP calculator, the adders are a little more complex because they can be switched between pure binary mode, in which four bits represent a hexadecimal digit between 0 and 15 (F), or BCD mode, in which they represent a decimal digit between 0 and 9. BCD mode is used to implement the higherlevel arithmetic functions.
HP calculators use a 56bit or 64bit word (48bit in the case of the HP01 watch). This is considered to be 14 or 16 digits. The digits are divided into a mantissa and an exponent field in order to represent floating point numbers.
To add two userentered floating point numbers, the calculator firmware (also sometimes known as microcode) first compares the exponents to see if the numbers have the same scaling. If not, one of the numbers is repeatedly shifted left, and its exponent adjusted, until the exponents match. Then the mantissas are added. The result may have a carry, in which case the result is shifted right and the exponent adjusted again.
There is some additional complication relating to the handling of negative numbers, but this is basically how it works.
Multiplication is performed using repeated shifts and additions. Division is performed using repeated shifts and subtractions. Logarithmic, exponential, trigonometric, and inverse trigonometric functions are performed using a CORDIC technique or series approximations.
