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
/
SETCON.SRC
< prev
next >
Wrap
Text File
|
1999-04-05
|
4KB
|
140 lines
;SUBROUTINES FOR SET CONSTRUCTION,UNION,MEMBERSHIP,AND INTERSECTION
;
NAME SETCON
ENTRY .CONSET,.RCSET,.UNION,.INN,.INSECT
EXT .SAVREG
;
; CONSET : A SUBROUTINE THAT SETS THE RELEVANT BIT(S) IN A SET TO INDICATE
; THE PRESENCE OF THAT ELEMENT IN THE SET.
;
;
; IF THE REPETITION COUNT IS NEGATIVE, IGNORE IT AND RETURN IMMEDIATELY
; NO BITS ARE SET IN THIS CASE.
;
.RCSET:
; IS THE REPETITION COUNT NEGATIVE ?
MOV A,L ; HIGH BOUND OF RANGE
SUB E ; LESS LOW BOUND OF RANGE
JRZ LEGRNG ; IF NON-ZERO AND CARRY FLAG SET -- YES
RC
LEGRNG: INR A ; CORRECT RANGE
MOV C,A ; SAVE IT IN C REG
JR TOPSET
; DOING ONE ELEMENT
.CONSET: MVI C,1 ; INDICATE A SINGLE ELEMENT, NOT A RANGE
TOPSET: LXI H,33 ; ALL SETS ARE 32 BYTES
DAD S ; HL -> FIRST BYTE OF THE SET
MOV A,E ; SAVE VALUE IN A
SRLR E ;; DE = VALUE
SRLR E
SRLR E ; DE = NUMBER OF BYTES OFFSET FROM START OF SET
ORA A ; CLEAR CARRY, SAVE VALUE
DSBC D ;; HL -> BYTE ON STACK
ANI 7 ; POSITION WITHIN BYTE
MVI E,1 ; START WITH BIT 0
; CPI 0 ;; IS IT BIT 0 ? ( ZERO FLAG SET/CLEARED BY ANI )
JRZ SINIT ;; YES -- DONE
MOV B,A ; B = BIT POSITION
SETBIT: SLAR E ;; ROTATE TO THE CORRECT BIT
DJNZ SETBIT
SINIT: MOV B,C ;; GET RANGE
MOV A,M ;; GET BYTE IN ACC
RANGE: ORA E ;; SET BIT
SLAR E ;; GO TO THE NEXT BIT
JRNC NOOVER ;;
MOV M,A ;; IF OVERFLOW, SAVE BYTE AND
MVI E,1 ; START AGAIN WITH BIT 0 OF THE NEXT BYTE
DCX H ;;
MOV A,M
NOOVER: DJNZ RANGE
MOV M,A ;; SAVE BYTE
XRA A
RET
; UNION : A ROUTINE THAT TAKES THE UNION OF TWO SETS ON THE STACK AND
; STORES IT IN THE FIRST SET -- THE ONE AT THE HIGHER LOCATION ON
; THE STACK.
;
;
.UNION:
CALL .SAVREG ; SET UP POINTERS
; HL -> START OF FIRST SET
; DE -> START OF SECOND SET
ORBIT: MOV A,M ;; GET BYTE FROM 2ND SET
XCHG
ORA M ;; OR WITH BYTE FROM 1ST SET
XCHG
MOV M,A ;; SAVE IT
DCX H ; GO ON TO NEXT BYTE
DCX D
DJNZ ORBIT
POP D ; DE = RETURN ADDRESS
LXI H,32 ; ALL SETS ARE 32 BYTES
DAD S ;; REMOVE THE 2ND SET FROM THE STACK
SPHL
XCHG ; HL = RETURN ADDRESS
XRA A
PCHL
; INN : A ROUTINE TO TEST FOR THE MEMBERSHIP OF AN ELEMENT IN A SET.
;
;
.INN: LXI H,34
DAD S ;; POINT TO VAR - ABOVE RET. ADDR. AND 32 BYTE SET
MOV B,A
MOV C,M
MOV A,C ; A AND C REGS CONTAIN THE VALUE OF THE ELEMENT
DCX H ;; HL -> FIRST BYTE OF SET
SRLR C ;; CALCULATE THE LOCATION IN THE SET
; OF THE ELEMENT
SRLR C
SRLR C
ORA A ;; CLEAR CARRY - SAVE VALUE IN A
DSBC B ;; POINT TO RELEVANT BYTE IN SET
ANI 7
MOV B,A ;; GET POSITION WITHIN SET
MVI A,1 ; START WITH BIT 0 IN THE BYTE
JRZ SET2 ;; IF ZERO THEN DONE ( ZERO FLAG SET/CLEARED BY ANI )
SET1: ADD A ;; ROTATE TO CORRECT BIT POSITION
DJNZ SET1
SET2: ANA M ;; SEE IF BIT IS SET
POP D ; RETURN ADDRESS
LXI H,34
DAD S ; REMOVE SET ( 32 BYTES ) AND VARIABLE
SPHL
XCHG ; RETURN ADDRESS -> HL
JRZ NOTIN ;; IF ZERO THEN NOT IN SET( SET/CLEARED BY ANA )
STC ;;IS IN THE SET
NOTIN: MVI A,0
PCHL
;
; INSECT : A ROUTINE TO TAKE THE INTERSECTION OF TWO SETS ON THE STACK AND
; STORE THE RESULT IN THE FIRST. INTERSECTION IS EQUIVALENT TO THE LOGICAL
; AND OF TWO SETS.
;
.INSECT:
CALL .SAVREG
; HL -> FIRST SET
; DE -> SECOND SET
ANDBIT:
LDAX D
ANA M
MOV M,A
DCX H
DCX D
DJNZ ANDBIT
POP D ; DE = RETURN ADDRESS
LXI H,32
DAD S ; REMOVE SECOND SET FROM STACK
SPHL
XCHG ; HL = RETURN ADDRESS
XRA A
PCHL