### comparison lab4/test/gcd.p @ 0:bfdcc3820b32

Basis
author Mike Spivey Thu, 05 Oct 2017 08:04:15 +0100
comparison
equal inserted replaced
-1:000000000000 0:bfdcc3820b32
1 (* Euclid's algorithm *)
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 @ picoPascal compiler output
23 .include "fixup.s"
24 .global pmain
25
26 .text
27 pmain:
28 mov ip, sp
29 stmfd sp!, {r4-r10, fp, ip, lr}
30 mov fp, sp
31 @ x := 3 * 37; y := 5 * 37;
32 mov r0, #111
33 set r1, _x
34 str r0, [r1]
35 mov r0, #185
36 set r1, _y
37 str r0, [r1]
38 .L2:
39 @ while x <> y do
40 set r4, _x
41 ldr r5, [r4]
42 set r0, _y
43 ldr r6, [r0]
44 cmp r5, r6
45 beq .L4
46 @ if x > y then
47 cmp r5, r6
48 ble .L6
49 @ x := x - y
50 sub r0, r5, r6
51 str r0, [r4]
52 b .L2
53 .L6:
54 @ y := y - x
55 set r4, _y
56 ldr r0, [r4]
57 set r1, _x
58 ldr r1, [r1]
59 sub r0, r0, r1
60 str r0, [r4]
61 b .L2
62 .L4:
63 @ print_num(x); newline()
64 set r0, _x
65 ldr r0, [r0]
66 bl print_num
67 bl newline
68 ldmfd fp, {r4-r10, fp, sp, pc}
69 .ltorg
70
71 .comm _x, 4, 4
72 .comm _y, 4, 4
73 @ End
74 ]]*)