The ";" symbol introduces a comment below.

	; start with n=N-1
	MOV 500, R0
	DEC R0

	; constant for DIV instruction below
	MOV# 2, R4

OLOOP:	; compute (n**2+n)/2 into R2
	; must DIV into an even register
	MOV R0, R1
	MUL R0, R1
	BVS OVERFLOW
	ADD R0, R1
	BVS OVERFLOW
	MOV R1, R2
	DIV R4, R2

	; subtract 1..n from R2
	; descending loop index is kept in R1
	MOV R0, R1
ILOOP:	SUB R1, R2
	BVS COUNTER  ; an overflow at this point indicates a counterexample
	DEC R1
	BGT ILOOP
	; subtracting 0 from R2 is unnecessary

	; we've now computed RHS-LHS into R2
	TST R2
	BNE COUNTER

	DEC R0
	BGT OLOOP

	; no counterexamples found for the 1..N-1 cases.
	; Let's just say that the 0 case has been verified by hand.
	MOV# -1, R0
	HALT

COUNTER:; counterexample found
	; the n is in R0
	HALT

OVERFLOW:; overflowed when calculating n**2+n
	MOV# -2, R0
	HALT


[on to problem #4]