annotate lab4/test/varparam.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 (* Access to var parameters from nested procedures *)
mike@0 2
mike@0 3 proc one(var x: integer);
mike@0 4 proc two(); begin x := x+1 end;
mike@0 5 begin
mike@0 6 two()
mike@0 7 end;
mike@0 8
mike@0 9 proc three();
mike@0 10 var y: integer;
mike@0 11 begin
mike@0 12 y := 36;
mike@0 13 one(y);
mike@0 14 print_num(y);
mike@0 15 newline()
mike@0 16 end;
mike@0 17
mike@0 18 begin
mike@0 19 three()
mike@0 20 end.
mike@0 21
mike@0 22 (*<<
mike@0 23 37
mike@0 24 >>*)
mike@0 25
mike@0 26 (*[[
mike@0 27 @ picoPascal compiler output
mike@0 28 .include "fixup.s"
mike@0 29 .global pmain
mike@0 30
mike@0 31 @ proc one(var x: integer);
mike@0 32 .text
mike@0 33 _one:
mike@0 34 mov ip, sp
mike@0 35 stmfd sp!, {r0-r1}
mike@0 36 stmfd sp!, {r4-r10, fp, ip, lr}
mike@0 37 mov fp, sp
mike@0 38 @ two()
mike@0 39 mov r10, fp
mike@0 40 bl _two
mike@0 41 ldmfd fp, {r4-r10, fp, sp, pc}
mike@0 42 .ltorg
mike@0 43
mike@0 44 @ proc two(); begin x := x+1 end;
mike@0 45 _two:
mike@0 46 mov ip, sp
mike@0 47 stmfd sp!, {r4-r10, fp, ip, lr}
mike@0 48 mov fp, sp
mike@0 49 @ proc two(); begin x := x+1 end;
mike@0 50 ldr r0, [fp, #24]
mike@0 51 ldr r4, [r0, #40]
mike@0 52 ldr r0, [r4]
mike@0 53 add r0, r0, #1
mike@0 54 str r0, [r4]
mike@0 55 ldmfd fp, {r4-r10, fp, sp, pc}
mike@0 56 .ltorg
mike@0 57
mike@0 58 @ proc three();
mike@0 59 _three:
mike@0 60 mov ip, sp
mike@0 61 stmfd sp!, {r4-r10, fp, ip, lr}
mike@0 62 mov fp, sp
mike@0 63 sub sp, sp, #8
mike@0 64 @ y := 36;
mike@0 65 mov r0, #36
mike@0 66 str r0, [fp, #-4]
mike@0 67 @ one(y);
mike@0 68 add r0, fp, #-4
mike@0 69 bl _one
mike@0 70 @ print_num(y);
mike@0 71 ldr r0, [fp, #-4]
mike@0 72 bl print_num
mike@0 73 @ newline()
mike@0 74 bl newline
mike@0 75 ldmfd fp, {r4-r10, fp, sp, pc}
mike@0 76 .ltorg
mike@0 77
mike@0 78 pmain:
mike@0 79 mov ip, sp
mike@0 80 stmfd sp!, {r4-r10, fp, ip, lr}
mike@0 81 mov fp, sp
mike@0 82 @ three()
mike@0 83 bl _three
mike@0 84 ldmfd fp, {r4-r10, fp, sp, pc}
mike@0 85 .ltorg
mike@0 86
mike@0 87 @ End
mike@0 88 ]]*)