Soft Building - how to navigate the machine code for the Z80.

Wallpaper #06
╔──────────────────╗
          │ 5. SOFT BUILDING │▐
          ╚──────────────────╝▐
           ▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀

              Hail Peoples!

   In many already electronic publications
was a description of assembly language, as well as
for beginners and for more advanced
twisted ;-) personalities. But just like new journals
cash takes quite a long time to reach Tashkent,
we will publish our assembly 'lessons'
Lera for beginners, gradually moving on
to increasingly complex things and ending
writing a small game. So let's get started
pim:

   HOW TO NAVIGATE MACHINE LANGUAGE

                  START

   It may turn out that before reading this
article you did not have a clear idea
about programming in machine language. you
you may not even know what a machine is
language.  You may not even know that
there is a difference between machine language and language
com assembler, and how they both differ
from programming in BASIC.
   Don't worry or be intimidated by the professional
sional jargon - we are all gradually
Let's explain.
   First of all, let's see how
computer running:

  1 PROGRAMMER---------- 2 KEYBOARD
        |                      |
        |                      |
5 TV SCREEN----------- 3 OPERATING SYSTEM
                 |
                 |
     4 CENTRAL PROCESSING UNIT

  1 - programmer, 2 - keyboard, 3 -
operating system, 4 -central pro-
processor, 5 - television screen.

   The purpose of this diagram is to show
understand what is between the programmer and the brain
"Spectrum", a central processor, has
there is a barrier. During normal processing
the programmer cannot ask the central
processor, usually called a CPU, that
must do.
   The Sinclair computer uses a Z80 type CPU. Che-
Three Z80 chips, 6502, 6809 and 8088 steel
Rocko common as a CPU for
microcomputer. Z80 is the most popular of them.
   It won't surprise you that the Z80 doesn't understand words.
wa in BASIC.  Actually neither
one chip was not designed this way,
so we can communicate directly
with a computer brain.
   If you think deeply enough, you can...
but to understand that it would be very difficult if
in general it is possible, in any case, to set for
computer chip command that makes sense to humans
century.  Remove the top of your Sinclair
(if you dare ;) ) and look at the most
the big chip is the Z80A CPU. Obviously this
your computer chip can only respond to
electrical signals transmitted to it
the rest of the circuit.

         What is machine language?

   The Z80 chip is designed in such a way that
that it can receive signals simultaneously
but from the eight contacts connected to it
Comrade
   The developers of the Z80 chip designed
it in such a way that different combinations
arriving at it from these eight contacts
comradesignals will "command" the Z80 you-
perform different functions. Remembering that
in fact there are only electric ones
signals, let's accept the conditional system
designations of these signals - for example,
"1" if one of the contacts has
signal, and "0" if there is no signal.
   A typical command would then look like
do it like this:

             0 0 1 1 1 1 0 0

      This is significantly different from:

             "LET A = A + 1"

   However, this is exactly what the machine is -
nal language.  The name speaks for itself.
This is a language for machines. Each manufacturer
various chips designed for his
products have their own special language.
   Here you can ask yourself the question:
Is this machine language, then what?
problem? Why not use the pro-
work given to someone else, which will allow
program on a computer in the language that I
easy to understand, such as "Basic" or "Co-
bol"?
   This makes some sense because
the following advantages of machine languages:

- faster program execution;
- more efficient use of memory;
- shorter programs (in memory);
- independence from the operating system.

   All the above benefits -
direct consequence of programming
language in a language that the CPU can understand without
pre-broadcast when you pro-
frame in BASIC, then in fact
The computer executes the operating room programsis-
topics written in machine language. This
the program looks something like this:

  NEXT TAKE NEXT COMMAND
        TRANSLATE IT INTO SEQUENCE
        MACHINE LANGUAGE COMMANDS
        EXECUTE EACH COMMAND
        RECORD THE RESULT IF NECESSARY
        GO TO NEXT AGAIN

   If you are wondering where the computer gets this
program, operating system, then it
stored in ROM. In other words, it is built-in
on in "Spectrum", (ROM is the abbreviated name
Read-only storage device
computer memory, the cells of which you cannot
You can change it, but you can only read it.
   A program in BASIC can...
complete almost 60 times slower than
program written directly in
machine language.
   The reason for this is that the broadcast is from
takes time, resulting
Machine language commands are less efficient.
Likewise, usually faster
turns out to be a personal car, not a
public transport; you can cut
path along the roads you know, and not following
take public transport routes,
who has to satisfy society
military needs. Nevertheless, we have
I would be the first to admit that the software
machine language has its drawbacks
tats:

- programs are difficult to read and debug;
- they cannot be transferred to other computers;
- programs turn out to be longer (per command)
  dah);
