annotate ppc/test/gcd.p @ 0:bfdcc3820b32

Basis
author Mike Spivey <mike@cs.ox.ac.uk>
date Thu, 05 Oct 2017 08:04:15 +0100
parents
children
rev   line source
0
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
1 (* gcd.p *)
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
2
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
3 var x, y: integer;
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
4
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
5 begin
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
6 x := 3 * 37; y := 5 * 37;
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
7 while x <> y do
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
8 if x > y then
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
9 x := x - y
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
10 else
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
11 y := y - x
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
12 end
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
13 end;
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
14 print_num(x); newline();
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
15 end.
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
16
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
17 (*<<
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
18 37
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
19 >>*)
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
20
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
21 (*[[
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
22 MODULE Main 0 0
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
23 IMPORT Lib 0
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
24 ENDHDR
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
25
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
26 PROC MAIN 0 0 0
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
27 ! x := 3 * 37; y := 5 * 37;
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
28 CONST 111
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
29 STGW _x
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
30 CONST 185
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
31 STGW _y
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
32 ! while x <> y do
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
33 JUMP L2
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
34 LABEL L1
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
35 ! if x > y then
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
36 LDGW _x
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
37 LDGW _y
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
38 JLEQ L5
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
39 ! x := x - y
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
40 LDGW _x
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
41 LDGW _y
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
42 MINUS
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
43 STGW _x
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
44 JUMP L2
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
45 LABEL L5
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
46 ! y := y - x
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
47 LDGW _y
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
48 LDGW _x
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
49 MINUS
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
50 STGW _y
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
51 LABEL L2
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
52 LDGW _x
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
53 LDGW _y
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
54 JNEQ L1
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
55 ! print_num(x); newline();
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
56 LDGW _x
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
57 CONST 0
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
58 GLOBAL lib.print_num
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
59 PCALL 1
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
60 CONST 0
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
61 GLOBAL lib.newline
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
62 PCALL 0
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
63 ! end.
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
64 RETURN
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
65 END
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
66
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
67 GLOVAR _x 4
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
68 GLOVAR _y 4
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
69 ! End
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
70 ]]*)