         Edinburgh IMP77 Compiler - Version 8.4
    1 !
		.Ltext0:
				.globl	main
		main:
		.LFB189:
    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
				leal	4(%esp), %ecx
				andl	$-16, %esp
				pushl	-4(%ecx)
				pushl	%ebp
				movl	%esp, %ebp
				pushl	%ebx
				pushl	%ecx
				subl	$320, %esp
				call	__x86.get_pc_thunk.bx
				addl	$_GLOBAL_OFFSET_TABLE_, %ebx
				movl	%ecx, %eax
				movl	4(%eax), %edx
				movl	%edx, -316(%ebp)
				movl	%gs:20, %ecx
				movl	%ecx, -12(%ebp)
				xorl	%ecx, %ecx
				subl	$8, %esp
				pushl	-316(%ebp)
				pushl	(%eax)
				call	_imp_initialise@PLT
				addl	$16, %esp
   56 %integer a,i,b
   57
   58   read(a)
				subl	$12, %esp
				leal	-300(%ebp), %eax
				pushl	%eax
				call	_imp_readint@PLT
				addl	$16, %esp
   59 ! BL     read_fn
   60
   61 ! Str    R0,a
   62   read(i)
				subl	$12, %esp
				leal	-296(%ebp), %eax
				pushl	%eax
				call	_imp_readint@PLT
				addl	$16, %esp
   63 ! BL     read_fn
   64
   65 ! Str    R0,i
   66   read(b)
				subl	$12, %esp
				leal	-292(%ebp), %eax
				pushl	%eax
				call	_imp_readint@PLT
				addl	$16, %esp
		.LBB17:
   67 ! BL     read_fn
   68
   69   %if a <= i <= b %start
				movl	-296(%ebp), %eax
				movl	%eax, -284(%ebp)
				movl	-300(%ebp), %eax
				cmpl	%eax, -284(%ebp)
				jl	.L16
				movl	-292(%ebp), %eax
				cmpl	%eax, -284(%ebp)
				jg	.L17
		.LBE17:
				nop
				jmp	.L3
		.L17:
				nop
		.L3:
		.LBE18:
		.LBB19:
   70 ! Ldr R1,a
   71 ! Ldr R2,i
   72 ! CmpS   R1,R2
   73 ! CmpSLE R2,R0
   74     i = 22
				movl	$22, -296(%ebp)
				jmp	.L3
		.L16:
		.LBB18:
   75 ! MovLE  R2,#22
   76   %finish
   77
   78   %if 22 <= i <= b %start
				movl	-296(%ebp), %eax
				movl	%eax, -288(%ebp)
				cmpl	$21, -288(%ebp)
				jle	.L18
				movl	-292(%ebp), %eax
				cmpl	%eax, -288(%ebp)
				jg	.L19
		.LBE19:
				nop
				jmp	.L6
		.L19:
				nop
		.L6:
		.LBE20:
		.LBB21:
   79 ! CmpS   R2,#22-1
   80 ! CmpSGT R2,R0
   81     i = 44
				movl	$44, -296(%ebp)
				jmp	.L6
		.L18:
		.LBB20:
   82 ! MovGT  R2,#44
   83   %finish
   84
   85   %if a <= i <= 77 %start
				movl	-296(%ebp), %eax
				movl	%eax, -280(%ebp)
				movl	-300(%ebp), %eax
				cmpl	%eax, -280(%ebp)
				jl	.L20
				cmpl	$77, -280(%ebp)
				jg	.L21
		.LBE21:
				nop
				jmp	.L9
		.L21:
				nop
		.L9:
		.LBE22:
		.LBB23:
   86 ! CmpS   R1,R2
   87 ! CmpSLE R2,#77
   88     i = 99
				movl	$99, -296(%ebp)
				jmp	.L9
		.L20:
		.LBB22:
   89 ! MovLE  R2,#99
   90   %finish
   91
   92   %if 11 <= i <= 100 %start     ;! Peter's special case when both const is good
				movl	-296(%ebp), %eax
				movl	%eax, -276(%ebp)
				cmpl	$10, -276(%ebp)
				jle	.L22
				cmpl	$100, -276(%ebp)
				jg	.L23
		.LBE23:
				nop
				jmp	.L15
		.L23:
				nop
		.L15:
		.LBE24:
   93 ! Sub   R2,#11                  ;! but usually corrupts a register needed later
   94 ! CmpS  R2,#100-11
   95     i = 1
				movl	$1, -296(%ebp)
				jmp	.L15
		.L12:
		.L22:
		.LBB24:
   96 ! MovLS R2,#1
   97   %finish
   98
   99 ! Str   R0,b
  100   write(a,0)
				movl	-300(%ebp), %eax
				subl	$8, %esp
				pushl	$0
				pushl	%eax
				call	_imp_writeint@PLT
				addl	$16, %esp
		.LBB25:
		.LBB26:
				call	_imp_newline@PLT
		.LBE26:
		.LBE25:
  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	-296(%ebp), %eax
				subl	$8, %esp
				pushl	$0
				pushl	%eax
				call	_imp_writeint@PLT
				addl	$16, %esp
		.LBB27:
		.LBB28:
				call	_imp_newline@PLT
		.LBE28:
		.LBE27:
  110 ! Bl    write
  111
  112   newline
  113 ! Bl    newline
  114
  115   write(b,0)
				movl	-292(%ebp), %eax
				subl	$8, %esp
				pushl	$0
				pushl	%eax
				call	_imp_writeint@PLT
				addl	$16, %esp
		.LBB29:
		.LBB30:
				call	_imp_newline@PLT
				movl	$0, -272(%ebp)
		.LBE30:
		.LBE29:
		.LBB31:
		.LBB32:
				subl	$12, %esp
				pushl	-272(%ebp)
				call	exit@PLT
		.LBE32:
		.LBE31:
		.LFE189:
				.section	.text.__x86.get_pc_thunk.bx,"axG",@progbits,__x86.get_pc_thunk.bx,comdat
				.globl	__x86.get_pc_thunk.bx
				.hidden	__x86.get_pc_thunk.bx
		__x86.get_pc_thunk.bx:
		.LFB190:
				movl	(%esp), %ebx
				ret
		.LFE190:
		.Letext0:
  116 ! Ldr   R0,b
  117 ! Bl    write
  118
  119   newline
  120 ! Bl    newline
  121
  122 %endofprogram
   24 Statements compiled
