comparison lab4/test/mult.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 (* Multiply instructions *)
2
3 var x, y, z: integer;
4
5 proc f(x: integer): integer;
6 begin return x end;
7
8 proc mmm(x: integer): integer;
9 begin
10 y := f(x);
11 return y*y
12 end;
13
14 begin
15 x := 3;
16 y := 5;
17 z := x * y;
18 print_num(z);
19 newline();
20 print_num(mmm(12));
21 newline()
22 end.
23
24 (*<<
25 15
26 144
27 >>*)
28
29 (*[[
30 @ picoPascal compiler output
31 .include "fixup.s"
32 .global pmain
33
34 @ proc f(x: integer): integer;
35 .text
36 _f:
37 mov ip, sp
38 stmfd sp!, {r0-r1}
39 stmfd sp!, {r4-r10, fp, ip, lr}
40 mov fp, sp
41 @ begin return x end;
42 ldr r0, [fp, #40]
43 ldmfd fp, {r4-r10, fp, sp, pc}
44 .ltorg
45
46 @ proc mmm(x: integer): integer;
47 _mmm:
48 mov ip, sp
49 stmfd sp!, {r0-r1}
50 stmfd sp!, {r4-r10, fp, ip, lr}
51 mov fp, sp
52 @ y := f(x);
53 ldr r0, [fp, #40]
54 bl _f
55 set r1, _y
56 str r0, [r1]
57 @ return y*y
58 mul r0, r0, r0
59 ldmfd fp, {r4-r10, fp, sp, pc}
60 .ltorg
61
62 pmain:
63 mov ip, sp
64 stmfd sp!, {r4-r10, fp, ip, lr}
65 mov fp, sp
66 @ x := 3;
67 mov r4, #3
68 set r0, _x
69 str r4, [r0]
70 @ y := 5;
71 mov r5, #5
72 set r0, _y
73 str r5, [r0]
74 @ z := x * y;
75 mul r4, r4, r5
76 set r0, _z
77 str r4, [r0]
78 @ print_num(z);
79 mov r0, r4
80 bl print_num
81 @ newline();
82 bl newline
83 @ print_num(mmm(12));
84 mov r0, #12
85 bl _mmm
86 bl print_num
87 @ newline()
88 bl newline
89 ldmfd fp, {r4-r10, fp, sp, pc}
90 .ltorg
91
92 .comm _x, 4, 4
93 .comm _y, 4, 4
94 .comm _z, 4, 4
95 @ End
96 ]]*)