         Edinburgh IMP77 Compiler - Version 8.4
    1 %begin
				NO_APP
		.Ltext0:
				.align	2
				.globl	main
		main:
		.LFB185:
		.LVL0:
		 		link.w %fp,#-576
		 		move.l %a2,-(%sp)
		 		move.l %d2,-(%sp)
    2
		 		move.l 12(%fp),-(%sp)
		 		move.l 8(%fp),-(%sp)
		 		jsr _imp_initialise
		.LVL1:
		 		addq.l #8,%sp
		 		lea (-404,%fp),%a0
    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
		 		moveq #-1,%d0
		.LVL2:
		.L2:
   12   write(n,3); newline
		 		moveq #-1,%d0
		.LVL5:
		.L3:
		 		addq.l #1,%d0
		.LVL6:
		 		pea 3.w
		 		pea 42.w
		 		jsr _imp_writeint
		.LVL7:
		.LBB11:
		.LBB12:
		 		jsr _imp_newline
		.LVL8:
		 		lea (-400,%fp),%a0
		 		lea (-568,%fp),%a1
		 		moveq #-25,%d1
		 		not.b %d1
		 		add.l %fp,%d1
		 		addq.l #8,%sp
		.LBE12:
		.LBE11:
		 		clr.l %d0
   13
		 		moveq #100,%d1
		 		cmp.l %d0,%d1
		 		jne .L2
		 		lea (-576,%fp),%a0
		.LVL4:
   14   n = 42
		 		addq.l #1,%d0
		.LVL3:
		 		moveq #42,%d1
		 		cmp.l %d0,%d1
		 		jne .L3
		.L4:
   15
		 		move.l %d0,(%a0)+
		.LDL1:
   16   j = 0; k = 0;
		 		move.l %d0,(%a0)+
		.LDL2:
		.LDL3:
   17
		 		clr.l %d2
		.LVL9:
		.L5:
		.LBB13:
   18   %cycle i = 1, 1, n
   19     j = j + a(i)
		 		add.l (%a0)+,%d0
		.LVL10:
   20     k = k + b(i+1)        ;! should cause a runtime error since i+1 == n+1 and array b is 0:n ...
		 		add.l (%a1)+,%d2
		.LVL11:
		.LDL4:
   21   %repeat
   22
   23   write(j, 5); write(k, 5); newline
		 		cmp.l %a0,%d1
		 		jne .L5
		.L6:
		.LBE13:
		 		pea 5.w
		 		move.l %d0,-(%sp)
		 		lea _imp_writeint,%a2
		 		jsr (%a2)
		.LVL12:
   24
		 		pea 5.w
		 		move.l %d2,-(%sp)
		 		jsr (%a2)
		.LVL13:
		.LBB14:
		.LBB15:
		 		jsr _imp_newline
		.LVL14:
		.LBE15:
		.LBE14:
		.LBB16:
		.LBB17:
		 		clr.l -(%sp)
		 		jsr exit
		.LVL15:
		.LBE17:
		.LBE16:
		.LFE185:
		.Letext0:
   25 %endofprogram
   19 Statements compiled
