; Simple multiply function
	.ORIG	x3000
	LD	R0, X	; Load the two pieces of data
	LD	R1, Y
	JSR	MULT1	; Multiply R0 and R1, giving R2
	HALT

X	.FILL 5
Y	.FILL 42


; Function which multiplies R0 and R1, giving R2.
; Note: Only works for R1 strictly positive.
; Also, will not work if answer is bigger than will fit in signed 16-bit number.
MULT1	ST	R1, SAVE_R1	; Save register that will be modified
	AND	R2, R2, #0	; Start by clearing the answer

				; Every time through the following loop,
				; we add R0 to R2.
				; Then we decrement R1 until it reaches zero.
LOOP	ADD	R2, R2, R0
	ADD	R1, R1, #-1
	BRp	LOOP		; Loop if not done yet.
				; Done. R2 now equals R0 times (original) R1.

	LD	R1, SAVE_R1	; Restore register
	RET

SAVE_R1	.BLKW	1		; Save R1 here

	.END

	