annotate lab4/test/infwhile.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 proc foo(): integer;
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
2 var i: integer;
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
3 begin
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
4 i := 3;
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
5 while true do
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
6 i := i + 2;
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
7 if i > 10 then return i end;
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
8 end
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
9 end;
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
10
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
11 begin
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
12 print_num(foo()); newline()
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
13 end.
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
14
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
15 (*<<
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
16 11
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
17 >>*)
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
18
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
19 (*[[
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
20 @ picoPascal compiler output
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
21 .include "fixup.s"
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
22 .global pmain
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
23
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
24 @ proc foo(): integer;
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
25 .text
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
26 _foo:
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
27 mov ip, sp
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
28 stmfd sp!, {r4-r10, fp, ip, lr}
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
29 mov fp, sp
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
30 @ i := 3;
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
31 mov r4, #3
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
32 .L2:
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
33 @ i := i + 2;
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
34 add r4, r4, #2
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
35 @ if i > 10 then return i end;
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
36 cmp r4, #10
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
37 ble .L2
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
38 mov r0, r4
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
39 ldmfd fp, {r4-r10, fp, sp, pc}
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
40 .ltorg
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
41
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
42 pmain:
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
43 mov ip, sp
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
44 stmfd sp!, {r4-r10, fp, ip, lr}
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
45 mov fp, sp
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
46 @ print_num(foo()); newline()
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
47 bl _foo
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
48 bl print_num
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
49 bl newline
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
50 ldmfd fp, {r4-r10, fp, sp, pc}
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
51 .ltorg
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
52
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
53 @ End
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
54 ]]*)