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