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