home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
ftp.barnyard.co.uk
/
2015.02.ftp.barnyard.co.uk.tar
/
ftp.barnyard.co.uk
/
cpm
/
walnut-creek-CDROM
/
ZSYS
/
SIMTEL20
/
SYSLIB
/
SLIB3.LBR
/
SMTH11.Z80
< prev
next >
Wrap
Text File
|
2000-06-30
|
2KB
|
96 lines
;
; SYSLIB Module Name: SMTH11
; Author: Richard Conn
; SYSLIB Version Number: 3.6
; Module Version Number: 1.1
public mulhd
;
; MULHD -- MULTIPLY HL BY DE, RESULT IN HL
; CARRY SET MEANS OVERFLOW
; A IS DESTROYED
;
MULHD:
PUSH AF
PUSH BC ; SAVE REGS
PUSH DE
XOR A ; SET NO OVFL
LD (OVFL),A
PUSH HL ; SAVE HL
LD HL,0 ; ZERO LONG ACC
LD (ACC),HL
POP HL ; GET HL
LD B,16 ; 16 LOOPS
MLHD:
CALL SHFTRH ; SHIFT RIGHT MULTIPLIER
JP NC,MLHD1 ; DON'T ADD IN IF LSB IS ZERO
PUSH HL ; SAVE VALUE
LD HL,(ACC)
LD A,L ; ADD IN MULTIPLICAND
ADD A,E
LD L,A
LD A,H
ADC A,D
LD H,A
LD (ACC),HL ; NEW ACCUMULATED VALUE
JP NC,MLHD0
LD A,0FFH ; SET OVFL FLAG
LD (OVFL),A
MLHD0:
POP HL ; GET VALUE
MLHD1:
EX DE,HL ; SHIFT LEFT MULTIPLICAND
CALL SHFTLH
EX DE,HL
DEC B ; COUNT DOWN
JP NZ,MLHD
POP DE ; RESTORE REGS
POP BC
LD HL,(ACC) ; GET RESULT
LD A,(OVFL) ; OVERFLOW?
OR A ; 0=NO
JP Z,OKRET
OVFLRET:
POP AF ; GET PSW
SCF ; SET CARRY
RET
OKRET:
POP AF
OR A ; CLEAR CARRY
RET
;
; SHIFT ROUTINES
;
SHFTRH: ; SHIFT RIGHT
PUSH AF
AND A ; CLEAR CARRY
LD A,H ; SHIFT HIGH
RRA ; ROTATE 9-BIT ACC RIGHT
LD H,A
LD A,L ; SHIFT LOW
RRA
LD L,A
JP NC,OKRET
JP OVFLRET
SHFTLH: ; SHIFT LEFT
PUSH AF
AND A ; CLEAR CARRY
LD A,L ; SHIFT LOW
RLA ; ROTATE 9-BIT ACC LEFT
LD L,A
LD A,H ; SHIFT HIGH
RLA
LD H,A
JP NC,OKRET
JP OVFLRET
;
; BUFFERS
;
ACC: DS 2 ; TEMP ACCUMULATOR
OVFL: DS 1 ; OVERFLOW FLAG
END