-
Notifications
You must be signed in to change notification settings - Fork 6
/
omult27.a
38 lines (35 loc) · 933 Bytes
/
omult27.a
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
; omult27.a
; from Starship Command at 0x0fa8 (and $10be): http://www.level7.org.uk/miscellany/starship-command-disassembly.txt
;
; 16 bit x 8 bit unsigned multiply, 16 bit result (high bytes)
; Average cycles: 444.00
; 22 bytes
input_fraction = $02 ;
input_pixels = $03 ;
multiplier = $04 ;
output_low = $05 ;
output_high = $06 ;
* = $0200
; 16 bit x 8 bit unsigned multiply, 16 bit result (high bytes)
;
; On Entry:
; (input_fraction, input_pixels): 16 bit multiplicand
; multiplier: 8 bits
; On Exit:
; (output_fraction, output_pixels): 16 bit product
mult
lda #0
ldx #16 ; 16-bit multiplication of input by multiplier
loop_over_bits_of_input
lsr input_pixels
ror input_fraction
bcc input_bit_unset
clc
adc multiplier
input_bit_unset
ror
ror output_low
dex
bne loop_over_bits_of_input
sta output_high
rts