annotate lab4/test/foo.p @ 1:b5139af1a420 tip basis

Fixed permissions on compile scripts
author Mike Spivey <mike@cs.ox.ac.uk>
date Fri, 13 Oct 2017 17:27:58 +0100
parents bfdcc3820b32
children
rev   line source
mike@0 1 (* Euclid's algorithm as a subroutine *)
mike@0 2
mike@0 3 proc gcd(u, v: integer): integer;
mike@0 4 var x, y: integer;
mike@0 5 begin
mike@0 6 x := u; y := v;
mike@0 7 while x <> y do
mike@0 8 if x < y then
mike@0 9 y := y - x
mike@0 10 else
mike@0 11 x := x - y
mike@0 12 end
mike@0 13 end;
mike@0 14 return x
mike@0 15 end;
mike@0 16
mike@0 17 var z: integer;
mike@0 18 begin
mike@0 19 z := gcd(3*37, 5*37);
mike@0 20 print_string("The final answer is calculated as ");
mike@0 21 print_num(z); newline()
mike@0 22 end.
mike@0 23
mike@0 24 (*<<
mike@0 25 The final answer is calculated as 37
mike@0 26 >>*)
mike@0 27
mike@0 28 (*[[
mike@0 29 @ picoPascal compiler output
mike@0 30 .include "fixup.s"
mike@0 31 .global pmain
mike@0 32
mike@0 33 @ proc gcd(u, v: integer): integer;
mike@0 34 .text
mike@0 35 _gcd:
mike@0 36 mov ip, sp
mike@0 37 stmfd sp!, {r0-r1}
mike@0 38 stmfd sp!, {r4-r10, fp, ip, lr}
mike@0 39 mov fp, sp
mike@0 40 @ x := u; y := v;
mike@0 41 ldr r4, [fp, #40]
mike@0 42 ldr r5, [fp, #44]
mike@0 43 .L3:
mike@0 44 @ while x <> y do
mike@0 45 cmp r4, r5
mike@0 46 beq .L5
mike@0 47 @ if x < y then
mike@0 48 cmp r4, r5
mike@0 49 bge .L7
mike@0 50 @ y := y - x
mike@0 51 sub r5, r5, r4
mike@0 52 b .L3
mike@0 53 .L7:
mike@0 54 @ x := x - y
mike@0 55 sub r4, r4, r5
mike@0 56 b .L3
mike@0 57 .L5:
mike@0 58 @ return x
mike@0 59 mov r0, r4
mike@0 60 ldmfd fp, {r4-r10, fp, sp, pc}
mike@0 61 .ltorg
mike@0 62
mike@0 63 pmain:
mike@0 64 mov ip, sp
mike@0 65 stmfd sp!, {r4-r10, fp, ip, lr}
mike@0 66 mov fp, sp
mike@0 67 @ z := gcd(3*37, 5*37);
mike@0 68 mov r1, #185
mike@0 69 mov r0, #111
mike@0 70 bl _gcd
mike@0 71 set r1, _z
mike@0 72 str r0, [r1]
mike@0 73 @ print_string("The final answer is calculated as ");
mike@0 74 mov r1, #34
mike@0 75 set r0, g1
mike@0 76 bl print_string
mike@0 77 @ print_num(z); newline()
mike@0 78 set r0, _z
mike@0 79 ldr r0, [r0]
mike@0 80 bl print_num
mike@0 81 bl newline
mike@0 82 ldmfd fp, {r4-r10, fp, sp, pc}
mike@0 83 .ltorg
mike@0 84
mike@0 85 .comm _z, 4, 4
mike@0 86 .data
mike@0 87 g1:
mike@0 88 .byte 84, 104, 101, 32, 102, 105, 110, 97, 108, 32
mike@0 89 .byte 97, 110, 115, 119, 101, 114, 32, 105, 115, 32
mike@0 90 .byte 99, 97, 108, 99, 117, 108, 97, 116, 101, 100
mike@0 91 .byte 32, 97, 115, 32
mike@0 92 .byte 0
mike@0 93 @ End
mike@0 94 ]]*)