ZX Classroom - Commands for working with ZX Microdrive

ZX Revija #03

ZX Educational: BASIC / Machine code

Commands for working with ZX Microdrive

ZX Microdrive is a special type of disk drive designed for storing large amounts of data. Commands: CAT, CLOSE#, ERASE, FORMAT, MOVE and OPEN#. Now we will not consider these commands, but when we talk about the ZX Microdrive and its use, we will analyze them in detail.

This concludes the short course on BASIC. Those who want to learn more about BASIC can order the video course BASIC-VIDEO-KURS V 2.00: it costs 40.00 dinars on domestic cassettes or 70.00 dinars on TDK or SONY cassettes. With this issue in our section we begin our acquaintance with machine language.

Machine code

Let’s imagine that you don’t know what machine language is, how to program in it, and... that is, you don’t know anything at all about machine code. To begin with, we will study using the example of a BASIC program. A BASIC program consists of program lines. Each line has a number that determines its place in the program.

10 PRINT 10
20 NEW

From this program you can see that the number 10 will be printed first, and only then the NEW command will be executed. Of course, everything happens very quickly, so you barely notice the command on line 10. But if you add PAUSE 0 on line 15, the program will not be erased from memory until you press a key.

This means that the computer executes instructions from lowest number to highest number, unless the program contains GO TO or GOSUB commands.

The machine program has the same structure. It consists of machine instructions, each of which is placed in a certain way in a separate memory cell.

Since the Spectrum's central processor executes 686 different machine instructions and there is a lot of code, symbolic machine language was introduced, the instructions of which are entered using assembler.

This language is called mnemonic machine language. Its form is something like this:

10 LD a,10

Here 10 is the program line number, and LD a,10 corresponds to the command LET a=10. But the command LD a,4D means PRINT - everything depends on the open channel, that is, on the famous CALL, which determines the remaining functions of the program.

The machine program can also be entered using the DATA and POKE commands: with their help, commands are placed in memory. Entering codes into memory with the POKE command is much easier, but also dangerous: the program can be blocked, that is, the computer will stop working. Then everything will have to be repeated again, and previous efforts will be in vain. If the program is long, it takes a lot of time, and you will not be able to correct the error.

With the DATA command it is much simpler: the contents of the stringDATA can be checked again, and again - even after the RUN command, if the computer reports an error in the DATA line.

However, this method is also tedious if you are writing a long program in machine code. That is why a mnemonic, or symbolic, language was created: it is the fastest to write a program and understand what is written, and it is most similar to real machine language that a computer understands.

To make it easier for you to learn to write in machine language, we will publish several tables in the next issues of ZX Revije.

First of all, you need to understand how your computer works, what its capacity is, what memory cells are, and so on. The legendary Z80A chip, operating at a frequency of 3.5 MHz, is responsible for the speed of program execution. It's not that fast, but it's enough to run most programs quickly.

In addition to the mentioned assembler, the machine program can be entered using the DEC-loader, M.C.M, EZ-CODE and HEXLOAD loaders. We will talk about each of them separately in the following issues.

Now let's return to assembler. It translates the mnemonic language into Spectrum machine language, that is, into zeros and ones.

The assembler converts the program only after you enter the entire program and press the appropriate key.

If you make a mistake, you will have to enter everything again, but this can be avoided by using more advanced software. This is briefly about ASSEMBLY, and now a little about DISASSEMBLER. It reads what is written in machine code. Since they also learn with its help, it is a MUST purchase. And now we offer several programs written in BASIC with machine code:

THE SOUND OF THE FOREST
10 DATA 243,33,0,0,17,255,251,201
   :FOR A=40001 TO 40031:READ N:POKE A,N:
   NEXT A:FOR N=1 TO 100:
   RANDOMIZE USR 40001:
   NEXT N

ALARM CLOCK SOUND
10 DATA 6,16,17,2,0,33,16,245,201
   :FOR A=40001 TO 40020:READ N:POKE A,N:NEXT A
   :FOR N=1 TO 200:RANDOMIZE USR 40001:NEXT N

10 FOR N=16384 TO 22527
20 POKE N,INT(RND*255)+1
30 NEXT N

10 FOR N=22528 TO 23295
20 POKE N,INT(RND*100)+1
30 PAUSE 10
40 NEXT N

Share your thoughts about the article