Personal Computer News


Variable Find

 
Author: Shingo Sugiura
Published in Personal Computer News #099

No need to spend eye-watering, carpet-chewing hours debugging a program. Try Shingo Sugiura's machine code utility.

Problem Locations

No need to spend eye-watering, carpet-chewing hours debugging a program. Try Shingo Sugiura's machine code utility

Anyone debugging programs often needs to find the occurrence of a particular variable or a particular string. The obvious way is to list the program and look through it line by line while pressing the SHIFT-CTRL combination. However, this method can be pretty frustrating. This short machine code routine helps you.

First, you must set page to &1A00 (or &F00 if you have a tape-based machine). This is necessary because the object code is assembled at &1900 and would overwrite the source code. Type in the program carefully (tape users, change line 60 to PAGE=&E00). Save the program before you run it.

If all is well, it will print out instructions for you to save the object code. Object code saved in this way may be *RUN at the beginning of a hacking session but once it's loaded, Break must be pressed to initialise the routine. This automatically moves up the value of PAGE so the machine code routine won't be corrupted by your Basic program.

To use the routine, type: *LINE A$ (RETURN) where A$ is the string you want to search for. As soon as you press RETURN, the routine checks that there is a basic program and then goes through each line of the program checking for the occurrence of A$. Every time there's a match, that line is listed.

The search process is extremely quick so you may miss some of the lines as they scroll off the screen. To prevent this, press CTRL and SHIFT simultaneously. The problem with this utility is that you lose one page of memory (0.25K) but I'm sure you'll find that a small sacrifice.

This utility intercepts Break. This is done so that PAGE is incremented by two pages whenever the Break key (or even CTRL-BREAK) is pressed. Also, the user vector is reset to point to the actual search routine so that *LINE invokes the utility. If you want to reinitialise the machine, type *FX247 (RETURN) and press Break (or switch the machine off).

How It Works

There are two main differences in writing a basic search routine. First, it must be fast so that means writing in machine code, which is more difficult. Second, because Basic tokenises keywords to speed up programs and save space), to find a keyword such as GOTO, you can't just search sequentially for characters G, O, T and O. Instead, you must find the token for that keyword (in this case, &E5) and search for that instead.

That may sound easy until you realise that keywords may be abbreviated and the whole routine must be as small as possible. I decided to call the tokenising routine in the Basic routine. The disadvantage is incompatible with different Basics. However, this should not be too much of a problem (surely, there aren't many people who use Basic I and Basic II at the same time?).

Shingo Sugiura

This article was converted to a web page from the following pages of Personal Computer News #099.

Personal Computer News #099 scan of page 18

Page 18

Personal Computer News #099 scan of page 19

Page 19