Microcode: Electronic Building Blocks For Calculators
(since April 22, 1997)
Last Update: August 14, 2021 -- THE HP REFERENCE
Hewlett Packard Personal Calculator Digest
Vol. 3, 1977
pp 4-6
Just as DNA can be called the building blocks of the human
organism. Microcode can be called the building blocks of the
electronic calculator.
But, while the way the human organism works is determined by
heredity, the way an electronic calculator works is determined
by the highly personal--and even idiosyncratic--creative impulses
of a programming specialist.
The principles of programming can be learned, of course. But
anyone who has programmed his own calculator quickly discovers
that techniques may vary widely from person to person.
Consider the challenge faced by the professional programmer
When you press the key labeled SIN, for example, you expect the
calculator to display the sine of the value you have keyed into
it--and presto, it does. But in that less-than-a-second interval
between keystroke and display, the calculator has executed an
internal program of about 3500 steps. And it does this according
to the highly individualistic microcode that the programmer has
created.
The development of microcode in Hewlett-Packard personal calculators
began with the development developments of the microprocessor in
the HP-35--and not coincidentally, since both were developed by
the same Hewlett-Packard engineer.
It is the microprocessor that determines the "language" of the
internal microcode. If you are familiar with computer languages
such as BASIC, FORTRAN, and COBOL, you know that these languages
structure the way you write your program on the computer.
You can only do what the language lets you do.
The microprocessor is similar to the computer. It provides a
language that a clever engineer can then build into a function on
the keyboard.
The original HP-35 microprocessor has remained essentially unchanged
through the years and is the heart of the new HP-19C and HP-29C.
Compared with computer processors, the binary-coded decimal
microprocessor is very simple it does not handle byte data well,
but is, in fact, specially designed for 10-digit floating point
numbers (See figure 1.). The resulting microcode language most closely
resembles machine language, which is programming at as most basic
level.
Most microprocessors use 8-bit instructions and two or three
instructions are usually combined to perform one operation. The
beauty of HP's calculator microcode is that 10-bit instructions
are used and each usually performs a complete operation by itself.
The language's strongest point is its robust arithmetic section of
37 instructions combined with eight field-select options. The
field-select options allow the program to apply the instruction
to any word-select portion of the register (See figure 2.).
The language is also designed to use very little storage; only
seven registers were used in the HP-35 of which five were user
registers. This is done to reduce costs and to save valuable space.
For the design engineer it means that he must accomplish all of his
miracles within the program itself.
Based on warranty card analysis and other market research,
parameters regarding the desired function set and price are given
to the design engineer. It is his job then to determine the specific
functions for the calculator and to attempt to fit them in the
allotted memory. Price is an important factor to the engineer because
it directly influences the amount of memory he has to work with.
Only after several months of hard work writing and compacting
microcode will he know if the function set will fit. If it is not
possible, the product may be redefined at a higher price with
greater performance to increase the available memory. More likely
however, the engineer will be forced to pare functions until his
program fits.
To give you an idea of how much memory is required, the HP-35 used
three pages of 256 instructions each. Each page required a separate
ROM read-only memory.
- HP-35----768 instructions--3/4 quad (3 pages of 256 instructions each)
The HP-45 originally took six pages of instructions. But about that
time the quad ROM was developed, which, as its name implies, was the
equivalent of four conventional ROM'S. So for the HP-45, two quad
ROM's were used. It was in the leftover two pages that an
enterprising designer placed the celebrated HP-45 clock. Later
calculators, listed below, continued to use quad ROM's.
- HP-45---2048 instructions--2 quads
- HP-80---2048 instructions--2 quads
- HP-65---3072 instructions--3 quads
- HP-70---2048 instructions--2 quads
- HP-55---3072 instructions--3 quads
- HP-19C--5120 instructions--5 quads
- HP-10---1536 instructions--1 1/2 quads
- HP-21---1024 instructions--1 quad
- HP-25---2048 instructions--2 quads
- HP-22---2048 instructions--2 quads
- HP 91---3072 instructions--3 quads
- HP-29C--4096 instructions--4 quads
- HP-27---3072 instructions--3 quads
- HP-25C--2048 instructions--2 quads
- HP 67---5120 instructions--5 quads
- HP 97---6144 instructions--6 quads
- HP-92---6144 instructions--6 quads
Note: 1 quad = 1024 instructions or 4 pages of 256
instructions each. -Rick-
Writing the microcode is where the designer's personality is
stamped indelibly on the Calculator. While it is true that the
fundamental algorithms for commuting the complex mathematical
functions found in HP personal calculators have remained
essentially the same since the HP-35, the individual code is
substantially different.
+---------------------------------------------------------------------+
| NUMBER REGISTER REPRESENTATION |
| |
| +---+---+---+---+---+---+---+---+---+---+---+---+---+---+ |
| 23.4 | 0 | 2 | 3 | 4 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 1 | |
| +---+---+---+---+---+---+---+---+---+---+---+---+---+---+ |
| |
| a |
| +---+---+---+---+---+---+---+---+---+---+---+---+---+---+ |
| -123. | 9 | 1 | 2 | 3 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 2 | |
| +---+---+---+---+---+---+---+---+---+---+---+---+---+---+ |
| |
| b |
| +---+---+---+---+---+---+---+---+---+---+---+---+---+---+ |
| .002 | 0 | 2 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 9 | 9 | 7 | |
| +---+---+---+---+---+---+---+---+---+---+---+---+---+---+ |
| |
| a. A "9" in the sign position indicates a negative number. |
| b. Exponents are kept in 10's complement form. |
| |
+---------------------------------------------------------------------+
| Figure 1. All numbers in registers are in scientific notation with |
| the mantissa portion of the number left justified in the mantissa |
| portion of the register. |
+---------------------------------------------------------------------+
+---------------------------------------------------------------------+
| mantissa sign exponent sign |
| pointer | | |
| positions+---+---+---+---+---+---+---+---+---+---+---+---+---+---+ |
| ----> |13 |12 |11 |10 | 9 | 8 | 7 | 6 | 5 | 4 | 3 | 2 | 1 | 0 | |
| +---+---+---+---+---+---+---+---+---+---+---+---+---+---+ |
| | | | | |
| | | | | |
| | +------------- mantissa ----------------+- exponent + |
| | | | |
| +----------- mantissa and sign -------------+ | |
| | | |
| +---------------------- word --------------------------+ |
| |
+---------------------------------------------------------------------+
+---------------------------------------------------------------------+
|Instructions |
+--------------+------------------------------------------------------+
| A = 0 | |
| B = 0 | Clears word-select portion. |
| C = 0 | |
+--------------+------------------------------------------------------+
| B = A | Copies word-select portion |
| C = B | from specified register |
| A = C | to specified register. |
+--------------+------------------------------------------------------+
| AB EX | Exchanges word-select portion |
| AC EX | between specified registers. |
| CB EX | |
+--------------+------------------------------------------------------+
| A = A + B | |
| A = A + C | |
| C = A + C | |
| C = C + C | |
| A = A - B | |
| C = A - C | |
| A = A - C | Performs stated arithmetic |
| A = A + 1 | on word-select portion. |
| C = C + 1 | |
| A = A - 1 | |
| C = C - 1 | |
| C = -C | |
| C = -C - 1 | |
+--------------+------------------------------------------------------+
| A SR | |
| B SR | Shifts word-select portion right. |
| C SR | |
+--------------+------------------------------------------------------+
| | |
| A SL | Shifts word-select portion left. |
| | |
+--------------+------------------------------------------------------+
| | Circular shifts whole A |
| A SLC | register but does not have |
| | word-select option. |
+--------------+------------------------------------------------------+
| ? B = 0 | |
| ? C = 0 | |
| ? A => C | Tests word-select portion of |
| ? A => B | given register. |
| ? A = 0 | |
| ? C = 0 | |
+--------------+------------------------------------------------------+
| Field-Select Options |
| |
| 1. Mantissa (M) |
| 2. Mantissa and Sign (MS) |
| 3. Exponent (X) |
| 4. Exponent Sign (XS) |
| 5. Sign of Mantissa (S) |
| 6. Pointer (P) |
| 7. Word (W) |
| 8. Word thru Pointer (WP) |
| |
+---------------------------------------------------------------------+
| Figure 2. Registers are 14 digits long with each digit being four |
| bits. An additional four bit register is used as a pointer. The |
| programmer can set the pointer to any digit position, change that |
| digit or all digits up to that position. |
+---------------------------------------------------------------------+
Some of the major routines such as those for sine, cosine, and
tangent are the same from calculator to calculator. But in most
cases if the code cannot be borrowed exactly as it exists in
another calculator, it must be rewritten.
Some designer begin by strictly flowcharting the entire program
Others tackle the code directly and leave all but basic flowcharting
till the end for documentation purposes only. The code is written
originally on paper just as you would write a program on an HP
programming pad. It is then either punched on cards or typed
into a handy CRT.
The major task in writing the microcode is not only to have the
functions produce the correct answers when a key is pressed, but
to fit the code into a given amount of memory and make it
execute as fast as possible. Compacting the code, that is,
rewriting sections of the program to make them more space-efficient,
is easy enough, but sometimes results in a loss of speed. These are
tradeoffs to which the designer must be constantly attentive.
The processor executes approximately three instructions per
millisecond, with each instruction taking the same amount of time.
The designer takes into consideration the type of function
and the necessary speed when writing the code. Straight-line
code with no branches of any I kind executes the fastest. For the
label search function on the HP-67 and the HP-97 the designer
duplicated a great deal of code to; make it faster. The print
instructions for the new HP-19C, on the other hand, did not need
to be as fast to keep up with the printer, mechanism. So the designer
compacted these codes, making them very complex.
+---------------------------------------------------------------------+
| +---------------+ +---------------+ +---------------+ |
| | A. Answer | |B. Multiplicand| | C. Multiplier | |
| +---------------+ +---------------+ +---------------+ |
| |
+--------+-----------+--------+---------------------------------------+
| LABEL | CODE | | Explanation |
+--------+-----------+--------+---------------------------------------+
| | A = 0 | W | Clearing space for answer. |
| | P = | 3 | Starting at least significant digit. |
| | GoTo | Mpy90 | Starting in middle of loop for speed. |
| Mpy90 | A = A + B | W | Add Multiplicand to partial product |
| | | | the number of times specified by |
| | | | digit being worked on. |
+--------+-----------+--------+---------------------------------------+
| Mpy100 | C = C - 1 | P | |
| | GoNC | Mpy90 | NC stands for no carry, i.e. a GoTo |
| | | | is executed unless a digit is |
| | | | carried (or borrowed). |
| | ? P = | 12 | Have we reached the end of the world? |
| | GoYes | END | |
| | | | |
+--------+-----------+--------+---------------------------------------+
| | P = P + 1 | | Move on the next digit. |
| | A SP | W | This does a divide by 10 to line up |
| | | | for the next decade. |
| | GoTo | Mpy100 | Go reenter loop. |
| | | | |
+--------+-----------+--------+---------------------------------------+
| Figure 3. Multiplying two numbers uses the basic routine shown |
| above and involves three registers The starting point of this |
| code assumes the sign and exponent of the answer have already |
| been calculated. END is a common function return which would |
| perform operations such as display formatting, printing, etc. |
+---------------------------------------------------------------------+
In general, programmable calculators go through more gyrations
for each function than do preprogrammed calculators because they
must generate an intermediate keycode. Where simple functions
such as Change Sign, x exchange y, and ENTER require only 100
steps of code on a preprogrammed calculator, the same functions
on a programmable calculator might take 150 steps. And a complex
function such as rectangular-to-polar conversion might take over
4000 steps, depending on the argument keyed in.
The engineer uses a computer simulator to write and debug his
code. Special programs written for this simulator furnish him with
status bit information, register contents, and intermediate answers
as an aid in this process.
Once the microcode is completed on the computer, it is transferred
to an E-ROM (erasable read only-memory) simulator for further
debugging (See photo.). The simulator is ideal for this because it
is portable and easily updated as bugs are found and corrected.
Simulated calculators are given to application engineers and quality
assurance engineers to help locate problems.
After much editing, the microcode is ready to be converted into
hardware. This usually takes several weeks. In the meantime, the
simulators continue to be used heavily and, in most cases, additional
bugs are found.
When the completed integrated circuit chips return, the first working
models of the calculator are constructed. Final testing is then
initiated. Some problems can only be discovered at this stage because
of the peculiarities of simulated operation. For example, this is the
first time low battery indicators can be checked since the E-ROM
simulator does not work on batteries.
At long last, the revised code is ready to be sent for final chips.
Although no problems are anticipated at this stage, testing continues
to assure traditional Hewlett-Packard reliability.
The tremendous emphasis on testing of the calculators is for
practical reasons as well incorrect programs cannot be easily
corrected as they can be on large computers. Once the code is set
in hardware, changes are costly and inconvenient.
When the final chips are approved for production, the development
cycle is complete. The design engineer has spent anywhere from six
months to 13 months perfecting his building block design. And
whether the end product is a high-powered financial calculator like
the HP-92 or a versatile keystroke programmable like the HP-19C, it
is first an expression of his personality and creativity.
The Calculator Reference by Rick Furr (rfurr@vcalc.net)
Back to The HP Page
Back to The Calculator Reference