Skip to content

Commit 5422f06

Browse files
committed
Minor optimization to multiplication code.
1 parent 33d5402 commit 5422f06

1 file changed

Lines changed: 13 additions & 11 deletions

File tree

src/interp/mul.asm

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -33,29 +33,31 @@
3333
.segment "RUNTIME"
3434

3535
.proc EXE_MUL ; AX = (SP+) * AX
36-
sta tmp1
37-
stx tmp1+1
38-
lda stack_l, y
36+
; Store A
3937
sta tmp3
40-
ldx stack_h, y
41-
stx tmp3+1
4238

43-
; Multiply "tmp1 * tmp3"
39+
; Get first bit into carry
40+
lda stack_h, y
41+
lsr
42+
sta tmp1+1
43+
lda stack_l, y
44+
ror
45+
sta tmp1
46+
4447
lda #0
4548
sta tmp2+1
4649
ldy #16 ; Number of bits
4750

48-
lsr tmp1+1
49-
ror tmp1 ; Get first bit into carry
5051
@L0: bcc @L1
5152

5253
clc
5354
adc tmp3
54-
tax
55-
lda tmp3+1
55+
sta tmp2
56+
57+
txa
5658
adc tmp2+1
5759
sta tmp2+1
58-
txa
60+
lda tmp2
5961

6062
@L1: ror tmp2+1
6163
ror

0 commit comments

Comments
 (0)