         Edinburgh IMP77 Compiler - Version 8.4
    1 !
		.Ltext0:
				.globl	main
		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
		.LVL0:
				subq	$40, %rsp
				movq	%fs:40, %rax
				movq	%rax, 24(%rsp)
				xorl	%eax, %eax
   56 %integer a,i,b
				call	_imp_initialise@PLT
		.LVL1:
   57
   58   read(a)
				leaq	12(%rsp), %rdi
				call	_imp_readint@PLT
		.LVL2:
   59 ! BL     read_fn
   60
   61 ! Str    R0,a
   62   read(i)
				leaq	16(%rsp), %rdi
				call	_imp_readint@PLT
		.LVL3:
   63 ! BL     read_fn
   64
   65 ! Str    R0,i
   66   read(b)
				leaq	20(%rsp), %rdi
				call	_imp_readint@PLT
		.LVL4:
		.LBB14:
   67 ! BL     read_fn
   68
   69   %if a <= i <= b %start
   70 ! Ldr R1,a
   71 ! Ldr R2,i
   72 ! CmpS   R1,R2
				movl	16(%rsp), %eax
		.LVL5:
				movl	12(%rsp), %edi
				cmpl	%edi, %eax
				jl	.L2
   73 ! CmpSLE R2,R0
   74     i = 22
				cmpl	20(%rsp), %eax
				jg	.L3
		.LBE14:
				movl	$22, 16(%rsp)
		.LVL6:
		.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
				movl	$22, %eax
		.LVL7:
		.L4:
				cmpl	$21, %eax
				jg	.L4
		.LVL10:
		.L3:
		.LBE16:
		.LBB17:
   82 ! MovGT  R2,#44
   83   %finish
				cmpl	%eax, 20(%rsp)
				jl	.L3
		.LVL8:
		.L5:
		.LBE15:
   84
   85   %if a <= i <= 77 %start
   86 ! CmpS   R1,R2
   87 ! CmpSLE R2,#77
   88     i = 99
				movl	16(%rsp), %eax
		.LVL11:
   89 ! MovLE  R2,#99
   90   %finish
				cmpl	$77, %eax
				jg	.L7
				cmpl	%eax, %edi
				jle	.L5
		.L7:
		.LVL12:
		.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
				movl	$1, 16(%rsp)
				jmp	.L8
		.LVL9:
		.L2:
		.LBB16:
   96 ! MovLS R2,#1
   97   %finish
				subl	$11, %eax
		.LVL13:
				cmpl	$89, %eax
				jbe	.L5
		.LVL14:
		.L8:
		.LBE18:
   98
   99 ! Str   R0,b
  100   write(a,0)
				movl	$0, %esi
				call	_imp_writeint@PLT
		.LVL15:
		.LBB19:
		.LBB20:
				call	_imp_newline@PLT
		.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)
				movl	$0, %esi
				movl	16(%rsp), %edi
				call	_imp_writeint@PLT
		.LVL17:
		.LBB21:
		.LBB22:
				call	_imp_newline@PLT
		.LVL18:
		.LBE22:
		.LBE21:
  110 ! Bl    write
  111
  112   newline
  113 ! Bl    newline
  114
  115   write(b,0)
				movl	$0, %esi
				movl	20(%rsp), %edi
				call	_imp_writeint@PLT
		.LVL19:
		.LBB23:
		.LBB24:
				call	_imp_newline@PLT
		.LVL20:
		.LBE24:
		.LBE23:
		.LBB25:
		.LBB26:
				movl	$0, %edi
				call	exit@PLT
		.LVL21:
		.LBE26:
		.LBE25:
		.LFE185:
		.Letext0:
  116 ! Ldr   R0,b
  117 ! Bl    write
  118
  119   newline
  120 ! Bl    newline
  121
  122 %endofprogram
   24 Statements compiled
