annotate lab4/test/gcd.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 *)
mike@0 2
mike@0 3 var x, y: integer;
mike@0 4
mike@0 5 begin
mike@0 6 x := 3 * 37; y := 5 * 37;
mike@0 7 while x <> y do
mike@0 8 if x > y then
mike@0 9 x := x - y
mike@0 10 else
mike@0 11 y := y - x
mike@0 12 end
mike@0 13 end;
mike@0 14 print_num(x); newline()
mike@0 15 end.
mike@0 16
mike@0 17 (*<<
mike@0 18 37
mike@0 19 >>*)
mike@0 20
mike@0 21 (*[[
mike@0 22 @ picoPascal compiler output
mike@0 23 .include "fixup.s"
mike@0 24 .global pmain
mike@0 25
mike@0 26 .text
mike@0 27 pmain:
mike@0 28 mov ip, sp
mike@0 29 stmfd sp!, {r4-r10, fp, ip, lr}
mike@0 30 mov fp, sp
mike@0 31 @ x := 3 * 37; y := 5 * 37;
mike@0 32 mov r0, #111
mike@0 33 set r1, _x
mike@0 34 str r0, [r1]
mike@0 35 mov r0, #185
mike@0 36 set r1, _y
mike@0 37 str r0, [r1]
mike@0 38 .L2:
mike@0 39 @ while x <> y do
mike@0 40 set r4, _x
mike@0 41 ldr r5, [r4]
mike@0 42 set r0, _y
mike@0 43 ldr r6, [r0]
mike@0 44 cmp r5, r6
mike@0 45 beq .L4
mike@0 46 @ if x > y then
mike@0 47 cmp r5, r6
mike@0 48 ble .L6
mike@0 49 @ x := x - y
mike@0 50 sub r0, r5, r6
mike@0 51 str r0, [r4]
mike@0 52 b .L2
mike@0 53 .L6:
mike@0 54 @ y := y - x
mike@0 55 set r4, _y
mike@0 56 ldr r0, [r4]
mike@0 57 set r1, _x
mike@0 58 ldr r1, [r1]
mike@0 59 sub r0, r0, r1
mike@0 60 str r0, [r4]
mike@0 61 b .L2
mike@0 62 .L4:
mike@0 63 @ print_num(x); newline()
mike@0 64 set r0, _x
mike@0 65 ldr r0, [r0]
mike@0 66 bl print_num
mike@0 67 bl newline
mike@0 68 ldmfd fp, {r4-r10, fp, sp, pc}
mike@0 69 .ltorg
mike@0 70
mike@0 71 .comm _x, 4, 4
mike@0 72 .comm _y, 4, 4
mike@0 73 @ End
mike@0 74 ]]*)