ZX Review #7-8-9-10
08 ноября 1997

Retro - 40 best procedure: Find the string.

<b>Retro</b> - 40 best procedure: Find the string.
      8.8. Substring search


  Length: 168

  Number of variables: 0

  Checksum: 19875

  Purpose: This program returns the position of the substring 
(B $) in the main line (A $), or 0 on failure.


  Calling the program:

     LET P = USR address

  Error checking: If Line
does not exist, or if the length
substring is zero, or if
length of the substring is greater than the length of the main 
line program returns 0. If no error, but the substring was not 
found in the main line, the program also gives 0.


  Comment: after leaving the
program in the native variable P (can use any other variable) 
will hold the desired value. Line, which made treatment can not 
be arrays data. To change the number of used lines marked with 
"*" 

should be changed. 66 * - this is
substring, 65 * - the main line.
To change these numbers need to replace code required
characters. For example, if you want to find a position in the 
H $ G $, then respectively, will need to enter 71 (code G) and 
72 (code H). 


   LISTING machine code
Assembly label number to VVODA147.


       SUB A 151

       LD B, A 71

       LD C, A 79

       LD D, A 87

       LD E, A 95

       LD HL, (23627) 42 75 92
NEXT_V LD A, (HL) 126

       CP 128 254 128

       JR Z, NOT_FD 40 95

       BIT 7, A 203 127

       JR NZ, FOR_NX 32 41

       CP 96254 1996

       JR NC, NUMBER 48 29

       CP 65 254 65 *

       JR NZ, SUBSTR 32 2

       LD D, H 84

       LD E, L 93
SUBSTR CP 66254 66 *

       JR NZ, CHECK 32 2

       LD B, H 68

       LD C, L 77
CHECK LD A, D 122

       OR E 179

       JR Z, STRING 40 4

       LD A, B 120

       OR C 177

       JR NZ, FOUND 32 38
STRING PUSH DE 213

       INC HL 35

       LD E, (HL) 94

       INC HL 35

       LD D, (HL) 86
ADD ADD HL, DE 25

       POP DE 209

       JR INCRS May 24
NUMBER INC HL 35

       INC HL 35

       INC HL 35

       INC HL 35

       INC HL 35
INCRS INC HL 35

       JR NEXT_V 24206
FOR_NX CP 224 254 224

       JR C, N_BIT 56 6

       PUSH DE 213

       LD DE, 18 17 18 0

       JR ADD 24234
N_BIT BIT 5, A 203 111

       JR Z, STRING 40225
NEXT_B INC HL 35

       BIT 7, (HL) 203 126

       JR Z, NEXT_B 40251

       JR NUMBER 24227
FOUND EX DE, HL 235

       INC HL 35

       INC HL 35

       PUSH HL 229

       PUSH HL 229

       INC BC 3

       PUSH BC 197

       LD A, (BC) 10

       LD E, A 95

       INC BC 3

       LD A, (BC) 10

       LD D, A 87

       OR E 179

       JR Z, ZERO 40 11

       PUSH DE 213

       LD A, (HL) 126

       DEC HL 1943

       LD L, (HL) 110

       LD H, A 103

       AND A 167

       SBC HL, DE 237 82

       JR NC, CONTIN 48 8

       POP BC 193
ZERO POP BC 193

       POP BC 193
ERROR POP BC 193
NOT_FD LD BC, 0 1 0 0

       RET 201
CONTIN POP IX 221225

       POP BC 193

       EX DE, HL 235

       POP HL 225

       INC BC 3

       INC BC 3
SAVE INC HL 35

       PUSH HL 229

       PUSH BC 197

       PUSH IX 221229

       PUSH DE 213
COMPAR LD A, (BC) 10

       CP (HL) 190

       JR Z, MATCH 40 12

       POP DE 209

       POP IX 221225

       POP BC 193

       POP HL 225

       LD A, D 122

       OR E 179

       JR Z, ERROR 40225

       DEC DE 1927

       JR SAVE 24,234
MATCH INC HL 35

       INC BC 3

       PUSH HL 229

       DEC IX 221 1943

       PUSH IX 221229

       POP HL 225

       LD A, H 124

       OR L 181

       POP HL 225

       JR NZ, COMPAR 32227

       POP DE 209

       POP DE 209

       AND A 167

       SBC HL, DE 237 82

       POP DE 209

       POP DE 209

       POP DE 209

       AND A 167

       SBC HL, DE 237 82

       LD B, H 68

       LD C, L 77

       RET 201
