         Edinburgh IMP77 Compiler - Version 8.4
    1 !
				.section	".text"
		.Ltext0:
				.align 4
				.global main
				.proc	04
		main:
		.LFB185:
    2 ! The hand-generated code below should be producable by PSR's compiler if it:
    3 ! A) delays stores as late as possible
    4 !
    5 ! B) remembers registers over procedure calls
    6 !
    7 ! C) has a general algorithm for drop-through conditionally executed
    8 !    instructions, i.e. if there are no instructions between a conditional
    9 !    branch and its destination which set the condition codes, and the
   10 !    sequence is less that a certain length, then all the instructions
   11 !    within the sequence can be made conditional.
   12 !
   13 ! D) does as above, but also allows instructions within the sequence
   14 !    whose subsequent execution depends on the same condition, e.g.
   15 !
   16 !    %if a=b %and c=d %then a=b
   17 !
   18 !    CmpS   R0,R1            NAIVE STYLE
   19 !    Bne    elsepart
   20 !    Cmps   R2,R3
   21 !    Bne    elsepart
   22 !    Mov    R0,R2
   23 !
   24 !    CmpS   R0,R1            RULE (C) ABOVE
   25 !    Bne    elsepart
   26 !    CmpS   R2,R3
   27 !    MovEQ  R0,R2
   28 !
   29 !    CmpS   R0,R1            RULE (D) SPECIAL CASE
   30 !    CmpSEQ R2,R3
   31 !    MovEQ  R0,R2
   32 !
   33 ! E) alters conditions to generate similar condition codes on
   34 !    condition AND condition AND condition to generate more cases
   35 !    to which rule (D) can be applied.
   36 !
   37 ! F) adjusts constants in < or <= cases to favour above, i.e. turning
   38 !    CMP R,#const & BLE ... into CMP R,#const-1 & BLT ... etc.
   39 !
   40 ! G) changes Newline back from the current implicit printsymbol(10) -
   41 !    there is no run-time overhead in moving the MOV R0,#10 over to
   42 !    the procedure body instead of having it in every call where it
   43 !    takes up space - after all, Peter's code-moving stuff ought to
   44 !    get %permroutine newline;printsymbol(10);%end correct - it will
   45 !    place the Mov R0,#10 before the body of %permroutine printsymbol
   46 !    and generate a suitable entry point for it...
   47 !       Personally, I would recommend stacking/restoring R0 as well
   48 !    as it might keep another variable in a register for a bit longer...
   49 !
   50 ! I've only suggested optimisations which fit into the style of PSR's
   51 ! compilers...
   52 !
   53
   54
   55 %begin
				.register	%g2, #scratch
				.register	%g3, #scratch
				.register	%g7, #ignore
		.LVL0:
				save	%sp, -208, %sp
		.LVL1:
				ldx	[%g7+40], %g1
				stx	%g1, [%fp+2039]
				mov	0, %g1
   56 %integer a,i,b
				mov	%i1, %o1
				call	_imp_initialise, 0
				 mov	%i0, %o0
		.LVL2:
   57
   58   read(a)
				call	_imp_readint, 0
				 add	%fp, 2027, %o0
		.LVL3:
   59 ! BL     read_fn
   60
   61 ! Str    R0,a
   62   read(i)
				call	_imp_readint, 0
				 add	%fp, 2031, %o0
		.LVL4:
   63 ! BL     read_fn
   64
   65 ! Str    R0,i
   66   read(b)
				call	_imp_readint, 0
				 add	%fp, 2035, %o0
		.LVL5:
		.LBB14:
   67 ! BL     read_fn
   68
   69   %if a <= i <= b %start
   70 ! Ldr R1,a
   71 ! Ldr R2,i
   72 ! CmpS   R1,R2
				lduw	[%fp+2031], %g1
		.LVL6:
				lduw	[%fp+2027], %o0
				cmp	%g1, %o0
				bl,pt	%icc, .L2
				 cmp	%g1, 21
   73 ! CmpSLE R2,R0
   74     i = 22
				lduw	[%fp+2035], %g2
				cmp	%g1, %g2
				bg,pt	%icc, .L10
				 cmp	%g1, 77
		.LBE14:
				mov	22, %g1
		.LVL7:
				st	%g1, [%fp+2031]
		.LVL8:
		.LBB15:
   75 ! MovLE  R2,#22
   76   %finish
   77
   78   %if 22 <= i <= b %start
   79 ! CmpS   R2,#22-1
   80 ! CmpSGT R2,R0
   81     i = 44
				bg,pn	%icc, .L12
				 lduw	[%fp+2035], %g2
		.LVL11:
		.L3:
		.LBE16:
		.LBB17:
   82 ! MovGT  R2,#44
   83   %finish
				lduw	[%fp+2035], %g2
		.L12:
				cmp	%g2, %g1
				bl,pn	%icc, .L11
				 lduw	[%fp+2031], %g1
		.LVL9:
		.L5:
		.LBE15:
   84
   85   %if a <= i <= 77 %start
   86 ! CmpS   R1,R2
   87 ! CmpSLE R2,#77
   88     i = 99
				lduw	[%fp+2031], %g1
		.LVL12:
		.L11:
				cmp	%o0, %g1
				mov	0, %g2
				movg	%icc, 1, %g2
   89 ! MovLE  R2,#99
   90   %finish
				cmp	%g1, 77
		.L10:
				mov	0, %g3
				movg	%icc, 1, %g3
				orcc	%g3, %g2, %g0
				be,pn	%icc, .L5
				 add	%g1, -11, %g1
		.L7:
		.LVL13:
		.LBE17:
		.LBB18:
   91
   92   %if 11 <= i <= 100 %start     ;! Peter's special case when both const is good
   93 ! Sub   R2,#11                  ;! but usually corrupts a register needed later
   94 ! CmpS  R2,#100-11
   95     i = 1
				mov	1, %g1
		.L13:
				ba,pt	%xcc, .L8
				 st	%g1, [%fp+2031]
		.LVL10:
		.L2:
		.LBB16:
   96 ! MovLS R2,#1
   97   %finish
				cmp	%g1, 89
				bleu,pn	%icc, .L13
				 mov	1, %g1
		.LVL14:
		.L8:
		.LBE18:
   98
   99 ! Str   R0,b
  100   write(a,0)
				mov	0, %o1
				call	_imp_writeint, 0
				 sra	%o0, 0, %o0
		.LVL15:
		.LBB19:
		.LBB20:
				call	_imp_newline, 0
				 nop
		.LVL16:
		.LBE20:
		.LBE19:
  101 ! Mov   R0,R1
  102 ! Mov   R1,#0
  103 ! Bl    Write
  104
  105   newline
  106 ! Bl    Newline
  107
  108 ! Mov   R0,R2
  109   write(i,0)
				mov	0, %o1
				call	_imp_writeint, 0
				 ldsw	[%fp+2031], %o0
		.LVL17:
		.LBB21:
		.LBB22:
				call	_imp_newline, 0
				 nop
		.LVL18:
		.LBE22:
		.LBE21:
  110 ! Bl    write
  111
  112   newline
  113 ! Bl    newline
  114
  115   write(b,0)
				mov	0, %o1
				call	_imp_writeint, 0
				 ldsw	[%fp+2035], %o0
		.LVL19:
		.LBB23:
		.LBB24:
				call	_imp_newline, 0
				 nop
		.LVL20:
		.LBE24:
		.LBE23:
		.LBB25:
		.LBB26:
				call	exit, 0
				 mov	0, %o0
		.LVL21:
		.LBE26:
		.LBE25:
				nop
		.LFE185:
		.Letext0:
  116 ! Ldr   R0,b
  117 ! Bl    write
  118
  119   newline
  120 ! Bl    newline
  121
  122 %endofprogram
   24 Statements compiled
