comparison lab4/test/search.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 (* String searching *)
2
3 const target = "abracadabra";
4
5 var i: integer; found: boolean;
6
7 begin
8 i := 0; found := false;
9 while not found do
10 found := target[i] = 'd';
11 i := i + 1
12 end;
13 print_num(i);
14 newline()
15 end.
16
17 (*<<
18 7
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 @ i := 0; found := false;
32 mov r0, #0
33 set r1, _i
34 str r0, [r1]
35 mov r0, #0
36 set r1, _found
37 strb r0, [r1]
38 .L3:
39 @ while not found do
40 set r4, _found
41 ldrb r0, [r4]
42 cmp r0, #0
43 bne .L5
44 @ found := target[i] = 'd';
45 set r5, _i
46 ldr r6, [r5]
47 set r0, g1
48 add r0, r0, r6
49 ldrb r0, [r0]
50 cmp r0, #100
51 mov r0, #0
52 moveq r0, #1
53 strb r0, [r4]
54 @ i := i + 1
55 add r0, r6, #1
56 str r0, [r5]
57 b .L3
58 .L5:
59 @ print_num(i);
60 set r0, _i
61 ldr r0, [r0]
62 bl print_num
63 @ newline()
64 bl newline
65 ldmfd fp, {r4-r10, fp, sp, pc}
66 .ltorg
67
68 .comm _i, 4, 4
69 .comm _found, 1, 4
70 .data
71 g1:
72 .byte 97, 98, 114, 97, 99, 97, 100, 97, 98, 114
73 .byte 97
74 .byte 0
75 @ End
76 ]]*)