cpu 6502
output scode
nam Multiply
page 128,128
	
* = $033C  ; assemble int the Cassette Buffer $033C (828 dec)
code
	;;  MAIN CODE
	;; multiplicand

.start  lda #$00		;reset data
	sta .rh
	sta .rl
	sta .mh
	sta .index
	lda .int1		;A = multiplier
	sta .ml			;.ml = multiplier (low byte)
	lda #$01		;reset the whichbit
	sta .whichbit
.top	lda #$08		;i=8
	cmp .index		;is index=i?
	beq .end		;if it is , goto end
	lda .whichbit		;get which bit
	bit .int2		;if it's true, then don't add
	beq .noone		;if it's zero, then add
	clc			;clear the carry flag
	lda .rl			;A = result low byte
	adc .ml			;Add multiplier low byte to A
	sta .rl			;store the result back in .rl
	lda .rh
	adc #$00		;add the carry flag to the high byte
	sta .rh
	clc			;clear the carry flag
	lda .rh			;A = high byte of result
	adc .mh			;add multiplier high byte to A
	sta .rh			;store the result back in .rh
.noone	clc			;clear the carry flag
	lda .ml			;A = multiplier Low Byte
	asl			;Shift A left 1 bit
	sta .ml			;Store A back in .ml
	lda .mh			;A = multiplier High Byte
 	rol			;Use Roll so that Carry from last shift
				;gets into Multiplier High Byte
	sta .mh			;Store A back in .mh
	lda .whichbit		;Shift the Test Bit 1 to the left
	asl
	sta .whichbit
	inc .index
	clc
	jmp .top
.end	rts
	
.index		db $00
.whichbit 	db $01

.mh		db $00
.ml		db $00
	
	;; multiplier
.int1	db $00			;930 (dec)
	;; multiplicand
.int2	db $00			;931 (dec)
	;; result high byte
.rh	db $00			;932 (dec)
	;; result low byte
.rl	db $00			;933 (dec)

code
