Skip to content

Commit de58d90

Browse files
committed
Comments, documentation.
* README.md: Comment cards count when calculating jumps. Added note on check_for_prime.ae. * check_for_prime.ae: Improved commenting. Updated branches to match.
1 parent 0f30ff9 commit de58d90

File tree

2 files changed

+69
-13
lines changed

2 files changed

+69
-13
lines changed

README.md

+19-9
Original file line numberDiff line numberDiff line change
@@ -31,17 +31,17 @@ The Ada emulator is written using [Ada2012][], and uses the
3131
[GNU Multiple Precision Arithmetic library][], via the
3232
[GMP binding in GNATCOLL][].
3333

34-
If you have the [FSF GCC 6.1.0 binary for OS X][] a suitable library
35-
is provided. Otherwise, GMP and GNATCOLL are reasonably
36-
straightforward to build.
34+
If you have one of the [FSF GCC binaries for OS X][] (6.1 or later), a
35+
suitable library is provided. Otherwise, GMP and GNATCOLL are
36+
reasonably straightforward to build.
3737

3838
[Ada2012]: http://www.ada-auth.org/standards/rm12_w_tc1/html/RM-TOC.html
3939

4040
[GNU Multiple Precision Arithmetic library]: https://gmplib.org
4141

4242
[GMP binding in GNATCOLL]: https://github.com/AdaCore/gnatcoll/blob/master/src/gmp/gnatcoll-gmp-integers.ads
4343

44-
[FSF GCC 6.1.0 binary for OS X]: https://sourceforge.net/projects/gnuada/files/GNAT_GCC%20Mac%20OS%20X/6.1.0/
44+
[FSF GCC binaries for OS X]: https://sourceforge.net/projects/gnuada/files/GNAT_GCC%20Mac%20OS%20X/
4545

4646
## Running
4747

@@ -65,7 +65,7 @@ transferring the value on the source to the destination as the source
6565
digits were rotated back to zeros.
6666

6767
If `-z` is given, overwriting will be allowed; otherwise, an error
68-
will be reported ane exceution will halt.
68+
will be reported and execution will halt.
6969

7070
[this paper]: http://rclab.de/rclab/_media/analyticalengine/aal_noteg_glaschick_v1.2.pdf
7171

@@ -94,14 +94,21 @@ These card types have not been implemented (yet):
9494
* Card Library Inclusion Requests
9595
* Decimal Place Expansion Cards
9696

97-
As a minor change, lower case can be used: `n001 42` is
98-
acceptable (it stores 42 into column 1).
99-
10097
As in the [Fourmilab Java implementation][], multiplication can be
10198
indicated by `*` or `×`, division by `/` or `÷`.
10299

103100
[Fourmilab Java implementation]: https://www.fourmilab.ch/babbage/cards.html
104101

102+
When counting for Combinatorial Cards (conditional and unconditional
103+
jumps), remember that comment cards (cards starting with a period or
104+
white space) need to be included!
105+
106+
### Changes
107+
108+
* As a minor change, lower case can be used: `n001 42` is acceptable
109+
(it stores 42 into column 1).
110+
* Text after the required content is ignored, so comments can be included: `n001 42 the answer` is acceptable.
111+
105112
## Examples
106113

107114
The file `bernouilli.ae` is an implementation of the Lovelace design
@@ -126,12 +133,15 @@ might have hoped for. To deal with this, all real values are scaled by
126133
For more on this, see the notes on _Stepping Up and Down Cards_ in the
127134
[Fourmilab Java implementation][].
128135

136+
[Sketch of the Analytical Engine]: https://www.fourmilab.ch/babbage/sketch.html
137+
129138
The file `bernouilli5.ae` adds another "iteration" to the above
130139
program; the previously computed B7 is stored on column 24, and
131140
operations 13 to 23 are repeated once more (now using column 24 as
132141
input at operation 21).
133142

134-
[Sketch of the Analytical Engine]: https://www.fourmilab.ch/babbage/sketch.html
143+
The file `check_for_prime.ae` determines whether a number is
144+
prime. It's set to check 203 (AAL's 203rd birthday was in 2018).
135145

136146
## Performance
137147

check_for_prime.ae

+50-4
Original file line numberDiff line numberDiff line change
@@ -6,20 +6,63 @@ N001 203 the number to be checked
66
N000 0 constant 0 - actually the default
77
N002 1 constant 1
88
N003 2 constant 2
9+
N004 3 starting test divisor
910

10-
N004 3 starting test value
11+
. column 10 is used as a scratch register; it must be zero before
12+
. storing into it, so always load using Z10
1113

1214
A write in columns
1315

14-
/ main loop: divide target by test value
16+
. if target number is < 4, it's prime
17+
+ add 1 to 3, makes 4
18+
L004
19+
L002
20+
S010
21+
- subtract 4 from target number
22+
L001
23+
Z010 leave column 10 zero
24+
CF?1 skip if sign changed (target < 4)
25+
CF+9 continue
26+
A write numbers as ##9
27+
+ report the target is prime
28+
L001
29+
L000
30+
P
31+
A write annotation is prime
32+
A write new line
33+
H
34+
35+
. if target number is divisible by 2, it isn't prime
36+
/
37+
L001
38+
L003
39+
S010 store remainder
40+
- check for zero
41+
Z010 load remainder, leaving column 10 zeroed
42+
L002 subtract 1
43+
CF?1 skip to print/halt if sign changed (i.e. was zero)
44+
CF+8 continue to check next divisor
45+
A write numbers as ##9
46+
+ print the target number
47+
L001
48+
L000
49+
P
50+
A write annotation is divisible by 2
51+
A write new line
52+
H
53+
54+
. main loop
55+
/ divide target by test value
1556
L001
1657
L004
1758
S010 store remainder (column 10 must be zero previously)
1859
- check for zero
1960
Z010 load remainder, leaving column 10 zeroed
2061
L002 subtract 1
2162
CF?1 skip to print/halt if sign changed (i.e. was zero)
22-
CF+13 continue to check next divisor
63+
CF+15 continue to check next divisor
64+
65+
. divisor found!
2366
A write numbers as ##9
2467
+ print the target number
2568
L001
@@ -33,6 +76,7 @@ L000
3376
P
3477
A write new line
3578
H
79+
3680
+ check next possible factor
3781
Z004 load current candidate, clear store
3882
L003 add 2
@@ -45,7 +89,9 @@ S010
4589
L001 load target
4690
Z010 load (candidate squared), leaving column 10 zeroed
4791
CF?1 skip if sign changed (i.e. no divisor found)
48-
CB+35 back to main loop
92+
CB+39 back to main loop
93+
94+
. no divisor found!
4995
A write numbers as ##9
5096
+ report the target is prime
5197
L001

0 commit comments

Comments
 (0)