Up
Flow chart

A step by step comment

4) Part 1: The exponents calculation.

Now here is the full story.

I'm going now to comment step by step my example: ln(4.4).

A text file is available here but you can do your own experiment with the simulator.

In this trace file links to comments are indicated by a sign [CPn] (e.g. [CP1] meaning check point #1 … etc).

The entry point address is 00003 (all addresses in octal) and control branches there when the ln key is pressed. Natural logarithm calculation has status bit S9 set and S5 reset. A switch between ln(x) and ex  is provided by status bit S8: if reset we go to ln(M) code address 02010.

Register C contains the mantissa M (argument of ln(M) ; returning from the input loop, the position if the decimal point us kept in a “mask” in register B (digit 2 is the decimal pint and 9 is a zero).


We have pressed “4.4” and “ln”,

C is [0044000000] and B is [0209999999999] 

[CP1]
First action to be taken is to form the 10’s complement of the mantissa at address 02014. Register C keeps the original argument and A has the 10’s complement value.

An “error” test is done for ln(0) and ln(<0) and branches to label err21 (displaying error message).

02013:.            0 -> a[w]
02014:.            a - c -> a[m]
A=05600000000000
02015:             if no carry go to err21
02016:            shift right a[w]
A=00560000000000
02017:             c - 1 -> c[s]
02020:             if no carry go to err21

[CP2]
To show how it works, I’m going to describe the calculation in depth for the first constants.

We enter in the ln(M) routine at label “ln25” of the Rom listing, address 02021.

C=94400000000000
02021: .          ln25:     c + 1 -> c[s]
C=04400000000000
02022:             ln26:     a -> b[w]
02023:             jsb eca22

Exponents qj –for a given constant- is the maximum of times the pseudo calculation  is done.

This count is kept in digit 13 of C register, for the current constant.
It will be shifted right, and kept in C, processing the next constant. At the end of part 1, C in hold the result in the form of a set of exponents (pseudo quotients)  ; the ROM of the HP35 uses only 6 constants j from 0 to 5.

When entering at ln25 for the first time, we are processing constant 2, exponent qo and we are incrementing the count at C digit 13, from zero:

So
02021              ln 25    c + 1 -> c[5]
is restoring C register sign to zero.
C=04400000000000 

We pass immediately to label ln26.

02022:             ln26:     a -> b[w]
A=00560000000000  B=00560000000000
02023:             jsb eca22

We copy A to B preparing “pseudo multiplication”, A is going to be shifted right and summed with B and the end A + B -> A

Then the code calls “eca22” to do the main job in part 1, handling the pseudo multiplication of a value in A by a constant. 

[CP3]
The call is made with the SR count (number of shift right operations) –for a given constant- in digit 13 of register A.

For constant 2, the SR count is zero.

This count is very simply related to indice j:

 j                constant                             number of SR              exponent qj

0          1 + 10-0           2                         0 SR                         1
1          1 + 10-1           1.1                      1 SR                         1
2          1 + 10-2           1.01                     2 SR                         3
3          1 + 10-3           1.001                   3 SR                         2
4          1 + 10-4           1.0001                  4 SR                         6
5          1 + 10-5           1.00001                5 SR                         7

The SR counter is decremented first when entering “eca” and a test is made to check if there is no carry after decrementing. If no, control loops to eca21 and performs another SR on a[wp] (p points digit 12) thus preserving the counter.

This loop ends when the count of SR is reached (a -1 -> a[s] makes a carry) and when A has the correct value (right shifted enough) to perform pseudo multiplication.

In the second part of “eca” subroutine (address 2230), the counter is reset to zero, and in 2231 the pseudo multiplication A + B -> A is done.  

02230:                         0 -> a[s]
A=00560000000000  B=00560000000000
02231:                         a + b -> a[w]
A=01120000000000  B=00560000000000 

We see now precisely that in the operation there are 2 key parameters in the automaton:

-         j (the number of SR in eca) stored in digit 13 of register A (shortly a[s]),
-         qj the pseudo quotient (exponent of the expression) or number of loops of pseudo multiplication with the same constant, which is stored in digit 13 of register C during a constant processing and kept during all the calculation in register C (right shifted, digit to digit). It is the output of the process.

SR will be incremented, for each new constant, at address 2002.

To be clear, in our example of ln(4.4), for constant 1.00001, j=5 and q5 is 7: 1+10-5 is applied 7 times.

[CP4]
When control is returned from “eca”, a[p] (p point 12) is decremented and a test is done to see if there is a carry while decrementing (a[p]=9 and carry).

This is the optimized form of the complemented algorithm (see $3 Fine tuning and eq3).

A=01120000000000  B=00560000000000  C=04400000000000
02024:                         a - 1 -> a[p]
A=00120000000000  B=00560000000000  C=04400000000000
02025:                        if no carry go to ln25

If no carry, one more pseudo multiplication is required and control goes to ln25 to update count of qj in C and gets back to ln26 and call again eca22.

If there is a carry, we must change of constant.

So “eca” subroutine is the heart of part 1 and, as the acronym suggests, is dedicated to exponent calculation (qj).  
In the later case (need to change constant), control goes to 02026 and there takes place a trick to test if we have finished calculation part 1. I have already shown that j goes from 0 to 5, so at address 02027 we double the a[s] value which is in fact containing j, and we test for a carry after the operation:

02026:                         a exchange b[wp]
A=50322882267342  B=59322885496164  C=76231144000000
02027:                         a + b -> a[s]
A=00322882267342  B=59322885496164  C=76231144000000
02030: .......111 -> 02001       if no carry go to ln24
A=00322882267342  B=59322885496164  C=76231144000000

In the case of a carry, control follows thru, and starts to process pseudo quotient (part 2).

02031:                         7 -> p
02032:                         jsb pqo23