comparison 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
comparison
equal deleted inserted replaced
-1:000000000000 0:bfdcc3820b32
1 (* gcd.p *)
2
3 var x, y: integer;
4
5 begin
6 x := 3 * 37; y := 5 * 37;
7 while x <> y do
8 if x > y then
9 x := x - y
10 else
11 y := y - x
12 end
13 end;
14 print_num(x); newline();
15 end.
16
17 (*<<
18 37
19 >>*)
20
21 (*[[
22 MODULE Main 0 0
23 IMPORT Lib 0
24 ENDHDR
25
26 PROC MAIN 0 0 0
27 ! x := 3 * 37; y := 5 * 37;
28 CONST 111
29 STGW _x
30 CONST 185
31 STGW _y
32 ! while x <> y do
33 JUMP L2
34 LABEL L1
35 ! if x > y then
36 LDGW _x
37 LDGW _y
38 JLEQ L5
39 ! x := x - y
40 LDGW _x
41 LDGW _y
42 MINUS
43 STGW _x
44 JUMP L2
45 LABEL L5
46 ! y := y - x
47 LDGW _y
48 LDGW _x
49 MINUS
50 STGW _y
51 LABEL L2
52 LDGW _x
53 LDGW _y
54 JNEQ L1
55 ! print_num(x); newline();
56 LDGW _x
57 CONST 0
58 GLOBAL lib.print_num
59 PCALL 1
60 CONST 0
61 GLOBAL lib.newline
62 PCALL 0
63 ! end.
64 RETURN
65 END
66
67 GLOVAR _x 4
68 GLOVAR _y 4
69 ! End
70 ]]*)