2

  How it works:

  In the battery, a pair of registers
BC and DE register pair is loaded 0. Later in the program
BC will be set to address B $, and
in DE will be set address A $.
In HL load address of the beginning
of program variables.

  As the battery is loaded bytes
from the address in HL.
If the battery contains the number 128, the program jumps to
NOT_FD, because reached the end of the program variables.
If bit 7 of the accumulator is set to 1, a transition is made to
FOR_NX, because found variable - not a string and not a number,
whose name consists only of
one letters. If the battery
contains a number greater than 95,
made the transition to a NUMBER.

  To achieve this phase
line must be found. If
in the accumulator contains the number
65, is determined by the location of the string A $, and the 
contents of HL copied to the DE. If the battery contains the 
number 66, is determined by the string B $, and HL is copied to 
the BC. If DE is not equal to 0 and BC is not equal to 0, 
determined the location of both lines, and the program jumps to 
FOUND. 

  If the program reaches a procedure STRING, DE stored in the
the stack and loads the long lines found. This amount is added 
to the address pointer high byte string and stored in the HL. 
DE recovered from the stack and made the transition to INCRS.


  The procedure NUMBER HL increases 5 times, pointing to the 
last byte of the number found. HL then increases, indicating

the following variable, and a transition to NEXT_V.

  The procedure FOR_NX, if the battery contains a number of 
smaller than 224, a transition is made to

N_BIT, because encountered variable is not controllable
loop variable FOR-NEXT. If
accumulator value is greater
than 223, then the number 18 is added to the HL, pointing to 
the last bytes of the loop variable, and the program returns to 
INCRS. 

  If the program reaches N_BIT
and bit 5 of the battery is installed
to 0, a transition is made to STRING,
to get the HL address of the next variable, because found
array.

  If the program reaches NEXT_
B, found the number with a name that
more than one character in length.
Thus, HL is increased
until then, until the point to the
the last character of variable name, and then made the 
transition to NUMBER.


  The procedure FOUND in HL is loaded row address A $, and this
value increases twice
to get the address of the senior
byte pointers. This value
then stored on the stack twice. BC increases, indicating
at low byte pointers substring B $. Address to BC then stored 
in the stack. In DE loaded length of the string B $ and if this 
value is 0, is go to ZERO. DE then pushed onto the stack. In HL 
load length of the string A $, and if this value is not smaller 
than DE, the program jumps to CONTIN. The stack pointer is then 
reduced in BC is loaded 0 the program returns to BASIC.


  The procedure CONTIN in IX established the length of the 
string B $, and BC put the address young

Byte pointer to the substring
B $. In DE load difference
lengths of strings A $ and B $, but loaded HL address high byte
Pointers to A $. BC then increased twice to get the address of 
first character in substring B $. HL increases

pointing to the next character
string A $. HL, BC, IX and DE is then stored on the stack. As 
the battery is loaded byte at the BC, and if this value is 
equal to the byte at the address in HL, a transition is made to 
MATCH. DE, IX, BC and then HL recovered from the stack. If

DE contains a 0, a transition is made
for ERROR, because substring B $ is not in
string A $. Counter DE decreases, and the program returns to
SAVE.

  If the program reaches a procedure MATCH, HL and BC are 
increasing, pointing to the next symbol A $ and B $, 
respectively. HL is then stored in the stack.

IX, the counter decreases, and after recovery from HL Stack
If IX does not contain 0, the program returns to COMPAR.

  To achieve this phase
locate substrings B $ in
string A $ is to be determined. The length of the substring B $ 
is subtracted from the HL, and then address strarshego byte 
pointers for string A $ is subtracted from the HL. The result - 
a position of the substring B $ in the string A $. This value 
is copied into the register pair BC, and the program returns to 
BASIC. 


           *


  Ending print books Dzh.Hardmana and E. Hyuzona "40 best
procedures, we would like to give
small comment, which
On the format of the program variables in the Spectrum. The 
point that the procedures outlined in this last final block, 
commonly operate with them. Those who do not have firm 
instructions on the Spectrum (Book Vickers), may be a

