-
Notifications
You must be signed in to change notification settings - Fork 8
Expand file tree
/
Copy pathmult34.a
More file actions
51 lines (46 loc) · 1.91 KB
/
mult34.a
File metadata and controls
51 lines (46 loc) · 1.91 KB
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
; mult34.a
; from Atari Roots, by Mark Andrews (1984) https://archive.org/details/ataribooks-atari-roots/page/n169/mode/2up
; from the first slower version, see mult35 for the corresponding faster version.
; also available at https://www.atariarchives.org/roots/chapter_10.php
; see also 'Microelectronic systems N2 checkbook' by R E Vears (1990) https://archive.org/details/microelectronics0000vear_q3o0/page/146/mode/2up
;
; 8 bit x 8 bit unsigned multiply, 16 bit result
; Average cycles: 280
; 36 bytes
* = $0200
mpr = $02 ; multiplier
mpd1 = $03 ; multiplicand
mpd2 = $04 ; new multiplicand after 8 shifts
prodl = $05 ; low byte of product
prodh = $06 ; high byte of product
*=$0200
; ***************************************************************************************
; On Entry:
; mpr: multiplier
; mpd1: multiplicand
; On Exit:
; prodl: low byte of product
; prodh: high byte of product
mult
clc
lda #0 ; clear accumulator
sta mpd2 ; clear address for shifted multiplicand
sta prodl ; clear low byte of product address
sta prodh ; clear high byte of product address
ldx #8 ; we will use the x register as a counter
loop
lsr mpr ; shift multiplier right; lsb drops into carry bit
bcc noadd ; test carry bit; if zero, branch to noadd
clc
lda prodl
adc mpd1 ; add low byte of product to multiplicand
sta prodl ; result is new low byte of product
lda prodh ; load accumulator with high byte of product
adc mpd2 ; add high part of multiplicand
sta prodh ; result is new high byte of product
noadd
asl mpd1 ; shift muliplicand left; bit 7 drops into carry
rol mpd2 ; rotate carry bit into bit 7 of mpd2
dex ; decrement contents of x register
bne loop ; if result isn't zero, jump back to loop
rts