Back to:
The parallelepiped surface |
Let's calculate full surface of the parallelepiped with ribs A, B and C,
using "E97". A, B and C values is taken from memory cells.
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:
Address | Code |
Operation | Comments |
0000 | 01E0 |
(22) ==> R0 | B ==> R0 |
0002 | 0022
|
|
|
0004 | 0101 |
R0 ==> R1 | B ==> R1 |
0006 | 02E0 |
R0 + (24) ==> R0 | B + C |
0008 | 0024 |
|
|
000A | 05E0 |
R0 * (20) ==> R0 | A * B (B + C) |
000C | 0020 |
|
|
000E | 05E1 |
R1 * (24) ==> R1 | B * C |
0010 | 0024
|
|
|
0012 | 0210 |
R0 + R1 ==> R0 | A * (B+C) + B * C |
0014 | 0200 |
R0 + R0 ==> R0 | 2 * [A * (B + C) + B * C] |
0016 | 010E |
R0 ==> (26) | result ==> S |
0018 | 0026
|
|
|
001A | 0F00 |
halt |
|
---- | ---- |
--------------- | ---------------------------- |
0020 | 0002 |
A |
|
0022 | 0003 |
B |
|
0024 | 0004 |
C |
|
0026 | 0034 |
S | (note, that hex number 34 is equal to decimal 52) |
Back to:
The program gets latin letter and makes it upper-case.
The upper- and lower-case characters differ in one bit only. For example,
ASCII codes for letter R, are the following:
R - 0101 0010; r - 0111 0010.
To reset the 5-th bit, logical operation AND with constant 1101 1111 = DF
can be used: if constant bit is zero, the result bit will be zero too,
otherwise it repeats the congruent character's bit.
Address | Code |
Operation | Comments |
0000 | 0E6D |
30 ==> SP | set SP for correct |
0002 | 0030 |
| subroutine calls |
0004 | 9C0D |
call subroutine | symbol input |
0006 | 40FE |
40FE | (without echo!) |
0008 | 0101 |
R0 ==> R1 | save input character |
000A | 07D0 |
DF and R0 ==> R0 | make upper-case character |
000C | 00DF |
|
|
000E | 9C0D |
call subroutine | result's output |
0010 | 4088
| 4088 |
|
0012 | 0F00 |
halt |
|
To convert input character to lower-case, it's enough to change the
logic operation AND to OR:
Back to:
Arbitrary integer numbers are stored in registers R1, R2 and R3. Find
maximum of them.
At first we'll copy maximum of R1 and R2 to R0. Then, if R3>R0,
it's necessary to replace R0 value by R3.
Address | Code
| Operation | Comments |
0000 | 0412 |
compare R2 and R1 |
|
0002 | 3D04 |
if <0, then pc=pc+4 | to 0008 |
0004 | 0120 |
R2 ==> R0 | remember R2 |
0006 | 1D02 |
pc=pc+2 | to 000A - bypass second branch |
0008 | 0110 |
R1 ==> R0 | remember R1 |
000A | 0403 |
compare R3 with R0 | |
000C | 3D02 |
if <0, then pc=pc+2 | to 0010 |
000E | 0130 |
R3 ==> R0 | remember R3 |
0010 | 0F00
| halt |
|
We can rewrite our program with jump instructions: it will become
more demonstrative, but longer. It also will lose relocation properties
- we will not be able to move it to anoother address without changes.
Address | Code
| Operation | Comments |
0000 | 0412 |
compare R2 and R1 |
|
0002 | 3C0D |
if <0, then to 000C | |
0004 | 000C |
|
|
0006 | 0120 |
R2 ==> R0 | remember R2 |
0008 | 1C0D |
jump to 000E | bypass second branch |
000A | 000E |
| |
000C | 0110 |
R1 ==> R0 | remember R1 |
000E | 0403 |
compare R3 with R0 | |
0010 | 3C0D |
if <0, then to 0016 |
|
0012 | 0016 |
| |
0014 | 0130 |
R3 ==> R0 | remember R3 |
0016 | 0F00
| halt |
|
Back to:
Serial natural numbers sum |
Calculate the sum of first 100 natural numbers.
Let's place current natural number N to R3 (N varies from 1 to 100),
and the sum result to R0. After assignment of initial values, we'll
increment N and add it's value to S. The condition of cycle ending
is N>100.
Address | Code
| Operation | Comments |
0000 | 2113 |
1 ==> R3 | 1 ==> N |
0002 | 2100 |
0 ==> R0 | 0 ==> S |
0004 | 0230 |
R0 + R3 ==> R0 | S = S + N |
0006 | 2213 |
R3 + 1 ==> R3 | N = N + 1 |
0008 | 04D3 |
compare R3 with 100 | compare N with 100 |
000A | 0064 |
| |
000C | 6DF6 |
if <=0, then pc=pc+F6 | if N<=100, repeat cycle
(000E + FFF6 = 0004) |
000E | 0F00 |
halt | |
Back to:
Form latin alphabet from "A" to "Z" on display screen..
The initial symbol "A" has code 65=41h. So we put it into R0 and call
ROM subroutine, that outputs character. The next letter can be get
after increment of R0. If the result exceeds 5Ah ("Z"), the cycle ends.
Address | Code
| Operation | Comments |
0000 | 0E6D |
30 ==> SP | set SP for correct |
0002 | 0030 |
| subroutine calls |
0004 | 01D0 |
41 ==> R0 | first symbol code |
0006 | 0041 |
("A") |
|
0008 | 9C0D |
call subroutine | output to screen |
000A | 4088 |
4088 | |
000C | 2210 |
R0 + 1 ==> R0 | next symbol |
000E | 04D0 |
compare R0 with 5A | code <= "Z"? |
0010 | 005A |
("Z") | |
0012 | 6DF4 |
if <=0, then pc=pc+F4 | repeat cycle (to 0008) |
0014 | 0F00 |
halt | |
Back to:
Copy data, allocated from address, stored in R1, to address, placed in R2.
The number of bytes is set in R0.
Because we consider R0 - R2 were set, our program is very short. It's
main command C156 works with bytes and copies (R1)b into (R2)b. Then
addresses in R1 and R2 are modified, and cycle counter decrements. The
cycle repeats until R0<>0.
Address | Code
| Operation | Comments |
0000 | C156 |
(R1)b ==> (R2)b | copy current byte |
0002 | 2211 |
R1 + 1 ==> R1 | get new sourse-array address |
0004 | 2211 |
R2 + 1 ==> R2 | get new destination-array address |
0006 | 2310 |
R0 - 1 ==> R0 | decrement byte counter |
0008 | 4DF6 |
if <>0, then pc=pc+F6 | repeat the cycle (to 0000) |
000A | 0F00 |
halt | |
Back to:
How many times this symbol is met in the text
|
Some text, terminated by zero byte, is allocated in memory from 0016
address. How many times a character from R0 meets in this text?
Let's place the conjunction counter to R1, and current address of the
text to R2. The algorithm compares each symbol of the text with pattern
and increments R1 if they are equal. The cycle ends, when address in R2
points to zero byte.
Address | Code
| Operation | Comments |
0000 | 2101 |
0 ==> R1 | clear conjunction counter |
0002 | 01D2 |
16 ==> R2 | set the beginning |
0004 | 0016 |
| of the text |
0006 | C460 |
compare R0b with (R2)b | compare symbol with pattern |
0008 | 4D02 |
if <>0, then pc=pc+2 | bypass if not equal (to 000C) |
000A | 2211 |
R1 + 1 ==> R1 | increment the conjunction counter |
000C | 2212 |
R2 + 1 ==> R2 | calculate the next address |
000E | E406 |
compare (R2)b with 0b | is text finished? |
0010 | 4DF4 |
if <>0, then pc=pc+F4 | if not - repeat the cycle (to 0006) |
0012 | 0F00 |
halt |
|
0014 | 0000 |
|
|
0016 | 4854 |
"TH" | text |
0018 | 5349 |
"IS" | "THIS IS MY TEXT"+ |
001A | 4920 |
" I" | +code 0 |
001C | 2053
| "S " |
|
001E | 594D |
"MY" |
|
0020 | 5420 |
" T" |
|
0022 | 5845 |
"EX" |
|
0024 | 0054 |
"T"(0) |
|
Back to:
|