home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
norge.freeshell.org (192.94.73.8)
/
192.94.73.8.tar
/
192.94.73.8
/
pub
/
computers
/
cpm
/
alphatronic
/
PASCALZ4.ZIP
/
D3
/
MULT.SRC
< prev
next >
Wrap
Text File
|
1999-04-05
|
2KB
|
116 lines
;MULTIPLY ROUTINES
;
NAME MULT
ENTRY .QMULT,.IMULT
EXT .MLTERR
;
;
;MULTIPLY REQUIRES THE A REGISTER TO BE 0
;THE MULTIPLIER MUST BE IN DE AND THE MULTIPLICAND MUST BE IN HL
;FAST MULTIPLY -- NO ERROR CHECKING
.QMULT: CMP D ;OPTIMIZATION SECTION...
JRZ OPT ;...CHECK FOR A ZERO HIGH BYTE
MVI B,17 ;17 FOR A LONG MULTIPLY
CMP H
JRNZ NOOPT ;CAN'T FIND ONE
XCHG
OPT: MVI B,9 ;ONLY DO NINE SHIFTS
MOV D,E
NOOPT: MOV A,B ;NUMBER OF SHIFTS
MOV B,H ;COPY HL -> BC
MOV C,L
LXI H,0 ;CLEAR RESULT
MLOOP: DCR A ;CHECK SHIFT COUNTER
RZ
DAD H ;SHIFT PARTIAL RESULT
SLAR E ;SHIFT MULTIPLIER
RLAR D
JRNC MLOOP ;NEXT SHIFT
DAD B ;ADD IN MULTIPLICAND
JR MLOOP
;
;
.IMULT: MOV A,H ;SAVE SIGN OF RESULT
XRA D
PUSH PSW
;MAKE BOTH OPERANDS POSITIVE
BIT 7,D
JRZ CANDP ;MULTIPLICAND POSITIVE
MOV A,D
CMA
MOV D,A
MOV A,E
CMA
MOV E,A ;MAKE POSITIVE
INX D
CANDP: BIT 7,H
JRZ CAND0 ;MULTIPLIER POSITIVE
MOV A,H
CMA
MOV H,A
MOV A,L
CMA
MOV L,A ;MAKE POSITIVE
INX H
;IS THE MULTIPLICAND 0?
CAND0: XRA A
CMP H
JRNZ SETUP
CMP L
JRNZ OP2ONE
;MULTIPLICAND IS ZERO
POP PSW ;SIGN
XRA A
RET
;IS MULTIPLICAND 1 OR -1
OP2ONE: DCR L
INX H
JRNZ SETUP
;IT'S A ONE, WHAT'S THE SIGN?
POP PSW ;SIGN OF RESULT
XCHG
XRA H
MOV A,D ;CLEAR ACC
RP ;SIGN STAYS THE SAME
;CHANGE THE SIGN
JR CSIGN
SETUP: MOV B,D
MOV C,E
XCHG
MOV H,A
MOV L,A
;MULTIPLY LOOP
MCONT: SRAR B ;SHIFT MULTIPLICAND
RRAR C
JRNC MTEST
DAD D
BIT 7,H
JNZ .MLTERR ;JUMP TO OVERFLOW ERROR ROUTINE
MTEST: MOV A,B
ORA C
JRZ MLTDON
XCHG
DADC H
XCHG
JNV MCONT
JMP .MLTERR
;DONE MULTIPLY
MLTDON: POP PSW ;SIGN OF RESULT
MOV A,C ;CLEAR ACC
RP
CSIGN: XCHG
XRA A
MOV H,A
MOV L,A
DSBC D
RET