comparison lab4/test/repchar.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 (* Simple recursion *)
2
3 proc repchar(c: char; n: integer);
4 var i: integer;
5 begin
6 if n > 0 then
7 print_char(c);
8 repchar(c, n-1)
9 end
10 end;
11
12 begin
13 repchar('A', 3);
14 repchar('B', 5);
15 newline()
16 end.
17
18 (*<<
19 AAABBBBB
20 >>*)
21
22 (*[[
23 @ picoPascal compiler output
24 .include "fixup.s"
25 .global pmain
26
27 @ proc repchar(c: char; n: integer);
28 .text
29 _repchar:
30 mov ip, sp
31 stmfd sp!, {r0-r1}
32 stmfd sp!, {r4-r10, fp, ip, lr}
33 mov fp, sp
34 @ if n > 0 then
35 ldr r0, [fp, #44]
36 cmp r0, #0
37 ble .L1
38 @ print_char(c);
39 ldrb r0, [fp, #40]
40 bl print_char
41 @ repchar(c, n-1)
42 ldr r0, [fp, #44]
43 sub r1, r0, #1
44 ldrb r0, [fp, #40]
45 bl _repchar
46 .L1:
47 ldmfd fp, {r4-r10, fp, sp, pc}
48 .ltorg
49
50 pmain:
51 mov ip, sp
52 stmfd sp!, {r4-r10, fp, ip, lr}
53 mov fp, sp
54 @ repchar('A', 3);
55 mov r1, #3
56 mov r0, #65
57 bl _repchar
58 @ repchar('B', 5);
59 mov r1, #5
60 mov r0, #66
61 bl _repchar
62 @ newline()
63 bl newline
64 ldmfd fp, {r4-r10, fp, sp, pc}
65 .ltorg
66
67 @ End
68 ]]*)