- difficultperform arithmetic calculations
  nia.

   This means that you should very
make thoughtful decisions about what
programming method should be used
for each specific task.
   A very large program in the field of physics
nans should be written in the language developed
data for number processing and such that
programs, if necessary, you can
easy to modify.
   On the other hand, there is nothing worse than
arcade game written in the language "Beat"
sik". When you sit down to play, it will be
too slow.
   Your choice of programming language will be
determined by your own needs
requirements, the amount of memory of your computer, the requirements
the evolving reaction time allowed for
development by time, etc.
   So, to summarize, machine language is -
sequence of commands understandable to the CPU
and can be represented as numbers.

        WHAT IS ASSEMBLY LANGUAGE?

   It is quite obvious that if the machine
language could only be represented with
using numbers, very few people would
capable of writing programs in machine language
ke.  After all, who could understand
the meaning of a program that looks like this:

             0 0 1 0 0 0 0 1
             0 0 0 0 0 0 0 0
             0 1 0 0 0 0 0 0
                  etc.

   Luckily we can come up with a number of names
for each of these numbers. Assembly language
that's exactly what it ispresentation
machine language. So people can read
it in a more understandable form than:

             0 1 1 1 0 1 1 1

   Between assembly language and machine language
com there is only one difference: the language is as-
sampler is one level higher than machine-
nal language.  It is easier for a person to read than
machine language, but on the other hand, a computer does not
can read assembly language. He is not
is adapted by machine language adaptation similar to
"BASIC".  For each command of the language as-
assembler has an identical (in function)
machine language command and vice versa, by others
in words, there is a mutually identical relationship between them
initial compliance.  Therefore, we can say
Note that assembly language is equivalent to ma-
tire language.
   Assembly language uses mnemonics
(or abbreviations) to improve readability
bridges. For example, at this stage of training
the INC HL team may know almost nothing
for you, but at least you can-
you want to read it. If you said that
"INC" is a standard abbreviation (or mnemonic)
symbol) INCREASE
read), and "HL" is "variable", then simply
by looking at this command you can get
get an idea of what is happening.
   The same command in machine language
has the form:

             0 0 1 0 0 0 1 1

   Now obviously you can also "pro-
read" this command in the sense in which
rum you can read the number. This is not a boo-
kids a lot formean you, unless you
you don't have a reference table or your brain doesn't
acts almost like a computer.
   Assembly language can be converted
directly into the machine program from software
by the power of the program or by yourself. Such
The program is called "ASSEMBLER". You can-
You can consider it as a program, you
completing a rather tedious task
broadcasts of your written in the language of as-
assembler program into sequence
machine language commands understandable by Spect
room" and we believe that the "assembler" for "ZX
Spectrum" is already available.
   An alternative way to work is instead
using the assembler program yourself
translate assembly language mnemonics into
machine language manually, using the given
tables in this book.
   It's difficult, at first it seems hopeless
but, it's inconvenient, but it's great practice
and gives you a deep understanding of how
The Spectrum CPU is running.
   We actually recommend that you
tried to write in this way a short
some program in machine language - i.e. on-
write it in assembly language and manually
translate into machine language before
buy an assembler program.

                CONCLUSION

                    CPU

   The central processing unit of a computer is a chip
performing computational and control tasks on a computer
lying functions.

              Machine language

   Language understood by the CPU. For CPU "Spect-
room" is a machineZ80 language containing
approximately 600 teams.

              BASIC language

   Programming language developed
so as to be understandable to humans. When
The computer executes a command in this language, it
you have to translate this command to
sequence of machine language commands.
Therefore, programs in the BASIC language are important
Much slower than programs
in machine language, but they are easier to write.

             Assembly language

   Representation of machine language commands in
abbreviated, human-readable recording,
for example, HALT is the assembly language equivalent
machine language commands 0 1 1 1 0 1 1 0.

           assembler program

   Program that translates language commands
assembler (readable and understandable to humans)
century) into machine language commands (perceived
portable computers).

    Read Only Memory

   Large machine language program
usually called programmable hardware
vaniyam. A program hard-wired into the app
computer parameters.  It persists even when
power off.  For Spectrum ROM
programmed in Z80 machine codes and
written especially for him. ROM "Spect-
room" occupies memory cells from 0 to 16383.
You can only access the content
these cells, while the rest of the memory you
You can not only read, but also change.

     For the first time, perhaps that's enough,
            to be continued...

Share your thoughts about the article