this format and unfamiliar, and we
in his works still get by this issue is not addressed. Those 
who are interested in this question, can read your comment. 


   Data format in the Spectrum


  Data is stored in a Spectrum
as variables and arrays
specially designated for this
memory area. This area begins directly behind the area in which 
located text of the BASIC program.


  At the beginning of the program
variable indicates the double-byte system variable VARS.
It is located at 23267
(5AE3H).

  End of program variables is given a special marker - a byte 
whose value is 80H (128). 

  Spectrum distinguishes several
different types of variables. They are:

  - The usual numeric variable
whose name consists of one
letters, eg x;

  - A numerical variable whose name consists of more than one 
letter, for example, row; 

  - A numeric array, for example,
a (5) or b (3,3,40);

  - Variables that control the cycles FOR ... NEXT, for 
example, 1; 

  - String variables, eg, a $;

  - String arrays, for example,
b $ (10,40).


      Numeric variable

    with the name of one letter


  Occupies 6 bytes. In the first
byte kept her name in the next five - its value in the integral 
form. On the integral representation of real numbers, see 
"Programming native. "The first byte

has the following layout:



    0 1 1 b to have in a



  That this is a simple variable, indicates a specific
location of the first three bits.


  A numeric variable named

    more than one letter


  Her first byte has the following format:



    1 0 1 b to have in a



  Other bytes of the name (except the last) have the following 
format: 



    0 in y to a well. .



  The last byte of name:



    1 b to have a well. .



  For the name followed by 5 bytes
expressions of the numbers in the integral form.


        Numeric array


  First byte:



    1 0 0 b y k in a



  Bytes 2 and 3 contain a complete
length of all elements (5 bytes for each array element)
plus 2 bytes for each dimension of the array, plus one byte
to specify the number of dimensions, ie it contains
indication of the end of the array.

  Byte 4 contains the dimension
array.

  Bytes 5 and 6 contain a number of elements in the first 
dimension. If the dimension of the array more than 1, then:


  Bytes 7 and 8 contain a number of elements in the second 
dimension, etc. Then go themselves array elements: five bytes 
for each element. For multidimensional arrays, the order

the data rate is as follows:
b (1,1), b (1,2), b (1,3), b (2,1) ...
b (3,3).


        Loop variables


  First byte:



    1 1 1 b to have in a



  Next:

  5 bytes - the current value;

  5 bytes - the final value;

  5 bytes - step;

  2 bytes - number of rows returned
            TA;

  1 byte - number of operators in
line to which you are
return.


     Character variable


  First byte:



    0 1 0 b y k in a



  Next:

  2 bytes - length of string;

  x bytes - text string.


       Character array


  First byte:



    1 1 0 b y k in a



  Next:

  2 bytes - an indication of the end
array;

  1 byte - the dimension;

  2 bytes - length in the first dimension;

  ..............................

  2 bytes - length of the latter
dimension.

  Next: one byte for each element.







Other articles:

TR-DOS for beginners - The end.

Computer novella - Prince of Persia.

Computer novella - Laser team (the game Laser Squad).

Crossing Dragon - Game Rapscallion.

Crossing Dragon - Playing The Runes of Zendos.

Crossing Dragon - Playing The Saga.

Crossing Dragon - Game Witch's Cauldron.

Crossing Dragon - Create Adventyuru. Review of the editors.

Crossing Dragon - Create a dictionary to Adventyurnoy game.

Program, which we choose - The possible consequences of using undocumented commands.

Program, which we choose - About noticed irregularities in some programs and suggestions for future versions.

Program, which we choose - A proposal to all the authors of software, printers, memory dump. Programmers protect discs from being copied.

Program, which we choose - A few suggestions to improve the assembly.

Program, which we choose - Suggestions for refining ZX Word v2.5.

Program, which we choose - The "Spectrum emulator" v1.2.

Program, which we choose - What could want in a perfect assembly.

Retro - 40 best procedures: Copying data in memory.

Retro - 40 best procedures: Exchange token.

Retro - 40 best procedures: Determination addresses BASIC string.

Retro - 40 best procedures: Determination of the length of BASIC programs.

Retro - 40 best procedures: Determination of the amount of free memory.

Retro - 40 best procedures for: Search and replace strings.

Retro - 40 best procedure: Find the string.

Retro - 40 best procedures: Search for the string.

Retro - 40 best procedures: the list of variables.

Retro - 40 best procedures: an increase and up the screen.

Retro - 40 best treatments: Removal of REM-strings.

Retro - 40 best procedures: Remove the block of the program.

Expert Tips - Game Fredloader.

Expert Tips - Game Robin of Sherwood: The Touchstones of Rhianon.

Expert Tips - Game Scorpions: Die Machines.

Expert Tips - Game Terropods.

page iS-DOS - Description of system restarts IS DOS.

Forum - An algorithm for recognizing characters.

Forum - Time undocumented command processor Z80.

Forum - The concept of a high-color screen resolution.

Forum - A few Pokes to a game. Program Hacman96.

Forum - As for the new DOS and BIOS settings for the Spectrum.

Forum - Multicolor program on any computer model. Using the 2 nd screen Multicolor'a. Demonstration of the text. Electronic journals.

Forum - Project ZX Config.

Forum - Improve Art Studio. Ideas on file compression.

Forum - ZX Spectrum emulator for IBM. About the hexadecimal system. Program ZX-Stars. Oddities in the Elita

Forum - The effects on the curb and Multicolor.

reader-reader - ZX Spectrum 128 - new opportunities, new challenges.

reader-reader - With 'Light'. Spectrum and expert system.

reader-reader - The printer driver for the Scorpion.

reader-reader - Print numbers in different number systems.

reader-reader - Programming arcade game with scrolling screen.

reader-reader - The procedure for printing labels assembler XAS to monitor debugger STS 4.3.

Studies - attribute scrolling text. "Gasilka" screen. A simplified version of the procedure, "Curtain". Procedure is enriched with pictures. Procedure display images on the points.

Studies - Graphic effect "color bars".

Studies - Driver screen printing 64 characters per line.

Studies - Set of protective boot.

Studies - Address to the drive mode IM 2. Working with non-standard disc format.

Studies - Print the character, magnified by 8 times. The program "pouring" screen. The procedure for screen-saver on the points. Clear screen in Terminator'e. Search strings in memory. System character set conversion.

Studies - Program - cataloger of disks.

Studies - Program the output values of the amplitude channel music. coprocessor on the curb.

Studies - Program the output image.

Studies - The program plugs sprite.

Studies - Cleanup of the specified window screen.

Studies - The program sort the array in ascending order. The procedure for filling the screen specified attribute. Procedure display pictures. The effect of moving towards the stars. "Shower", coming from the upper left corner of the screen. The procedure of "shedding" pictures on the pixel lines. The program of "pulling" the picture at an angle of 45 degrees. Three procedures "Scroll".

Studies - The printing of numbers.

Studies - The procedure for drawing a character with attributes.

Studies - The procedure for display pictures. Fade-OUT effect (picture goes beyond the edge of the screen). Visual effect "Fountain." Fade-OUT effect, mimicking the TV off. Procedure "Ignition" pictures. The program continuously drawing a picture.

Studies - The procedure for drawing a line.

Studies - The procedure for making optimal symbol table.

Studies - scrolling lines of text in the specified window. Attribute scroller. Diagonal scrolling.

Studies - sprite scroller. Procedure display screen.

Studies - Short procedure indicating the amplitude channel music. coprocessor. Way to subtract a constant from a register pair HL.

Studies - The formula for calculating the day of the week.


Темы: Игры, Программное обеспечение, Пресса, Аппаратное обеспечение, Сеть, Демосцена, Люди, Программирование

Similar articles:
Softinka - Editor of two screen graphics DouBleScreen Editor v0.4.
Advertising - Advertisements and announcements ...
Advertising - advertising and announcements.
Review - New Games: TIME COP, UFO III, MORTAL COMBAT, MINELAYER, SEX REVERSY, THE MAGIC OF LOGIC, FEUDAL WARS, CUP AVILLIADY, CHOPPER DUEL, BACK TO SCHOLL, LCP, 750 CC GRANDPRX, INTERNA- TIONAL KIKBOXING, TAG TEAM WRESTLING, CAPTAIN PLANET, DOC THE DESTRUE DUX, OLE, TORO!.

В этот день...   4 May