annotate lab4/test/strcopy.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 (* String copying by loop *)
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
2
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
3 const in = "Hello, world!*";
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
4
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
5 var out: array 128 of char; i: integer;
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
6
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
7 begin
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
8 i := 0;
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
9 while in[i] <> '*' do
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
10 out[i] := in[i];
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
11 i := i + 1
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
12 end;
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
13 out[i] := chr(0);
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
14 print_string(out); 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 Hello, world!
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 @ picoPascal compiler output
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
23 .include "fixup.s"
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
24 .global pmain
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
25
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
26 .text
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
27 pmain:
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
28 mov ip, sp
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
29 stmfd sp!, {r4-r10, fp, ip, lr}
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
30 mov fp, sp
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
31 @ i := 0;
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
32 mov r0, #0
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
33 set r1, _i
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
34 str r0, [r1]
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
35 .L3:
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
36 @ while in[i] <> '*' do
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
37 set r4, _i
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
38 ldr r5, [r4]
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
39 set r0, g1
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
40 add r0, r0, r5
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
41 ldrb r6, [r0]
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
42 cmp r6, #42
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
43 beq .L5
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
44 @ out[i] := in[i];
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
45 set r0, _out
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
46 add r0, r0, r5
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
47 strb r6, [r0]
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
48 @ i := i + 1
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
49 ldr r0, [r4]
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
50 add r0, r0, #1
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
51 str r0, [r4]
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
52 b .L3
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
53 .L5:
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
54 @ out[i] := chr(0);
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
55 set r4, _out
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
56 mov r0, #0
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
57 set r1, _i
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
58 ldr r1, [r1]
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
59 add r1, r4, r1
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
60 strb r0, [r1]
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
61 @ print_string(out); newline()
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
62 mov r1, #128
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
63 mov r0, r4
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
64 bl print_string
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
65 bl newline
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
66 ldmfd fp, {r4-r10, fp, sp, pc}
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
67 .ltorg
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
68
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
69 .comm _out, 128, 4
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
70 .comm _i, 4, 4
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
71 .data
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
72 g1:
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
73 .byte 72, 101, 108, 108, 111, 44, 32, 119, 111, 114
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
74 .byte 108, 100, 33, 42
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
75 .byte 0
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
76 @ End
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
77 ]]*)