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
/
SYSLIB.LBR
/
SYSLIBJ.HQP
/
SYSLIBJ.HLP
Wrap
Text File
|
2000-06-30
|
21KB
|
633 lines
Branching Introduction
ACase Case via Reg A: ACASE1, ACASE2, ACASE3
HCase Case via Reg Pair HL: HCASE1, HCASE2, HCASE3
AGoto Computed GOTO via Reg A: AGOTO1, AGOTO2, BGOTO1, BGOTO2
HGoto Computed GOTO via RP HL: HGOTO1, HGOTO2, DGOTO1, DGOTO2
Aif Arithmetic IF via Reg A: AIF1, AIF2
Hif Arithmetic IF via RP HL: HIF1, HIF2
:Branching
Thσ routine≤ iε thi≤ sectioε dea∞ witΦ conditiona∞ branchinτ ì
vißá CASE¼á ComputeΣá GOTO¼á anΣ Arithmetiπ I╞á constructs«á Thσ ì
following example illustrates the case concept:
< register A = key value >
CALL ACASE1
DB SIZE ; NUMBER OF ENTRIES IN TABLE
DW ERROR ; GO HERE IF NO MATCH
DB VAL1 ; FIRST VALUE TO TEST FOR
DW ADDR1 ; GO HERE IF A = VAL1
DB VAL2 ; 2ND VALUE TO TEST FOR
DW ADDR2 ; GO HERE IF A = VAL2
...
DB VAL$SIZE ; 'SIZE' VALUE TO TEST FOR
DW ADDR$SIZE ; GO HERE IF A = VAL$SIZE
The following example illustrates the Computed GOTO:
< register A = index (zero-relative) >
CALL AGOTO1
DW ADDR0 ; GO HERE IF A = 0
DW ADDR1 ; GO HERE IF A = 1
...
DW ADDRN ; GO HERE IF A = N
Thσá followinτá examplσ illustrate≤ thσ ComputeΣá GOT╧á witΦ ì
limits:
< register A = index (zero-relative) >
< register B = limit >
CALL AGOTO1
DW ADDR0 ; GO HERE IF A = 0
DW ADDR1 ; GO HERE IF A = 1
...
DW ADDRN ; GO HERE IF A = N
< error code > ; RESUME AFTER DW ADDRN IF A > B
The following example illustrates the Arithmetic IF:
< register A = key value >
< register B = test value >
CALL AIF1
DW ADDRLT ; GO HERE IF A < B
DW ADDREQ ; GO HERE IF A = B
DW ADDRGT ; GO HERE IF A > B
Seσ thσ SYSLI┬ tes⌠ prograφ STEST014.MA├ fo≥ example≤ oµ usσ ì
of all of the branching routines.
The following routines are provided:
Routine Comments
======= ========
ACASE1 Case statement with A = key value
ACASE2 Like ACASE1, but DE = address of case table
ACASE3 Like ACASE2, but return address is left on stack
HCASE▒ Likσ ACASE1¼ bu⌠ H╠ ╜ ke∙ value
HCASE2 Like ACASE2, but HL = key value
HCASE3 Like ACASE3, but HL = key value
AGOTO1 Computed GOTO with A = key value
AGOTO2 Like AGOTO1, but JMPs rather than DW follow
HGOTO1 Computed GOTO with HL = key value
HGOTO2 Like AGOTO2, but HL = key value
Routine Comments
======= ========
BGOTO1 Like AGOTO1, but B = limit value
BGOTO2 Like AGOTO2, but B = limit value
DGOTO1 Like HGOTO1, but DE = limit value
DGOTO2 Like HGOTO2, but DE = limit value
AIF1 Arithmetic IF with A, B = values
AIF2 Like AIF1, but JMPs rather than DW follow
HIF1 Arithmetic IF with HL, DE = values
HIF2 Like AIF2, but HL, DE = values
:ACASE Routines
Routine: ACASE1
Function║
ACASE▒ i≤ ß casσ statemen⌠ processor«á Oε input¼ registe≥ ┴ ì
contain≤ ß valuσ t∩ tes⌠ against«á Thi≤ valuσ i≤ compareΣ t∩ thσ ì
value≤á iε ß casσ table¼á and¼á iµ ß matcΦ i≤ found¼á contro∞á i≤ ì
transferreΣá t∩á thσ addres≤ associateΣ witΦ thσ matchinτá value« ì
Thi≤ casσ act≤ a≤ ß multiwa∙ JM╨ instructioε (returε addres≤ froφ ì
thσ cal∞ t∩ ACASE▒ i≤ no⌠ retained).
Example:
MVI A,TEST
CALL ACASE1
DB N ; number of entries in the table
DW DEFAULT ; go to this address if no match
DB VAL1 ; test for TEST = VAL1
DW ADDR1 ; go here if TEST = VAL1
...
DB VALN ; test for TEST = VALN
DW ADDRN ; go here if TEST = VALN
Inputs: A = value to test for
Outputs: None (branch is made)
Registers Affected: None
SYSLIB Routines Called: None
Special Error Conditions: None
Routine: ACASE2
Function║
ACASE▓ i≤ ß casσ statemen⌠ processor«á Oε input¼ registe≥ ┴ ì
contain≤á ß valuσ t∩ tes⌠ agains⌠ anΣ D┼ contain≤ thσ addres≤á oµ ì
thσá casσá table«á Thσ valuσ iε registe≥ ┴ i≤á compareΣá t∩á thσ ì
value≤á iε ß casσ table¼á and¼á iµ ß matcΦ i≤ found¼á contro∞á i≤ ì
transferreΣá t∩á thσ addres≤ associateΣ witΦ thσ matchinτá value« ì
Thi≤ casσ act≤ a≤ ß multiwa∙ JM╨ instructioε (returε addres≤ froφ ì
thσ cal∞ t∩ ACASE▓ i≤ no⌠ retained).
Example:
MVI A,TEST ; value to test for
LXI D,TABLE ; address of table
CALL ACASE2
...
TABLE:
DB N ; number of entries in the table
DW DEFAULT ; go to this address if no match
DB VAL1 ; test for TEST = VAL1
DW ADDR1 ; go here if TEST = VAL1
...
DB VALN ; test for TEST = VALN
DW ADDRN ; go here if TEST = VALN
Inputs: A = value to test for
DE = address of case table
Outputs: None (branch is made)
Registers Affected: None
SYSLIB Routines Called: None
Special Error Conditions: None
Routine: ACASE3
Function║
ACASE│ i≤ ß casσ statemen⌠ processor«á Oε input¼ registe≥ ┴ ì
contain≤á ß valuσ t∩ tes⌠ agains⌠ anΣ D┼ contain≤ thσ addres≤á oµ ì
thσá casσá table«á Thσ valuσ iε registe≥ ┴ i≤á compareΣá t∩á thσ ì
value≤á iε ß casσ table¼á and¼á iµ ß matcΦ i≤ found¼á contro∞á i≤ ì
transferreΣá t∩á thσ addres≤ associateΣ witΦ thσ matchinτá value« ì
Thi≤á casσá act≤ a≤ ß multiwa∙ CAL╠ instructioεá (returεá addres≤ ì
froφ thσ cal∞ t∩ ACASE│ i≤ lef⌠ oε thσ stack).
Example:
MVI A,TEST ; value to test for
LXI D,TABLE ; address of table
CALL ACASE3
< resume execution here if routines execute an RET instr >
...
TABLE:
DB N ; number of entries in the table
DW DEFAULT ; go to this address if no match
DB VAL1 ; test for TEST = VAL1
DW ADDR1 ; go here if TEST = VAL1
...
DB VALN ; test for TEST = VALN
DW ADDRN ; go here if TEST = VALN
Inputs: A = value to test for
DE = address of case table
Outputs: None (branch is made)
Registers Affected: None
SYSLIB Routines Called: None
Special Error Conditions: None
:HCASE Routines
Routine: HCASE1
Function║
HCASE▒ i≤ ß casσ statemen⌠ processor«á Oεá input¼á registe≥ ì
pai≥ H╠ contain≤ ß valuσ t∩ tes⌠ against« Thi≤ valuσ i≤ compareΣ ì
t∩ thσ value≤ iε ß casσ table¼á and¼ iµ ß matcΦ i≤ found¼ contro∞ ì
i≤ transferreΣ t∩ thσ addres≤ associateΣ witΦ thσ matchinτ value« ì
Thi≤ casσ act≤ a≤ ß multiwa∙ JM╨ instructioε (returε addres≤ froφ ì
thσ cal∞ t∩ HCASE▒ i≤ no⌠ retained).
Example:
LXI H,TEST
CALL HCASE1
DW N ; number of entries in the table
DW DEFAULT ; go to this address if no match
DW VAL1 ; test for TEST = VAL1
DW ADDR1 ; go here if TEST = VAL1
...
DW VALN ; test for TEST = VALN
DW ADDRN ; go here if TEST = VALN
Inputs: HL = value to test for
Outputs: None (branch is made)
Registers Affected: None
SYSLIB Routines Called: None
Special Error Conditions: None
Routine: HCASE2
Function║
HCASE▓á i≤ ß casσ statemen⌠ processor«á Oε input¼á registe≥ ì
pai≥á H╠á contain≤ ß valuσ t∩ tes⌠ agains⌠ anΣá D┼á contain≤á thσ ì
addres≤á oµá thσ casσ table«á Thσ valuσ iε registe≥ pai≥á H╠á i≤ ì
compareΣ t∩ thσ value≤ iε ß casσ table¼ and¼ iµ ß matcΦ i≤ found¼ ì
contro∞á i≤á transferreΣá t∩á thσá addres≤á associateΣá witΦá thσ ì
matchinτá value«á Thi≤á casσ act≤ a≤ ß multiwa∙ JM╨á instructioε ì
(returε addres≤ froφ thσ cal∞ t∩ HCASE▓ i≤ no⌠ retained).
Example:
LXI H,TEST ; value to test for
LXI D,TABLE ; address of table
CALL HCASE2
...
TABLE:
DW N ; number of entries in the table
DW DEFAULT ; go to this address if no match
DW VAL1 ; test for TEST = VAL1
DW ADDR1 ; go here if TEST = VAL1
...
DW VALN ; test for TEST = VALN
DW ADDRN ; go here if TEST = VALN
Inputs: HL = value to test for
DE = address of case table
Outputs: None (branch is made)
Registers Affected: None
SYSLIB Routines Called: None
Special Error Conditions: None
Routine: HCASE3
Function║
HCASE│ i≤ ß casσ statemen⌠ processor«á Oεá input¼á registe≥ ì
pai≥á H╠á contain≤á ß valuσ t∩ tes⌠ agains⌠ anΣ D┼á contain≤á thσ ì
addres≤á oµá thσ casσ table«á Thσ valuσ iε registe≥ pai≥á H╠á i≤ ì
compareΣ t∩ thσ value≤ iε ß casσ table¼ and¼ iµ ß matcΦ i≤ found¼ ì
contro∞á i≤á transferreΣá t∩á thσá addres≤á associateΣá witΦá thσ ì
matchinτá value«á Thi≤ casσ act≤ a≤ ß multiwa∙ CAL╠á instructioε ì
(returε addres≤ froφ thσ cal∞ t∩ HCASE│ i≤ lef⌠ oε thσ stack).
Example:
LXI H,TEST ; value to test for
LXI D,TABLE ; address of table
CALL HCASE3
< resume execution here if routines execute an RET instr >
...
TABLE:
DW N ; number of entries in the table
DW DEFAULT ; go to this address if no match
DW VAL1 ; test for TEST = VAL1
DW ADDR1 ; go here if TEST = VAL1
...
DW VALN ; test for TEST = VALN
DW ADDRN ; go here if TEST = VALN
Inputs: HL = value to test for
DE = address of case table
Outputs: None (branch is made)
Registers Affected: None
SYSLIB Routines Called: None
Special Error Conditions: None
:AGOTO (Computed Goto)
Routine: AGOTO1
Function║
AGOTO▒ i≤ ß computeΣ GOTO«á Wheε called¼ registe≥ ┴ ╜ inde° ì
(zero-relative⌐á oµá thσá followinτ addres≤á t∩á brancΦá to«á N∩ ì
informatioε i≤ availablσ oε thσ numbe≥ oµ alloweΣ values¼á s∩á i⌠ ì
i≤á thσ programmer'≤ responsibilit∙ t∩ seσ tha⌠ thσ rangσ oµá thσ ì
Computed GOTO is not exceeded.
Example:
MVI A,INDEX ; Index value
CALL AGOTO1
DW ADDR0 ; GO HERE IF A = 0
DW ADDR1 ; GO HERE IF A = 1
...
DW ADDRN ; GO HERE IF A = N
Inputs: A = index value (zero-relative)
Outputs: None
Registers Affected: None
SYSLIB Routines Called: None
Special Error Conditions: None
Routine: AGOTO2
Function║
AGOTO2 i≤ ß computeΣ GOTO«á Wheε called¼ registe≥ ┴ ╜ inde° ì
(zero-relative⌐á oµá thσá followinτ addres≤á t∩á brancΦá to«á N∩ ì
informatioε i≤ availablσ oε thσ numbe≥ oµ alloweΣ values¼á s∩á i⌠ ì
i≤á thσ programmer'≤ responsibilit∙ t∩ seσ tha⌠ thσ rangσ oµá thσ ì
Computed GOTO is not exceeded.
Example:
MVI A,INDEX ; Index value
CALL AGOTO2
JMP ADDR0 ; RETURN TO THIS JMP IF A = 0
JMP ADDR1 ; RETURN TO THIS JMP IF A = 1
...
JMP ADDRN ; RETURN TO THIS JMP IF A = N
< next instr > ; RETURN TO THIS INSTR IF A = N+1
Inputs: A = index value (zero-relative)
Outputs: None
Registers Affected: None
SYSLIB Routines Called: None
Special Error Conditions: None
Routine: BGOTO1
Function║
BGOTO▒ i≤ ß computeΣ GOTO«á Wheε called¼ registe≥ ┴ ╜ inde° ì
(zero-relative⌐ oµ thσ followinτ addres≤ t∩ brancΦ to«á Registe≥ ì
┬ ╜ maximuφ valuσ alloweΣ fo≥ thσ inde° (registe≥ A)«á Iµ ┴ ╛ B¼ ì
theεá contro∞á i≤ transferreΣ t∩ afte≥ thσ las⌠á addres≤á iεá thσ ì
table.
Example:
MVI A,INDEX ; Index Value
MVI B,LIMIT ; Maximum Index Value
CALL BGOTO1
DW ADDR0 ; GO HERE IF A = 0
DW ADDR1 ; GO HERE IF A = 1
...
DW ADDR$LIMIT; GO HERE IF A = LIMIT
< next instruction >; RETURN TO THIS INSTRUCTION IF A > LIMIT
Inputs: A = index value (zero-relative)
B = maximum index value allowed
Outputs: None
Registers Affected: None
SYSLIB Routines Called: None
Special Error Conditions: None
Routine: BGOTO2
Function║
BGOTO▓ i≤ ß computeΣ GOTO«á Wheε called¼ registe≥ ┴ ╜ inde° ì
(zero-relative⌐ oµ thσ followinτ addres≤ t∩ brancΦ to«á Registe≥ ì
┬ ╜ maximuφ valuσ alloweΣ fo≥ thσ inde° (registe≥ A)«á Iµ ┴ ╛ B¼ ì
theεá contro∞á i≤á transferreΣ t∩ afte≥ thσ las⌠ addres≤á iεá thσ ì
table.
Example:
MVI A,INDEX ; Index value
MVI B,LIMIT ; Maximum Index Value
CALL BGOTO2
JMP ADDR0 ; RETURN TO THIS JMP IF A = 0
JMP ADDR1 ; RETURN TO THIS JMP IF A = 1
...
JMP ADDR$LIMIT; RETURN TO THIS JMP IF A = LIMIT
< next instr > ; RETURN TO THIS INSTR IF A > LIMIT
Inputs: A = index value (zero-relative)
B = maximum index value
Outputs: None
Registers Affected: None
SYSLIB Routines Called: None
Special Error Conditions: None
:HGOTO (Computed Goto)
Routine: HGOTO1
Function║
HGOTO▒ i≤ ß computeΣ GOTO«á Wheε called¼ registe≥ pai≥ H╠ ╜ ì
inde° (zero-relative⌐ oµ thσ followinτ addres≤ t∩ brancΦ to«á N∩ ì
informatioε i≤ availablσ oε thσ numbe≥ oµ alloweΣ values¼á s∩á i⌠ ì
i≤á thσ programmer'≤ responsibilit∙ t∩ seσ tha⌠ thσ rangσ oµá thσ ì
ComputeΣ GOT╧ i≤ no⌠ exceeded.
Example:
LXI H,INDEX ; Index value
CALL HGOTO1
DW ADDR0 ; GO HERE IF HL = 0
DW ADDR1 ; GO HERE IF HL = 1
...
DW ADDRN ; GO HERE IF HL = N
Inputs: HL = index value (zero-relative)
Outputs: None
Registers Affected: None
SYSLIB Routines Called: None
Special Error Conditions: None
Routine: HGOTO2
Function║
HGOTO▓ i≤ ß computeΣ GOTO«á Wheε called¼ registe≥ pai≥ H╠ ╜ ì
inde° (zero-relative⌐ oµ thσ followinτ addres≤ t∩ brancΦ to«á N∩ ì
informatioεá i≤ availablσ oε thσ numbe≥ oµ alloweΣ values¼á s∩ i⌠ ì
i≤á thσ programmer'≤ responsibilit∙ t∩ seσ tha⌠ thσ rangσ oµá thσ ì
ComputeΣ GOT╧ i≤ no⌠ exceeded.
Example:
LXI H,INDEX ; Index value
CALL HGOTO2
JMP ADDR0 ; RETURN TO THIS JMP IF HL = 0
JMP ADDR1 ; RETURN TO THIS JMP IF HL = 1
...
JMP ADDRN ; RETURN TO THIS JMP IF HL = N
< next instr > ; RETURN TO THIS INSTR IF HL = N+1
Inputs: HL = index value (zero-relative)
Outputs: None
Registers Affected: None
SYSLIB Routines Called: None
Special Error Conditions: None
Routine: DGOTO1
Function║
DGOTO▒ i≤ ß computeΣ GOTO«á Wheε called¼ registe≥ pai≥ H╠ ╜ ì
inde°á (zero-relative⌐á oµ thσ followinτ addres≤á t∩á brancΦá to« ì
Registe≥á pai≥ D┼ ╜ maximuφ valuσ alloweΣ fo≥ thσ inde° (registe≥ ì
pai≥ HL)«á Iµ H╠ ╛ DE¼á theε contro∞ i≤ transferreΣ t∩ afte≥ thσ ì
las⌠ addres≤ iε thσ table.
Example:
LXI H,INDEX ; Index Value
LXI D,LIMIT ; Maximum Index Value
CALL DGOTO1
DW ADDR0 ; GO HERE IF HL = 0
DW ADDR1 ; GO HERE IF HL = 1
...
DW ADDR$LIMIT; GO HERE IF HL = LIMIT
< next instruction >; RETURN TO THIS INSTRUCTION IF HL > LIMIT
Inputs: HL = index value (zero-relative)
DE = maximum index value allowed
Outputs: None
Registers Affected: None
SYSLIB Routines Called: None
Special Error Conditions: None
Routine: DGOTO2
Function║
DGOTO▓ i≤ ß computeΣ GOTO«á Wheε called¼ registe≥ pai≥ H╠ ╜ ì
inde°á (zero-relative⌐á oµ thσ followinτ addres≤á t∩á brancΦá to« ì
Registe≥á pai≥ D┼ ╜ maximuφ valuσ alloweΣ fo≥ thσ inde° (registe≥ ì
pai≥ HL)«á Iµ H╠ ╛ DE¼á theε contro∞ i≤ transferreΣ t∩ afte≥ thσ ì
las⌠ addres≤ iε thσ table.
Example:
LXI H,INDEX ; Index value
LXI D,LIMIT ; Maximum Index Value
CALL DGOTO2
JMP ADDR0 ; RETURN TO THIS JMP IF HL = 0
JMP ADDR1 ; RETURN TO THIS JMP IF HL = 1
...
JMP ADDR$LIMIT; RETURN TO THIS JMP IF HL = LIMIT
< next instr > ; RETURN TO THIS INSTR IF HL > LIMIT
Inputs: HL = index value (zero-relative)
DE = maximum index value
Outputs: None
Registers Affected: None
SYSLIB Routines Called: None
Special Error Conditions: None
:AIF (Arithmetic IF with Register A)
Routine: AIF1
Function║
AIF▒ i≤ aε arithmetiπ I╞ facility« ┴ ke∙ valuσ i≤ passeΣ iε ì
thσá ┬á registe≥á anΣ ß tes⌠ valuσ i≤ passeΣ iε thσá ┴á register« ì
Branchinτ i≤ donσ dependinτ oε thσ followinτ tests║ ┴ ╝ B¼ ┴ ╜ B¼ ì
and A > B.
Example:
MVI A,TEST ; test value
MVI B,KEY ; key value
CALL AIF1
DW ALTB ; GO HERE IF A < B
DW AEQB ; GO HERE IF A = B
DW AGTB ; GO HERE IF A > B
Inputs: A = test value
B = key value
Outputs: None
Registers Affected: None
SYSLIB Routines Called: None
Special Error Conditions: None
Routine: AIF2
Function║
AIF2 i≤ aε arithmetiπ I╞ facility« ┴ ke∙ valuσ i≤ passeΣ iε ì
thσá ┬á registe≥á anΣ ß tes⌠ valuσ i≤ passeΣ iε thσá ┴á register« ì
Branchinτ i≤ donσ dependinτ oε thσ followinτ tests║ ┴ ╝ B¼ ┴ ╜ B¼ ì
and A > B.
Example:
MVI A,TEST ; test value
MVI B,KEY ; key value
CALL AIF2
JMP ALTB ; RESUME AT THIS JMP IF A < B
JMP AEQB ; RESUME AT THIS JMP IF A = B
JMP AGTB ; RESUME AT THIS JMP IF A > B
Inputs: A = test value
B = key value
Outputs: None
Registers Affected: None
SYSLIB Routines Called: None
Special Error Conditions: None
:HIF (Arithmetic IF with Register Pair HL)
Routine: HIF1
Function║
HIF▒ i≤ aε arithmetiπ I╞ facility« ┴ ke∙ valuσ i≤ passeΣ iε ì
thσá D┼á registe≥á pai≥á anΣ ß tes⌠ valuσ i≤á passeΣá iεá thσá H╠ ì
registe≥á pair«á Branchinτá i≤ donσ dependinτ oεá thσá followinτ ì
tests║ H╠ ╝ DE¼ H╠ ╜ DE¼ anΣ H╠ ╛ DE.
Example:
LXI H,TEST ; test value
LXI D,KEY ; key value
CALL HIF1
DW HLTD ; GO HERE IF HL < DE
DW HEQD ; GO HERE IF HL = DE
DW HGTD ; GO HERE IF HL > DE
Inputs: HL = test value
DE = key value
Outputs: None
Registers Affected: None
SYSLIB Routines Called: None
Special Error Conditions: None
Routine: HIF2
Function║
HIF▓ i≤ aε arithmetiπ I╞ facility« ┴ ke∙ valuσ i≤ passeΣ iε ì
thσá D┼á registe≥á pai≥á anΣ ß tes⌠ valuσ i≤ passeΣá iεá thσá H╠ ì
registe≥á pair«á Branchinτá i≤ donσ dependinτ oεá thσá followinτ ì
tests║ H╠ ╝ DE¼ H╠ ╜ DE¼ anΣ H╠ ╛ DE.
Example:
LXI H,TEST ; test value
LXI D,KEY ; key value
CALL HIF2
JMP HLTD ; RESUME AT THIS JMP IF HL < DE
JMP HEQD ; RESUME AT THIS JMP IF HL = DE
JMP HGTD ; RESUME AT THIS JMP IF HL > DE
Inputs: HL = test value
DE = key value
Outputs: None
Registers Affected: None
SYSLIB Routines Called: None
Special Error Conditions: None