Created
May 3, 2011 23:07
-
-
Save neuro-sys/954442 to your computer and use it in GitHub Desktop.
6502 multiplier
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
processor 6502 | |
prod EQU $0380 | |
multiplier EQU $0381 | |
multiplicand EQU $0382 | |
INCLUDE basic.rom | |
INCLUDE common.asm | |
+autoRun | |
; mul.er prod | |
; 00101000 00000000 | |
; 01010000 00000000 | |
; 10100000 00000000 | |
;C 01000000 00110000 | |
; 10000000 01100000 | |
;C 00000000 11110000 | |
; 00000001 11100000 | |
; 00000011 11000000 | |
; 00000111 10000000 | |
ldx #48 ; 00110000 | |
lda #40 ; 00101000 | |
;a * x -> prod (low), multiplier(high) | |
stx multiplicand | |
sta multiplier | |
lda #$0 | |
sta prod | |
ldx #$08 | |
n: | |
asl prod | |
rol multiplier ; add the carry from prod to multiplier | |
bcc noadd | |
lda prod | |
clc | |
adc multiplicand | |
sta prod | |
noadd: | |
dex | |
bne n | |
ldx prod | |
lda multiplier | |
jsr linprt | |
rts | |
ECHO * |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment