annotate lab4/test/allregs.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 (* Expressions with high register demand *)
mike@0 2
mike@0 3 proc foo(a, b, c, d: integer): integer;
mike@0 4 begin
mike@0 5 return
mike@0 6 (a-b)*(a-c)*(a-d)*(b-c)*(b-d)*(c-d)
mike@0 7 +
mike@0 8 (a-c)*(a-d)*(b-c)*(b-d)*(c-d)*(a-b)
mike@0 9 end;
mike@0 10
mike@0 11 proc baz(n: integer): integer;
mike@0 12 begin
mike@0 13 return (n-1)*(n-1)
mike@0 14 end;
mike@0 15
mike@0 16 begin
mike@0 17 print_num(foo(1,2,3,4)); newline();
mike@0 18 print_num(baz(10)); newline()
mike@0 19 end.
mike@0 20
mike@0 21 (*<<
mike@0 22 24
mike@0 23 81
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 foo(a, b, c, d: integer): integer;
mike@0 32 .text
mike@0 33 _foo:
mike@0 34 mov ip, sp
mike@0 35 stmfd sp!, {r0-r3}
mike@0 36 stmfd sp!, {r4-r10, fp, ip, lr}
mike@0 37 mov fp, sp
mike@0 38 @ return
mike@0 39 ldr r4, [fp, #40]
mike@0 40 ldr r5, [fp, #44]
mike@0 41 sub r6, r4, r5
mike@0 42 ldr r7, [fp, #48]
mike@0 43 sub r8, r4, r7
mike@0 44 ldr r9, [fp, #52]
mike@0 45 sub r4, r4, r9
mike@0 46 sub r0, r5, r7
mike@0 47 sub r5, r5, r9
mike@0 48 sub r7, r7, r9
mike@0 49 mul r1, r6, r8
mike@0 50 mul r1, r1, r4
mike@0 51 mul r1, r1, r0
mike@0 52 mul r1, r1, r5
mike@0 53 mul r1, r1, r7
mike@0 54 mul r2, r8, r4
mike@0 55 mul r0, r2, r0
mike@0 56 mul r0, r0, r5
mike@0 57 mul r0, r0, r7
mike@0 58 mul r0, r0, r6
mike@0 59 add r0, r1, r0
mike@0 60 ldmfd fp, {r4-r10, fp, sp, pc}
mike@0 61 .ltorg
mike@0 62
mike@0 63 @ proc baz(n: integer): integer;
mike@0 64 _baz:
mike@0 65 mov ip, sp
mike@0 66 stmfd sp!, {r0-r1}
mike@0 67 stmfd sp!, {r4-r10, fp, ip, lr}
mike@0 68 mov fp, sp
mike@0 69 @ return (n-1)*(n-1)
mike@0 70 ldr r0, [fp, #40]
mike@0 71 sub r4, r0, #1
mike@0 72 mul r0, r4, r4
mike@0 73 ldmfd fp, {r4-r10, fp, sp, pc}
mike@0 74 .ltorg
mike@0 75
mike@0 76 pmain:
mike@0 77 mov ip, sp
mike@0 78 stmfd sp!, {r4-r10, fp, ip, lr}
mike@0 79 mov fp, sp
mike@0 80 @ print_num(foo(1,2,3,4)); newline();
mike@0 81 mov r3, #4
mike@0 82 mov r2, #3
mike@0 83 mov r1, #2
mike@0 84 mov r0, #1
mike@0 85 bl _foo
mike@0 86 bl print_num
mike@0 87 bl newline
mike@0 88 @ print_num(baz(10)); newline()
mike@0 89 mov r0, #10
mike@0 90 bl _baz
mike@0 91 bl print_num
mike@0 92 bl newline
mike@0 93 ldmfd fp, {r4-r10, fp, sp, pc}
mike@0 94 .ltorg
mike@0 95
mike@0 96 @ End
mike@0 97 ]]*)