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