Retro - 40 best procedures: Search for the string.

ZX Review #7-8-9-10
       8.6. String Search


  Length: 155

  Number of variables: 2

  Checksum: 17221

  Purpose: This program searches through the BASIC program and 
writes each line, containing a set of characters defined by the 
user. 

  Variables:

     Name: data start

     Length: 2

     Cell: 23296

     Comment: The address of the first
bytes of data.

     Name: string length

     Length: 1

     Cell: 23298

     Comment: The number of characters per line.

     Calling the program:

     RANDOMIZE USR address

  Error checking: If no BASIC program or a character string has 
zero length - return to BASIC.


  Comment: time
This program is proportional to
two quantities: the length of the string
variable-length-BASIC program. Search term must
be placed in the cell above
RAMTOP, and the address of the first byte
line should be placed in
23,296 cells / 7. String length
should be kept in a cell
23298.


   LISTING machine code
Assembly label number to VVODA147.


       RES 0, (IY +2) 253 203 2134

       LD IX, (23296) 221 42 0 91

       LD HL, (23635) 42 83 92
RESTAR LD A, (23 298) 58 February 1991

       LD E, A 95

       CP 0254 0

       RET Z 200

       PUSH HL 229
RESTOR PUSH IX 221229

       POP BC 193

       LD D, 0 22 0

       INC HL 35

       INC HL 35

       INC HL 35
CHECK INC HL 35

       PUSH DE 213

       LD DE, (23627) 237 91 75 92

       AND A 167

       SBC HL, DE 237 82

       ADD HL, DE 25

       POP DE 209

       JR C, ENTER 56 4

       POP HL 225

       RET 201
LONG_J JR RESTAR 24223
ENTER LD A, (HL) 126

       CP 13254 1913

       JR NZ, NUMBER 32 5

       INC HL 35

       POP BC 193

       PUSH HL 229

       JR RESTOR 24221
NUMBER CALL 6326 205 182 1924

       JR NZ, COMPAR 32 8

       DEC HL 1943
DIFFER PUSH IX 221229

       POP BC 193

       LD D, 0 22 0

       JR CHECK 24216
COMPAR LD A, (BC) 10

       CP (HL) 190

       JR NZ, DIFFER 32245

       INC BC 3

       INC D 20

       LD A, D 122

       CP E 187

       JR NZ, CHECK 32206

       LD A, 13 62 13

       RST 16215

       POP HL 225

       PUSH HL 229

       LD B, (HL) 70

       INC HL 35

       LD L, (HL) 110

       LD H, B 96

       LD DE, 1000 17 232 3

       LD A, 47 62 47
THOUS INC A 60

       AND A 167

       SBC HL, DE 237 82

       JR NZ, THOUS 48250

       ADD HL, DE 25

       RST 16215

       LD DE, 100 17 100 0

       LD A, 47 62 47
HUNDR INC A 60

       AND A 167

       SBC HL, DE 237 82

       JR NC, HUNDR 48250

       ADD HL, DE 25

       RST 16215

       LD DE, 17 October 1910 0

       LD A, 47 62 47
TENS INC A! 60

       AND A 167

       SBC HL, DE 237 82

       JR NC, TENS 48250

       ADD HL, DE 25

       RST 16215

       LD A, L 125

       ADD A, 48 198 1948

       RST 16215

       POP HL 225

       INC HL 35

       INC HL 35

       INC HL 35
140.
NEXT_C INC HL 35

       LD A, (HL) 126
LINEND CP 13254 1913

       JR NZ, CHR_14 32 4

       RST 16215

       INC HL 35

       JR LONG_J 24155
CHR_14 CALL 6326 205 182 1924

       JR Z, LINEND 40243

       CP 32254 1932

       JR C, NEXT_C 56237

       RST 16215

       JR NEXT_C 24 23
2

  How it works:

  Bit 0 bytes stored in
at 23,612, dropped to the characters that appear in print,
appears at the top of the screen. In IX load address of the 
first byte of data. This allows you to load the address to 
another pair of registers, using less printer buffer.

In HL load address of the beginning
BASIC program.

  As the battery is loaded length of the reference line and the 
value is copied to the E-register. If string length is 0, the 
program returns to BASIC. Address in the HL

pushed onto the stack, holding the position of the unknown at 
the moment strings in memory.


  Address data is copied from the IX
in BC for greater accessibility. In
D-register is loaded 0, ie
number of found characters
equivalent entered data.
A pair of registers increases HL
3, indicating the high byte
pointer to the string length. HL increased, pointing to the 
next character. A pair of registers, DE stored in the stack.


  In DE loads the address of the variables, and this value is 
subtracted from the HL. If the result negative, the program 
goes to ENTER after the restoration of HL and the return of the 
stack DE. If the result was positive, the stack is restored

to its original size and return to BASIC, because reached the 
end of BASIC program. 

  The procedure ENTER in the battery loaded byte is stored at 
the address in HL. If it is not sign ENTER, the transition to a 
NUMBER. If the trait ENTER found, HL increases, pointing to the 
next line. Address of the previous row is removed from the 
stack and replaced with a new value in HL. Then becomes

transition to RESTOR. The procedure
NUMBER routine is called
ROM, which is located there at 6326. If the battery symbol is a 
sign of NUMBER (CHR_14), HL increases, pointing to the first 
character after pyatibaytnogo number representation, certain 
routine ROM. If the sign of NUMBER is not detected, the program 
goes to COMPAR, otherwise HL decreases

program goes to DIFFER. BC
copied from IX, the number of
characters found dumped
to 0 and a transition is made to CHECK.

  The procedure COMPAR in the battery loaded byte is stored at 
in BC. If this is not the same thing as byte is stored at the 
address in HL, the program returns to DIFFER.


  BC increases, indicating
the next byte of data, and the amount of certain characters
increases. If this value is not equal to the length of a 
character line, the program returns to

CHECK.

  As the battery is loaded code
sign ENTER, and this value
prints, using
RST command 16. Address Line
print boots from
stack in the HL. Line number and then
copied to the HL through the B-register.
In the DE 1000 and loaded into the accumulator value is loaded 
on 1 less than the character code 0.

Battery decreases, and DE
again subtracted from HL as
long as the HL does not become negative. Then DE is added to the
HL, to obtain a positive
residue. Symbol of the battery
printed.

  The above method is repeated and then to 100 and DE = DE = 
10. The residue was then loaded into the battery, added 48, and 
as a result of the symbol is printed. 

  Address of the start line is restored from the stack and 
loaded in HL. Then HL is increased,

pointing to a byte pointer to the string length, HL increased, 
and the byte address in HL loaded into the accumulator. If

This byte is not a sign ENTER, a transition is made to
CHR_14, otherwise ENTER displayed on the
printing. HL increases and the program returns to RESTAR.

  The procedure is called CHR_14
ROM routine at 6326.
If the battery symbol is a sign of the number, HL increases, 
pointing to the first symbol appearing after the found number. 
This character is loaded into the battery, and a transition is 
made to LINEND. Then, if the character in the accumulator has 
the code less than 32, the subroutine

returns to NEXT_C. If the code is
more than 31, found the symbol is printed and proisodit 
transition to NEXT_C.