VVS
═══
We dedicate this section to those who
decided to learn how to program
machine codes. Someone might
the question arises, why is this necessary?
important when there are so many times
various programming languages,
designed for all tastes and inte-
res?
In order to answer
this issue needs to be considered
what are programming languages and
how do they provide human communication?
century with a computer.
The heart of the ZX-SPECTRUM is the pro-
the processor is a microcircuit that does not understand
no programming languages as well
accepts only machine codes,
since they are represented by electrical
ical impulses. So when
we run the program in machine
codes, then we essentially control
operating the processor directly. When
we're launchingprogram written
for example, in BASIC we transmit
control of the BASIC interpreter,
which in turn translates
BASIC string commands and operators
machine code. It's not hard to guess
that a program written in machine
codes, will execute much faster
tray than a program written in
BASIC. This statement is true
Livo and for other programming languages
roving.
So, programming in machine
code allows you to increase the speed of work
bots programs, which can be extremely
it is very important if the program has
numerous nested
ha cycles, if executed repeatedly
search and selection of data from the general
ary memory areas. A lot of time
occupy operations related to ob-
working on graphic images
screen. The effect is smooth and fast
moving objects in computers
video games almost always create
is given in Machine code.
It is necessary to note one more important
ment - reduction of the volume of occupied
memory It would seem that 48 kilo
bytes of memory is a lot, but if you
You SPECTRUM 128, then 128 kilobytes
and there is absolutely nowhere to go. But it's not worth it
rush to conclusions. If we take into account
that almost 7 kilobytes occupies the screen -
nal memory area, then when creating
colorful programs containing non-
how many dozens of screens there are on them
storage even incompressed
vide takes several tens of kilo-
bytes, but you still need to allocate space
for storing data tables, variables
nykh, texts, etc. Therefore, in the best
programs on the machine code itself, by
which they work for, there are 4 left -
8 KB. This is where the skill comes in.
programmer who managed to provide
in such a small volume the rich multi-
variety of game variations, color palette
tov and range of sounds.
Let's compare memory consumption during operation
in BASIC and machine codes. Pro-
grams in BASIC size 30
lines takes up approximately 1K of memory.
Similar to it, performing the same
tasks, program in machine codes
will take approximately 150 lines,
but they take up only 200..250 bytes
RAM.
We could continue the conversation
about the benefits of programming in
machine codes, but I hope that everything
the above has interested you and
we can get to the heart of the matter,
namely the study of machine language
Z-80 processor.
APXETECTURE OF THE Z-80 PROCESS
The Z-80 processor was created by the American
skaya corporation ZILOG and became one
one of the most successful processors in the world.
He has 8bit data bus
and a 16-bit address bus. This
means it can process
integers (bytes) from 0 to 255 and
directly access 65535 cells
memory
The processor structure includes non-
how many registers? We are with them
and work, programming in machine
code We can assume that the registers
are internal memory cells
processor. But unlike ROM,
where can you just read the information?
when working with RAM, you can both read
both to write and to write down information. C
CPU registers can be used to perform
a large number of different arithme-
tic and logical operations.
The processor registers are unique and
have their own names. They are designated
letters of the Latin alphabet: F, A, B,
C,D,E,H,L,SP,PC,IX,IY,I,R.
This is the main set of registers. Yes
one more extra set. His
called alternative and we dis-
watch it below.
Some of these registers are eight-
world-bit (single-byte) and can
contain integers from 0 to 255.
These are registers F, A, B, C, D, E, H, L, I, R.
Others are sixteen-bit (two-
byte). They can contain whole
numbers from 0 to 65535. These are SP registers
, PC,IX,IY.
Some single-byte registers can be
can be combined into double-byte regions
string pairs BC, DE, NL. In thiscase
such a couple can be spoken of as
separate sixteen-bit region
stre .
The Z-80 processor is very
asymmetrical, that is, each register
has specific features, de-
barking him unlike the others
registers. Therefore, different registers
designed to perform various
personal functions.
Register A - BATTERYTOP.
This register is called the accumulator
because in many cases the result is
the completion of the operation remains in it. B
this register performs the greatest
number of arithmetic and logical
which teams. This is the main one-byte
processor register In many comas
ndah it’s not even indicated which one
they belong to the register: presupposed
it is believed that they belong to the regi-
stru A .
Registers B, C, D, E, H, L - REGISTERS
GENERAL PURPOSE.
These registers are widely used
processor when executing various
commands Their characteristicfeature
is that they can use
be called also as single-byte singles
registers, and how two-byte hexadecimal
10-bit register pairs BC,
DE, NL.
In this case, the largest number
commands have an NL register. When working
with double-byte integers it
is just as important as
and register A when working with single-byte
nym.
All these pairs are used as
for storing addresses. At the same time
the HL register often contains ad-
res of the byte with which the
The operation is underway.
The abbreviation goes to the DE register
from the word DESTINATION (Destination place)
nia). And indeed, in many
operations related to movement
something, the HL register indicates from-
where to get it, and the DE register - where to go from -
edit
You can select a match for the aircraft register
abbreviation VASK COUNTER (Reverse
counter). In cases where op-
defined sequence of commands
must be repeated N times, i.e. when
a cycle of calculations is organized, in re-
The BC register stores a counter for this
cycle
When combining single registers
in pairs, the eldest is stored in the first
byte, and in the second - least significant. So
B,D,H is the eldest, and C,E,L is the youngest. SP register - STACK INDEX
(STASK POINTER).
In cases where necessary
release some for a while
either a register (or registers) and storage
thread its contents from now on to the far-
best use, computer
can be used as a place
special temporary data storage
section of RAM called
stackable. A stack is a form
organization of memory, in which
Data loading and unloading is in progress
according to the principle of “last come first”
you will leave." It can be organized
van almost anywhere operational
memory
The stack "grows" from top to bottom. When
its top also moves. B
the SP register contains the address of the vertex
stack. When placing the next number
on the stack, the SP register is automatically
ki decreases its value, and when
removing a number from the stack increases it.
Having submitted your address to the stan-
ka, you can organize the stack in
elsewhere in RAM.
PC register - PROGRAMMAR
COUNTER (PROGREM COUNTER).
This register, like the SP register -
sixteen-bit. It serves for
storing the address of the operation that
paradise must be performed next.
When the processor starts executing
this operation the program counter
increments by one if
the command is one byte, two if
double-byte, etc. Thus, according to
at the end of this operation the processor
knows what operation to perform next
blowing
If the program contains a transition to
another place or subroutine call, then
it is the program counter that provides
there is such a jump.
Register F - FLAG REGISTER.
This register is different from all others
the rest and plays in a very unique way
new role. He is not considered as
a separate register storing eight-
digit number, more like eight
individual flag bits. Everyone
the flag can be set or cleared
that is, the corresponding bit is turned on
(equal to 1) or disabled (equal to 0).
Below is the structure of the flag-
th register: Bit 0 - carry flag C
Bit 1 - addition/subtraction flag N
Bit 2 - parity/overflow flag
Bit 3 - not used
Bit 4 - half-transfer flag H
Bit 5 - not used
Bit 6 - Z zero flag
Bit 7 - sign flag S
Learn more about working with flags
Let's talk in one of the next issues -
ditch
Registers IX, IY - Index
registers.
These are two register pairs as
forks are used for memorization
addresses Characteristic feature
of these registers is that
thanks to them you can organize it like this
called index addressing.If
You need to work with some tab-
data persons, then you can
searching and selecting the element you need
tables do not specify its address, but
store an address in an index register
beginning of the table. Contacting the right person
You element is performed by converting
access to this index register with
indicating the magnitude of the "displacement" is necessary -
th element from the beginning of the table.
On the Spectrum, the IY register stores in
imagine the address is 23610, which is
starting address of the system table
variables This makes it easy to
expand to any systemic change-
noah The initial installation
press register IY to this address
executes after turning on the computer
to the network initialization program, on-
stored in ROM, but you can change
thread this installation, sending it there
any of your address.
Register IX is widely used by
computer when executing commands
Loading/unloading programs: LOAD,SAVE,
VERIFY,MERGE. It stores the address
the beginning of the loading (unloading) place
block.
Register R - REGENERATION REGISTER.
This is an internal system register,
which is used by the processor
automatically, without program participation
mista. Electric charges in micro
RAM circuits have ten-
tendency to “leak away”, therefore for the norm-
proper computer operation is necessary
recharge (regenerate)
RAM. For these purposes and
register R is used.
Register I - VECTOR OF INTERRUPTIONS.
This register is involved in the Spectrum
only in the formation of television
signal and processing the subroutine op-
keyboard dew, but you can do it yourself
create your own processing program
interruptions (more on this in the future).
ALTERNATIVE REGISTER SET.
One of the distinctive features of the process is
litter is the availability of alternatives
a large set of registers. These are registers
F',A',B',C',D',H',L'. They are completely
identical to registers F, A, B, C, D, E, H, L.
The presence of such an alternative
Bora allows you to quickly switch
from one set to another. When
you need to perform some operations with
general registersappointments, and they
already occupied and lose contained in
the data is not possible, it is in front of you
three ways:
1.Send the contents to memory and
then return it back.
2.Place on the stack, and then ver-
get him out of there.
3.Switch to alternative
a set of registers and work with it, and
then switch back to basic
no set .
The third way is the most efficient.
Thanks to the availability of alternative
set the processor can simultaneously
serve two tasks. At that time,
when you switched to alternative
tive set, it becomes the main one
and the former main one becomes al-
alternative. Physically these sets
completely identical and therefore defined
share with which set, at this time
moment, you are working impossible.
The program can turn out quite
intricately woven and from a programmer
requires some careful
ness.
Well that's all for today. Continued
Read about our encyclopedia in
next issue of the magazine. Good luck !!!
Share your thoughts about the article