annotate lab4/test/prob3-3.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 (* From a problem sheet *)
mike@0 2
mike@0 3 proc double(x: integer): integer;
mike@0 4 begin
mike@0 5 return x + x
mike@0 6 end;
mike@0 7
mike@0 8 proc apply3(proc f(x:integer): integer): integer;
mike@0 9 begin
mike@0 10 return f(3)
mike@0 11 end;
mike@0 12
mike@0 13 begin
mike@0 14 print_num(apply3(double));
mike@0 15 newline()
mike@0 16 end.
mike@0 17
mike@0 18 (*<<
mike@0 19 6
mike@0 20 >>*)
mike@0 21
mike@0 22 (*[[
mike@0 23 @ picoPascal compiler output
mike@0 24 .include "fixup.s"
mike@0 25 .global pmain
mike@0 26
mike@0 27 @ proc double(x: integer): integer;
mike@0 28 .text
mike@0 29 _double:
mike@0 30 mov ip, sp
mike@0 31 stmfd sp!, {r0-r1}
mike@0 32 stmfd sp!, {r4-r10, fp, ip, lr}
mike@0 33 mov fp, sp
mike@0 34 @ return x + x
mike@0 35 ldr r4, [fp, #40]
mike@0 36 add r0, r4, r4
mike@0 37 ldmfd fp, {r4-r10, fp, sp, pc}
mike@0 38 .ltorg
mike@0 39
mike@0 40 @ proc apply3(proc f(x:integer): integer): integer;
mike@0 41 _apply3:
mike@0 42 mov ip, sp
mike@0 43 stmfd sp!, {r0-r1}
mike@0 44 stmfd sp!, {r4-r10, fp, ip, lr}
mike@0 45 mov fp, sp
mike@0 46 @ return f(3)
mike@0 47 mov r0, #3
mike@0 48 ldr r10, [fp, #44]
mike@0 49 ldr r1, [fp, #40]
mike@0 50 blx r1
mike@0 51 ldmfd fp, {r4-r10, fp, sp, pc}
mike@0 52 .ltorg
mike@0 53
mike@0 54 pmain:
mike@0 55 mov ip, sp
mike@0 56 stmfd sp!, {r4-r10, fp, ip, lr}
mike@0 57 mov fp, sp
mike@0 58 @ print_num(apply3(double));
mike@0 59 mov r1, #0
mike@0 60 set r0, _double
mike@0 61 bl _apply3
mike@0 62 bl print_num
mike@0 63 @ newline()
mike@0 64 bl newline
mike@0 65 ldmfd fp, {r4-r10, fp, sp, pc}
mike@0 66 .ltorg
mike@0 67
mike@0 68 @ End
mike@0 69 ]]*)