I have written, what I hope is a simple multiplication routine to multiply 2 bytes, returning a word. This could obviously be very useful for calculating screen addresses.

Just want to check that what I have come up with is as efficient as possible, so I would like some of you gurus to have a quick look over it please.

First up, I have designated these locations for custom maths routines I may come up with:

Code: Select all

```
; First operand for custom maths routines
#define MATHOP1 $00
; Second operand for custom math routines
#define MATHOP2 $02
; Answer from custom maths routines
#define MATHRES $04
```

Code: Select all

```
; Multiply routine
;
; This routine multiplies two bytes together,
; resulting in a word.
;
; Pass the two arguments via (Page 0 addresses):
; MATHOP1 ($00)
; MATHOP2 ($02)
;
; The jump to the subroutine:
; multiply
;
; The answer is held in (Page 0 address):
; MATHRES ($04)
; and MATHRES+1 ($05)
;
; Corrupts the following registers:
; P, X, A
;
; Corrupts the following memory locations:
; MATHOP1
Multiply
.(
cld
lda #0
sta MATHRES
sta MATHRES + 1
ldx #8
multloop asl MATHRES
rol MATHRES + 1
asl MATHOP1
bcc multnext
clc
lda MATHOP2
adc MATHRES
sta MATHRES
lda MATHRES + 1
adc #0
sta MATHRES + 1
multnext dex
bne multloop
rts
.)
```