An HP35 Hardware Emulator on ARDUINO board

By Pietro DE LUCA (PESCARA, Italy)  


Talking about calculator, particularly ancient scientific pocket calculator, makes you think with a bit of nostalgia: the beginning of computing Era.

Accustomed to the rapid pace of technology evolution, it may seem overly simplistic to analyze in detail the modus operandi of a pocket calculator.

But excluding this kind of reverse engineering analysis will deprive us of valuable technological knowledge.

An opportunity that allows us to begin this trip through time is the analysis of a computing machine that made history: let’s talk about the HP35.




On this subject there are the contributions of Jacques Laporte and Peter Monta.

Peter made the first reverse engineering of the HP35’s ROM and Jacques published the documentation that comprehensively addressed all aspects of the pocket calculator firmware and architecture.

You can also get –on their sites- detailed information about how the firmware works, with notes of historical characters and events that have contributed to scientific progress (1).

This material is actually ‘living’ as confirmed by various postings on the HP Calculator forum, though 40 years have elapsed since the creation of this calculator.

The material is living also because there are software emulators.

Emulators are showing a mock-up of objects that exist in reality, at virtually any level.

So why not turn it into something concrete?


1) Emulating HP35 in hardware

The first pocket scientific calculator in history, one with the standard transcendental functions, was the HP35.

As it is now an object of worship, this paper is about emulating the machine on a modern micro-controller: the modern chip running the ancient code in ROM.

Although it seems almost impossible, we know we are men and if men did it in 1971 we can do it now : a question of desire and will.

So, I said to myself, let's do it !!!!!

But we’ll have to start from a purely formal analysis: The Church-Turing thesis.

The first part argues that there isn't a more powerful formalism of the Turing machine than modeling an algorithm.

The second part of the statement concludes that any algorithm can be encoded in terms of Turing machine formalism or equivalent.

Without going into detail of what a Turing machine is, we know that this statement, although it has not yet been shown in its entirety, it is true for any problem that we submit to it, if there is an algorithm that can give us an answer in a definite time.

This tells us that the algorithm exists, written in the ROM of HP35, and the formalism is the equivalent CPU built up at the time by AMI / Mostek.

If we build something that acts as the CPU can then recreate the object using the encoding algorithm written in the ROM.

2) Emulation set up

The system is an Arduino board PS2-Keyboard, and LCD 1x16 or more, hardwired on my homemade USB shield.

Today (fortunately) there are processors and development systems, simple but powerful. For example, the board with his Arduino programming language (so called ‘wiring’), allows to disentangle with great ease of use in programming and hardware interfaces, in this case those of the microprocessor ATMEGA328P.

I wonder what was the development system used by HP, in 1972-71 : I used Emulino.

3) Architecture

It's a CPU with 7 working registers A, B, C, D, E, F and M, wide 56-bit, plus status register wide 12-bit, a carry of one-bit, and the input register wide 6-bit, the output is the contents of register A, that through a multiplex presents its output on the display.

The status register is addressable bit by bit, this means that I can set or reset, and also to test every single bit.

Then there is an address register P, 4-bit pointer.

Everything is better described in the following link :

http://www.jacques-laporte.org/HP35 ROM.htm

(bottom of the page there is a table of jump addresses and correspondence with the keys).

4) Memory

The memory is divided into blocks of 256 words by 10 bits, exactly 3 blocks for a total of 768 Word ROM. It 's a segmented memory, such as modern CPU we call the segment register offset and the program counter PC of course.

The external RAM does not exist; the only memory used has the form of registers in the CPU.

5) 'Fetch Execute' cycle

Like all the CPU is in two phases:


Carry_Alu (Arithmetic logic unit ) = Carry
Carry = 0
take data from the memory addressed by the offset and PC and copy it in IR register
increment PC


Do operation stored in the register IR
The 'arithmetic logic unit always uses carry and generates output carry.
The conditional jump instructions use Carry_Alu (the result of a previous operation)
The pointer has a range from 0 to 15 register word (wide 4 bit) on only 14-word long.
There are no hardware problem, if the given address does not exist there is no data modification.
In the simulation is different, this can lead to read something outside the index, then by mistake or by a data element in memory, outside of our control.

The solution used in the emulator that I made is to have vector that are the registers of the simulated length of 16 words by 4 bits, although in reality it uses 14.

The reason for this is the time of execution involving a check every time you use P (time cost) and complexity of software that does that, compared to a simple increase to more modest of memory used.

6) Data Input

