	; R0 := R0 / R1, remainder in R2, R1 is positivised
	; R0 is top, shifted into R2 one bit at a time.
	; R3 is the loop counter.
DIVIDE:
	MOV	R2,-(SP)
	MOV	R3,-(SP)
	TST	R1	; Validate divisor
	BEQ	DIV0	; divide by 0!
	BPL	DIV1
	NEG	R1
DIV1:
	CLR	R2
	MOV	#15.,R3		; 16 iterations
DIV2:
	ASL	R0
	ROL	R2
	CMP	R2,R1		; can we subtract bottom from top?
	BCS	DIV3		; no
	SUB	R1,R2		; yes - do it.
	BIS	#1,R0
DIV3:	DEC	R3
	BPL	DIV2

DIVEND:	MOV	(SP)+,R3
	MOV	(SP)+,R2
	RTS	PC

DIV0:	; divide by 0.  return 0. (any other ideas?)
	CLR	R0
	BR	DIVEND
; end of DIVIDE
