"E97": example of linear program

Let's calculate full surface of the parallelepiped with ribs A, B and C, using "E97". A, B and C values will be stored in memory cells 40-44.

The parallelepiped surface formula is the following:
S = 2 * (A * B + A * C + B * C) = 2 * [A * (B + C) + B * C]
Let's program it in "E97" codes (don't be afraid that the program is so long, it consists from several simple parts):

AddressCodeOperationComments
0000
0002
0E6D
0100
100 ==> SPDetermine SP
for correct subroutine calls
0004
0006
9C0D
4182
input ==> R1 A ==> R1
0008
000A
011E
0040
R1 ==> (40) A ==> (40)
000C
000E
9C0D
4182
input ==> R1 B ==> R1
0010
0012
011E
0042
R1 ==> (42) B ==> (42)
0014
0016
9C0D
4182
input ==> R1 C ==> R1
0018
001A
011E
0044
R1 ==> (44) C ==> (44)
001C
001E
01E0
0042
(42) ==> R0 B ==> R0
00200101 R0 ==> R1 B ==> R1
0022
0024
02E0
0044
R0 + (44) ==> R0 B + C
0026
0028
05E0
0040
R0 * (40) ==> R0 A * (B + C)
002A
002C
05E1
0044
R1 * (44) ==> R1 B * C
002E0201 R1 + R0 ==> R1 A * (B+C) + B * C
00300211 R1 + R1 ==> R1 2 * [A * (B + C) + B * C]
0032
0034
011E
0046
R1 ==> (46) result ==> S
0036
0038
9C0D
4152
R1 ==> displayprint S
003A0F00 halt stop
003C
003E
---- -------------------------------------------
00400002 A  
00420003 B  
00440004 C  
00460034 S (resut) (note, that hex number 34
is equal to decimal 52)

Try and examine, how it works in "E97". Input 3 integer values and read the result on the display.
Attention please! You may have some difficulties with input window (it can appear only once) in MS Internet Explorer v 5.0. in Windows media. To correct the situation disable JAVA compiler - JIT, using IE options.

Back to main applet page