It 's very simple, is that of a typical PC keyboard with PS2 connection connected to the Arduino with only 4 wires (+, -, data, sck) that  -via the use of a library - gives us the code of key pressed. The HP35's original key mapping will be redistributed on the keyboard.

Here are the choices I made to assign keys.

For functions, of course I chose the function keys F1 through F12, ESC to cancel and the numeric keypad to input data and the 4 fundamentals operation and the ENTER key. The required functions are 19 has been used for some, the shift key.

Library file used : (PS2Keyboard_1)

I changed the Arduino library for the following layout:

ESC                               F1              F2           F3          F4                    F5            F6            F7            F8                   F9           F10           F11      F12

The upper functions are obtained with the shift key plus F7-F9-F10-F11-F12

You can print and stick a label near your keyboard's function keys (keyboard layout).

The software wait for a key pressed, and return the address used to jump to the corresponding code, and set flag S0.

The library uses interrupts: do not change keyboard pinout.

The pull-up resistors required for operation are internally included in the micro controller

Remember for the keyboard the modified library is mandatory!!!

7) Output

It 's the most delicate phase of the presentation of data.

To compose the output string: the HP35 used two CPU registers that provide direct decimal encoding and positional number to be displayed. A register contains the displayable form (floating point) while another register holds a mask to correctly position digits and decimal point.

The original CPU has a dedicated hardware that does this, using an LED display.

The unit of output provided in the simulator is a classic 1 x 16 LCD controlled by a single HD44780.

This means that the library that manages the LCD is changed (currently displays, '1 x 16 ', have two '44780') : you can find it here : LCD4BitHP.zip

Inside the file, there is the pinout configuration used for the project (please refer to the schematic)

In the source code there is #define LCD1x16 .

If this value, is true the software configure the lcd for 1x16 (display module have only one IC 44780 )

If  #define LCD1x16 is assigned to false, the software configure the display interface for 2 x 16 characters.

You can download for your use the originally library from:

http://www.arduino.cc/playground/uploads/Code/LCD4BitLibrary.zip (different pinout)

The functions used are the same. It is possible if there are conflicts to use a different pinout. The proposed solution uses the most logical layout for the available pins.

Here is the display layout implemented:

                                                                    GND       Contr. GND   +

             D7   D6   D5   D4                           E  R/W  RS   Adj  Vdd  Vcc

LCD       14   13    12   11   10    9    8    7    6     5    4       3      2      1

Arduino 11   10     9    8                             6          12    



The software emulation update the display when the internal signal display on / off passes from 1 to 0. The display is updated properly, but can not blink. For error signaling I used a LED connected to pin 13 of Arduino board. This led blink if there is a error condition like n/0 or sqr(-n) .

The error condition is recognized by the emulator when the PC jumps to the '277 '(' base 8 ') and is removed when it receives a character from keyboard for the interrupt I used the following library :


8) Assembling All

After discussing the features of the various modules, here is below a photo of the Arduino (ready to emulate HP-35) :

And the schematic diagram :

Below photos of display in various condition of work:

For example the famous (e^(ln(2,02)) sequence on LCD display.

After reset:


entering 2.02

ln (2.02)



And an example of very small floating point number, the number displayed on the first page of original manual:

With Arduino’s ‘IDE’ compile the source file hp35_lcd.pde and upload it to the target, you can uncomment the appropriate line, in the rom section, to have the calculator with or without a known bug on the natural logarithm.

Personally I have an Arduino USBASP but will still work with the same pins on Arduino UNO and 2009. All draw about 125 milliamps (keyboard included).

The Keyboard:


For a description of CPU instructions and functions of the calculator refer to website

http://www.jacques-laporte.org/HP 35 Saga.htm

Jacques has given ample space, with high grade of competence, to the topic.

9) Evolution

Having recreated the CPU with all its features, we can see the Arduino as a server that performs certain instructions (hence the HP35 ROM), we can exploit this condition to a supervisory control or to implement a programmable calculator with its own specific language maybe stored in the ATMEGA‘s flash, using as input devices like a touch-pad with a color display for output, all features that perhaps some other, will want to implement.

The software is the power!

You can include this project into a specific case or use the keyboard itself.


Can someone create the same functionality of HP35 in less space ROM?

© Pietro De Luca (PESCARA, Italy), June 9, 2011.

currently majoring in computer science at the University of L'Aquila
can be reached on

(1) P. Monta : http://www.pmonta.com/calculators/hp-35/index.html

J. Laporte, on this site : http://www.jacques-laporte.org/HP 35 Saga.htm