ack/mach/6500/libem/mli.s

75 lines
1.2 KiB
ArmAsm
Raw Permalink Normal View History

1984-12-17 11:03:13 +00:00
.define Mli2, Mlinp, Mul
1987-01-30 18:41:42 +00:00
.sect .text
.sect .rom
.sect .data
.sect .bss
.sect .text
1984-12-17 11:03:13 +00:00
! The subroutine Mli2 multiplies two signed integers. The integers
! are popped from the stack.
! The subroutine Mlinp expects the two integer to be in zeropage.
! While the subroutine Mul an unsigned multiply subroutine is.
! For the algoritme see A. S. Tanenbaum
! Structured Computer Organisation. 1976.
Mli2:
stx ARTH
sta ARTH+1
jsr Pop
stx ARTH+2
sta ARTH+3
Mlinp: ldy #1
sty UNSIGN ! it's signed
lda ARTH+1
bpl 3f ! multiplier negative so:
ldx ARTH
jsr Ngi2 ! negate multiplier
stx ARTH
sta ARTH+1
ldx ARTH+2
lda ARTH+3
jsr Ngi2 ! negate multiplicand
stx ARTH+2
sta ARTH+3
Mul:
3: lda #0
sta ARTH+4
sta ARTH+5
sta ARTH+6
sta ARTH+7 ! clear accumulator
ldy #16
1988-08-19 17:05:03 +00:00
1: lda #0x01
1984-12-17 11:03:13 +00:00
bit ARTH
beq 2f ! multiplying by zero: no addition
clc
lda ARTH+6
adc ARTH+2
sta ARTH+6
lda ARTH+7
adc ARTH+3
sta ARTH+7
2: lsr ARTH+1
ror ARTH ! shift multiplier
lsr ARTH+7
ror ARTH+6
ror ARTH+5
ror ARTH+4 ! shift accumulator
lda UNSIGN
beq 3f ! unsigned multiply: so no shift in of signbit
lda ARTH+3
bpl 3f
1988-08-19 17:05:03 +00:00
lda #0x40
1984-12-17 11:03:13 +00:00
bit ARTH+7
beq 3f
lda ARTH+7
1988-08-19 17:05:03 +00:00
ora #0x80
1984-12-17 11:03:13 +00:00
sta ARTH+7
3: dey
bne 1b
ldx ARTH+4
lda ARTH+5
rts