         Edinburgh IMP77 Compiler - Version 8.4
    1 %begin
				.section	".text"
		.Ltext0:
				.align 4
				.global main
				.proc	04
		main:
		.LFB185:
				.register	%g2, #scratch
				.register	%g3, #scratch
				.register	%g7, #ignore
		.LVL0:
				save	%sp, -768, %sp
		.LVL1:
				ldx	[%g7+40], %g1
				stx	%g1, [%fp+2039]
				mov	0, %g1
    2
				mov	%i1, %o1
				call	_imp_initialise, 0
				 mov	%i0, %o0
		.LVL2:
				add	%fp, 1635, %g2
    3   ! the example in https://www.ancientgeek.org.uk/EMAS/EMAS_Papers/The_IMP_language_and_compiler.pdf
    4   %integer i, j, k, n
    5
    6   n = 42 ; ! a little initialisation has been added which was not explicit in the paper to avoid runtime errors.
    7
    8   %integer %array a(0:100), b(0:n)
    9
   10   a(n) = n %for n = 0, 1, 100
   11   b(n) = n %for n = 0, 1, 42
				mov	-1, %g1
		.LVL3:
		.L2:
   12   write(n,3); newline
				mov	-1, %g1
		.LVL5:
		.L3:
				add	%g1, 1, %g1
		.LVL6:
				mov	3, %o1
				call	_imp_writeint, 0
				 mov	42, %o0
		.LVL7:
		.LBB11:
		.LBB12:
				call	_imp_newline, 0
				 mov	0, %i5
		.LVL8:
				add	%fp, 1639, %g2
				add	%fp, 1471, %g1
				add	%fp, 1639, %g4
		.LBE12:
		.LBE11:
				mov	0, %o0
		.LVL9:
		.L5:
		.LBB13:
   13
				cmp	%g1, 100
				bne,pt	%icc, .L2
				 add	%g2, 4, %g2
				add	%fp, 1463, %g2
   14   n = 42
				add	%g1, 1, %g1
		.LVL4:
				cmp	%g1, 42
				bne,pt	%icc, .L3
				 add	%g2, 4, %g2
		.L4:
   15
				st	%g1, [%g2]
		.LDL1:
   16   j = 0; k = 0;
				st	%g1, [%g2]
		.LDL2:
		.LDL3:
   17
   18   %cycle i = 1, 1, n
   19     j = j + a(i)
				lduw	[%g2], %g3
				add	%o0, %g3, %o0
		.LVL10:
   20     k = k + b(i+1)        ;! should cause a runtime error since i+1 == n+1 and array b is 0:n ...
				lduw	[%g1], %g3
				add	%i5, %g3, %i5
		.LVL11:
		.LDL4:
				add	%g1, 4, %g1
   21   %repeat
   22
   23   write(j, 5); write(k, 5); newline
				cmp	%g1, %g4
				bne,pt	%xcc, .L5
				 add	%g2, 4, %g2
		.L6:
		.LBE13:
				mov	5, %o1
				call	_imp_writeint, 0
				 sra	%o0, 0, %o0
		.LVL12:
   24
				mov	5, %o1
				call	_imp_writeint, 0
				 sra	%i5, 0, %o0
		.LVL13:
		.LBB14:
		.LBB15:
				call	_imp_newline, 0
				 nop
		.LVL14:
		.LBE15:
		.LBE14:
		.LBB16:
		.LBB17:
				call	exit, 0
				 mov	0, %o0
		.LVL15:
		.LBE17:
		.LBE16:
				nop
		.LFE185:
		.Letext0:
   25 %endofprogram
   19 Statements compiled
