         Edinburgh IMP77 Compiler - Version 8.4
    1 !
				.section .mdebug.abi32
				.previous
				.nan	legacy
				.module	fp=xx
				.module	nooddspreg
				.abicalls
		$Ltext0:
				.align	2
				.globl	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
				.set	nomips16
				.set	nomicromips
				.ent	main
		main:
				.frame	$sp,48,$31		# vars= 16, regs= 1/0, args= 16, gp= 8
				.mask	0x80000000,-4
				.fmask	0x00000000,0
				.set	noreorder
				.set	nomacro
				LVL0 = .
				addiu	$sp,$sp,-48
				sw	$31,44($sp)
				lui	$28,%hi(__gnu_local_gp)
				addiu	$28,$28,%lo(__gnu_local_gp)
				.cprestore	16
				lw	$2,%got(__stack_chk_guard)($28)
				lw	$2,0($2)
				sw	$2,36($sp)
   56 %integer a,i,b
				lw	$25,%call16(_imp_initialise)($28)
				.reloc	1f,R_MIPS_JALR,_imp_initialise
			1:	jalr	$25
				nop
				LVL1 = .
				lw	$28,16($sp)
				LVL2 = .
   57
   58   read(a)
				addiu	$4,$sp,24
				lw	$25,%call16(_imp_readint)($28)
				.reloc	1f,R_MIPS_JALR,_imp_readint
			1:	jalr	$25
				nop
				LVL3 = .
				lw	$28,16($sp)
   59 ! BL     read_fn
   60
   61 ! Str    R0,a
   62   read(i)
				addiu	$4,$sp,28
				lw	$25,%call16(_imp_readint)($28)
				.reloc	1f,R_MIPS_JALR,_imp_readint
			1:	jalr	$25
				nop
				LVL4 = .
				lw	$28,16($sp)
   63 ! BL     read_fn
   64
   65 ! Str    R0,i
   66   read(b)
				addiu	$4,$sp,32
				lw	$25,%call16(_imp_readint)($28)
				.reloc	1f,R_MIPS_JALR,_imp_readint
			1:	jalr	$25
				nop
				LVL5 = .
				lw	$28,16($sp)
				LBB14 = .
   67 ! BL     read_fn
   68
   69   %if a <= i <= b %start
   70 ! Ldr R1,a
   71 ! Ldr R2,i
   72 ! CmpS   R1,R2
				lw	$2,28($sp)
				LVL6 = .
				lw	$4,24($sp)
				slt	$3,$2,$4
				bne	$3,$0,$L2
				slt	$3,$2,22
   73 ! CmpSLE R2,R0
   74     i = 22
				lw	$3,32($sp)
				slt	$3,$3,$2
				bne	$3,$0,$L3
				slt	$3,$2,22
				LBE14 = .
				li	$2,22			# 0x16
				LVL7 = .
				sw	$2,28($sp)
				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
				bne	$3,$0,$L17
				slt	$2,$2,78
				LVL11 = .
				L4 = .
				LBE16 = .
				LBB17 = .
				beq	$3,$0,$L13
				lw	$3,32($sp)
				LVL15 = .
		$L7:
				LBE18 = .
				LBB19 = .
				lw	$2,28($sp)
				addiu	$2,$2,-11
		$L18:
				sltu	$2,$2,90
				bne	$2,$0,$L14
				li	$2,1			# 0x1
				LVL16 = .
		$L8:
				LBE19 = .
   82 ! MovGT  R2,#44
   83   %finish
				lw	$2,32($sp)
				slt	$2,$2,22
				bne	$2,$0,$L16
				lw	$2,28($sp)
				LVL9 = .
		$L5:
				LBE15 = .
				slt	$2,$3,$2
				LVL25 = .
				beq	$2,$0,$L5
				lw	$2,28($sp)
				LBE28 = .
   84
   85   %if a <= i <= 77 %start
   86 ! CmpS   R1,R2
   87 ! CmpSLE R2,#77
   88     i = 99
				lw	$2,28($sp)
				LVL12 = .
		$L16:
				slt	$3,$2,$4
				bne	$3,$0,$L7
				slt	$2,$2,78
				LVL13 = .
		$L17:
   89 ! MovLE  R2,#99
   90   %finish
				beq	$2,$0,$L7
				li	$2,1			# 0x1
				.option	pic0
				b	$L8
				.option	pic2
				sw	$2,28($sp)
				LVL14 = .
		$L2:
				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
				li	$2,1			# 0x1
		$L14:
				.option	pic0
				b	$L8
				.option	pic2
				sw	$2,28($sp)
				LVL10 = .
		$L3:
				LBB16 = .
				.option	pic0
				b	$L18
				.option	pic2
				addiu	$2,$2,-11
				.set	macro
				.set	reorder
				.end	main
		$LFE185:
		$Letext0:
   96 ! MovLS R2,#1
   97   %finish
   98
   99 ! Str   R0,b
  100   write(a,0)
				move	$5,$0
				lw	$25,%call16(_imp_writeint)($28)
				.reloc	1f,R_MIPS_JALR,_imp_writeint
			1:	jalr	$25
				nop
				LVL17 = .
				lw	$28,16($sp)
				LBB20 = .
				LBB21 = .
				lw	$25,%call16(_imp_newline)($28)
				.reloc	1f,R_MIPS_JALR,_imp_newline
			1:	jalr	$25
				nop
				LVL18 = .
				lw	$28,16($sp)
				LBE21 = .
				LBE20 = .
  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)
				move	$5,$0
				lw	$4,28($sp)
				lw	$25,%call16(_imp_writeint)($28)
				.reloc	1f,R_MIPS_JALR,_imp_writeint
			1:	jalr	$25
				nop
				LVL19 = .
				lw	$28,16($sp)
				LBB22 = .
				LBB23 = .
				lw	$25,%call16(_imp_newline)($28)
				.reloc	1f,R_MIPS_JALR,_imp_newline
			1:	jalr	$25
				nop
				LVL20 = .
				lw	$28,16($sp)
				LBE23 = .
				LBE22 = .
  110 ! Bl    write
  111
  112   newline
  113 ! Bl    newline
  114
  115   write(b,0)
				move	$5,$0
				lw	$4,32($sp)
				lw	$25,%call16(_imp_writeint)($28)
				.reloc	1f,R_MIPS_JALR,_imp_writeint
			1:	jalr	$25
				nop
				LVL21 = .
				lw	$28,16($sp)
				LBB24 = .
				LBB25 = .
				lw	$25,%call16(_imp_newline)($28)
				.reloc	1f,R_MIPS_JALR,_imp_newline
			1:	jalr	$25
				nop
				LVL22 = .
				lw	$28,16($sp)
				LVL23 = .
				LBE25 = .
				LBE24 = .
				LBB26 = .
				LBB27 = .
				move	$4,$0
				lw	$25,%call16(exit)($28)
				.reloc	1f,R_MIPS_JALR,exit
			1:	jalr	$25
				nop
				LVL24 = .
		$L13:
				LBE27 = .
				LBE26 = .
				LBB28 = .
  116 ! Ldr   R0,b
  117 ! Bl    write
  118
  119   newline
  120 ! Bl    newline
  121
  122 %endofprogram
   24 Statements compiled
