Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ;;
- ; Multiplies two 8-bit factors to produce a 16-bit product
- ; in about 153 cycles.
- ; @param A one factor
- ; @param Y another factor
- ; @return high 8 bits in A; low 8 bits in $0000
- ; Y and $0001 are trashed; X is untouched
- .proc mul8
- factor2 = TempVal+1
- prodlo = TempVal
- ; Factor 1 is stored in the lower bits of prodlo; the low byte of
- ; the product is stored in the upper bits.
- lsr a ; prime the carry bit for the loop
- sta prodlo
- sty factor2
- lda #0
- ldy #8
- loop:
- ; At the start of the loop, one bit of prodlo has already been
- ; shifted out into the carry.
- bcc noadd
- clc
- adc factor2
- noadd:
- ror a
- ror prodlo ; pull another bit out for the next iteration
- dey ; inc/dec don't modify carry; only shifts and adds do
- bne loop
- ldy TempVal
- rts
- .endproc
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement