Post Reply 
Multiply Function [x]
08-03-2018, 06:45 PM
Post: #9
RE: Multiply Function [x]
(08-03-2018 02:40 PM)Dieter Wrote:  There was a series of HP Journal articles that described how calculators do their calculations. I remember something about log, exponential and trig functions, and maybe there also was something about multiplication and division.

This is the relevant MCODE of the HP-41 for the multiplication:
Code:
*****************************************************
*   NUT MATH ROM 1                                  *
* HP41C MAINFRAME MICROCODE ADDRESSES @14000-15777  *
*****************************************************
******************************************************
*      COMMON MATH ENTRIES                         ***
*          IF NUMBER IS 2-10,                      ***
*             THEN FORM IS:                        ***
*                A HAS 10-DIGIT FORM               ***
*                C HAS 10-DIGIT FORM               ***
*          IF NUMBER IS 1-10,                      ***
*             THEN FORM IS:                        ***
*                A HAS SIGN AND EXP                ***
*                B HAS 13-DIGIT MANTISSA           ***
*                C HAS 10-DIGIT FORM               ***
*          IF NUMBER IS 2-13,                      ***
*             THEN FORM IS:                        ***
*                A AND B AS IN 1-10                ***
*                M HAS SIGN AND EXP                ***
*                C HAS 13-DIGIT MANTISSA           ***
*                                                  ***
*       ON EXIT, C HAS 10-DIGIT FORM               ***
*                A AND B HAVE 13-DIGIT FORM        ***
*                                                  ***
******************************************************

136  115 MP2-10   56 B=0    W
137  116         172 AB EX  M
138  117 MP1-10  730 MC EX
139  120         630 C=M
140  121         106 C=0    X
141  122 MP2-13   76 B=0    S
142  123         136 C=0    S
143  124         730 MC EX
144  125        1006 C=A+C  X
145  126        1136 C=A-C  S
146  127          23 GONC   MPY110 ( 131)
147  130        1236 C=-C   S
148  131 MPY110   16 A=0    W
149  132         730 MC EX
150  133        1334 PT=    13
151  134 MPY120 1734 INC PT
152  135        1616 A SR   W
153  136          23 GOTO   MPY140 ( 140)
154  137 MPY130  456 A=A+B  W
155  140 MPY140 1142 C=C-1  PT
156  141        1763 GONC   MPY130 ( 137)
157  142        1524 ? PT=  12
158  143        1713 GONC   MPY120 ( 134)
159  144         630 C=M
160  145 MPY150  256 AC EX  W           ***ROUND, SHIFT AND NORMALIZE

This line adds the exponents:
Code:
144  125        1006 C=A+C  X

The algorithm uses the same digit by digit method we use when we manually calculate the product of two numbers.

The accumulator A keeps track of the sum.
The mantissa of one number is kept in B and continuously added to A while the mantissa of the other number in C is decremented digit by digit:
Code:
154  137 MPY130  456 A=A+B  W
155  140 MPY140 1142 C=C-1  PT
156  141        1763 GONC   MPY130 ( 137)

Once a digit of C is done the pointer PT is incremented and the accumulator A is shifted:
Code:
151  134 MPY120 1734 INC PT
152  135        1616 A SR   W

Easiest of course is to follow the program step by step in the debugger of an emulator.

Cheers
Thomas

PS: The algorithm is similar to the binary multiplication of my previous post. However base 10 instead of base 2 is used.
Find all posts by this user
Quote this message in a reply
Post Reply 


Messages In This Thread
Multiply Function [x] - Gamo - 08-03-2018, 09:27 AM
RE: Multiply Function [x] - Pekis - 08-03-2018, 01:04 PM
RE: Multiply Function [x] - rprosperi - 08-03-2018, 01:13 PM
RE: Multiply Function [x] - wynen - 08-03-2018, 01:07 PM
RE: Multiply Function [x] - Dave Britten - 08-03-2018, 02:10 PM
RE: Multiply Function [x] - Dieter - 08-03-2018, 02:40 PM
RE: Multiply Function [x] - Thomas Klemm - 08-03-2018, 05:33 PM
RE: Multiply Function [x] - Thomas Klemm - 08-03-2018 06:45 PM
RE: Multiply Function [x] - Leviset - 08-03-2018, 10:54 PM
RE: Multiply Function [x] - ijabbott - 08-03-2018, 11:05 PM
RE: Multiply Function [x] - Gamo - 08-04-2018, 01:41 AM
RE: Multiply Function [x] - Gamo - 08-04-2018, 04:23 AM
RE: Multiply Function [x] - Namir - 08-04-2018, 08:26 AM
RE: Multiply Function [x] - brickviking - 08-05-2018, 03:12 AM
RE: Multiply Function [x] - Gamo - 08-05-2018, 03:33 AM
RE: Multiply Function [x] - Thomas Klemm - 08-05-2018, 04:07 PM



User(s) browsing this thread: 1 Guest(s)