-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmultiplication_8bit.asm
52 lines (48 loc) · 1.05 KB
/
multiplication_8bit.asm
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
org $3400
lda $41
tay
lda #0
sta $41
sta $42
sta $43
check_bit_for_mult
tya
beq mult_done
lsr
tay
bcc double_1st_num
lda $42
clc
adc $40
sta $42
lda $43
adc $41
sta $43
double_1st_num
asl $41
asl $40
bcc check_bit_for_mult
inc $41
jmp check_bit_for_mult
mult_done
; Optimalized solution - it starts from multiplier's MSB bit instead of LSB (the previous solution)
;
; lda #0
; sta $43
; ldx #8
; double_prod
; asl ; Double product's LSB byte for every multiplier's bit
; rol $43 ; Double product's MSB byte with getting of overflow from LSB
; asl $40 ; Double multiplier
; bcc next_bit ; Don't add multiplicand to product for multiplier's bit = 0
; clc
; adc $41 ; Add multiplicand to product for multiplier 1
; bcc next_bit
; inc $43 ; Increase product's MSB as LSB overflowed
; next_bit
; dex
; bne double_prod
; sta $42 ; Store product's LSB
org $40
.by $6f, $61
; Result of multiplication is in ($42, $43)