annotate lab4/test/search.p @ 1:b5139af1a420 tip basis

Fixed permissions on compile scripts
author Mike Spivey <mike@cs.ox.ac.uk>
date Fri, 13 Oct 2017 17:27:58 +0100
parents bfdcc3820b32
children
rev   line source
mike@0 1 (* String searching *)
mike@0 2
mike@0 3 const target = "abracadabra";
mike@0 4
mike@0 5 var i: integer; found: boolean;
mike@0 6
mike@0 7 begin
mike@0 8 i := 0; found := false;
mike@0 9 while not found do
mike@0 10 found := target[i] = 'd';
mike@0 11 i := i + 1
mike@0 12 end;
mike@0 13 print_num(i);
mike@0 14 newline()
mike@0 15 end.
mike@0 16
mike@0 17 (*<<
mike@0 18 7
mike@0 19 >>*)
mike@0 20
mike@0 21 (*[[
mike@0 22 @ picoPascal compiler output
mike@0 23 .include "fixup.s"
mike@0 24 .global pmain
mike@0 25
mike@0 26 .text
mike@0 27 pmain:
mike@0 28 mov ip, sp
mike@0 29 stmfd sp!, {r4-r10, fp, ip, lr}
mike@0 30 mov fp, sp
mike@0 31 @ i := 0; found := false;
mike@0 32 mov r0, #0
mike@0 33 set r1, _i
mike@0 34 str r0, [r1]
mike@0 35 mov r0, #0
mike@0 36 set r1, _found
mike@0 37 strb r0, [r1]
mike@0 38 .L3:
mike@0 39 @ while not found do
mike@0 40 set r4, _found
mike@0 41 ldrb r0, [r4]
mike@0 42 cmp r0, #0
mike@0 43 bne .L5
mike@0 44 @ found := target[i] = 'd';
mike@0 45 set r5, _i
mike@0 46 ldr r6, [r5]
mike@0 47 set r0, g1
mike@0 48 add r0, r0, r6
mike@0 49 ldrb r0, [r0]
mike@0 50 cmp r0, #100
mike@0 51 mov r0, #0
mike@0 52 moveq r0, #1
mike@0 53 strb r0, [r4]
mike@0 54 @ i := i + 1
mike@0 55 add r0, r6, #1
mike@0 56 str r0, [r5]
mike@0 57 b .L3
mike@0 58 .L5:
mike@0 59 @ print_num(i);
mike@0 60 set r0, _i
mike@0 61 ldr r0, [r0]
mike@0 62 bl print_num
mike@0 63 @ newline()
mike@0 64 bl newline
mike@0 65 ldmfd fp, {r4-r10, fp, sp, pc}
mike@0 66 .ltorg
mike@0 67
mike@0 68 .comm _i, 4, 4
mike@0 69 .comm _found, 1, 4
mike@0 70 .data
mike@0 71 g1:
mike@0 72 .byte 97, 98, 114, 97, 99, 97, 100, 97, 98, 114
mike@0 73 .byte 97
mike@0 74 .byte 0
mike@0 75 @ End
mike@0 76 ]]*)