╔═══════════════════ ═══════════════════╗
║Section:CPU for you; ║
║Article: You need to start small; ║
║Music:CONT; ║
║Text: V. Alexander, B. Stanislav. ║
╚═══════════════════ ═══════════════════╝
With all the advantages of BASIC, there are
The main disadvantage of this language is the comparative
extremely low speed written
programs available on it.Modern versions
BASIC allows in some cases to compensate
eliminate this drawback by introducing
new program, subroutines recorded in
machine codes. It is especially convenient to use
to use such subroutines when converting
on large arrays of homogeneous information
mation.
In computer games, in various applications
good and demo programs
a very productive way of copying
data from one memory area to another,
for example from the screen area to the reserved area
encoded area of memory and vice versa. This is
allows you to: almost instantly call
insert a picture into the desired part of the screen or
text, placed in advance in re-
backup memory; create moving car-
teenagers, one by one “redrawing” the images
movement or part of it from the “screen” to the “co-
I drink" and vice versa and at the same time changing the definition
existing parameters; achieve other effective
Comrade
On SPECTRUM there is such a commandMP LDIR, which forwards the memory block
ty, whose address is indicated in the HL register,
length is in BC, and the address to which is needed is
can move the block.At each tick
operation the number entered in the BC pair,
decreases by 1, and the corresponding addresses
CA in HL and DE increases by 1.
Addresses of neighboring video memory cells, co-
the contents of which are shown on the display
in the form of elementary raster sections, from
differ by just one. It is clear that
in this way you can copy the entire ek-
wounds or a separate part of it. Obviously
other: if the block transfer command
apply within one line, entering
in BC the length of its segment, then load into
HL starting addresses of subsequent segments
and repeat the block forwarding operation,
then you can copy it to the backup buffer
any part of the screen.
POSSIBLE TRANSMISSION SUBROUTINES:
From screen From copy
to copy to screen
LD DE,(Z2) LD DE,(Z1)
LD BC,(Z3) LD BC,(Z3)
LDIR LDIR
LD BC,LENGHT LD BC,LENGHT
ADD HL,BC EX DE,HL
LD A,(Z5) ADD HL,BC
DEC A EX DE,HL
LD (Z5),A LD A,(Z5)
JR NZ,$-20 DEC A
RET LD (Z5),A
JR NZ,$-22
RET
In certain memory cells, write
are: in the first pair, with the starting address
Z1, - address of the beginning of the copied fragment;
to the second, with the starting address Z2, - address
"copies", i.e. memory area reserved
bathroom for a copy of this fragment; in
the third, with address Z3, is the length of the copied
line segment, in LENGHT, - increment of te-
current address; and finally to a separate
cell with address Z5 - number of lines.
As a result of transfer to the buffer site,
memory current, line segments are “stacked”
one after another without any spaces.
This allows you to save significantly
computer RAM.
In conclusion, a few words about her quick
interaction. It is easy to calculate that when
copying the entire screen the number of times
number of commands exceeds 100 thousand. When
clock frequency 3.47 - 3.51 MHz and duration
of elementary operations 4-6 so-
and the screen copying time will not exceed
0.2 sec. If a small one is sent
screen block, counting in hundredths of seconds.
A subroutine for the Z-80 copies the screen to
literally instantly.
You may not even know what ma-
bus language. You may not even be able to
it is known that there is a difference between machine
language and assembly language, and what they both are
different from programming in a language
BASIC.
Don't worry or be intimidated by the professionalregional jargon. In the future, we will all
We will explain gradually.
WHAT IS MACHINE LANGUAGE?
Remembering that in fact there is an electric
tric signals, let's accept the system
symbols of these signals - nap-
example, putting "1" if on one of the contacts
there is a signal, and "0" if there is no signal.
A typical team might then look like
do it like this:
00111100
This is significantly different from
"LET A = A + 1", isn't it!
However, this is precisely what machine
language. The name speaks for itself! This is-
language for machines.
Here you can ask yourself if
this is machine language, what is the test
Lema? Why not use the pro-
a job given to someone else, which will allow
should I program on a computer in a language that
which I can easily understand, such as BASIC
or PASCAL.
This makes some sense because
the following advantages of machine language:
Faster program execution;
More efficient use of memory;
Shorter programs (in memory);
Operating system independent.
All the above benefits -
direct consequence of programming
language in a language that the CPU understands
without pre-broadcast. When you
program in BASIC, then actually
in factThe computer executes the operating program
a system written in machine language
ke.
A BASIC program can be executed
almost 60 times slower than the program,
written directly in machine
language!!!
The reason for this is that the broadcast
takes time, and also the resulting
as a result of the machine language command
are effective. Machine language has
the following benefits:
Programs are difficult to read and debug;
They cannot be transferred to other computers;
Programs turn out to be longer (in command
dah);
It is difficult to perform arithmetic calculations
leniya.
This means that you should be very careful
make a thoughtful decision 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
tann for number processing and such that
programs, if necessary, you can
easy to modify.On the other hand
There's nothing worse than an arcade game...
written in BASIC - when you
sit down to play, she will turn out to be too med-
Lennoy
WHAT IS ASSEMBLY LANGUAGE?
It is quite obvious that if the machine
language could only be represented
using numbers, very few people have been
would be able to write programs on machine
language.
INin the end, who could understand the meaning
programs that look like this:
00100001
00000000
01000000
, etc.
Luckily we can come up with a number of names
for each of these numbers. Assembly language
ra is just such a representation
knowledge of machine language so that people can
read it in a more understandable form than
01110111
Between assembly language and machine language
com there is only one difference: the language is as-
sampler is one level higher than machine-
language. It is easier for a person to read than
machine language, but on the other hand, a computer is not
can read assembly language.
It is not an adaptation of the machine
language, like . For each code
Assembly language mands have identical
machine language command (by function)
ka and vice versa. In other words, between them
there is a one-to-one correspondence
vie.Therefore we can say that the language is as-
assembler is equivalent to machine language.
Assembly language uses mnemonics
(or reductions) to improve usability
tability. For example, at this stage of training
The INC HL team can do almost nothing
doesn't mean anything to you, but at least
you can read it. If you said-
Is INC a standard abbreviation?
INCREASE (increase), and HL is a variable,then just by looking at this command you
you can get an idea of what
happens. The same command for cars -
In local language it looks like 00100011.
Now, obviously, you can also pro-
read this command in the sense in which
rum you can read the number. This is not bu-
children mean a lot to you, unless
you don't have a lookup table or your
the brain acts almost like a computer.
Assembly language can be converted
directly into the machine program with
using the program or by yourself. Such
the program is called "ASSEMBLER". You
you can consider it as a program,
performing a rather tedious task
your broadcast, written in the language
assembler programs in sequence
number of machine language commands understandable
SPECTRUM and we believe that assembler is for
ZX-SPECTRUM is already available.
However, such assemblers are usually
require 6K memory and have limited
application on a computer with a memory capacity of 16K.
The SPECTRUM display takes up 7K of memory, and
after loading the assembler you can
only 4K memory left for the program
in assembly language (this means using
approximately 500B machine language programs).
An alternative way to work is instead
application of the assembler itself to the translator
introduce assembly language mnemonics into machines
language manually, using for a long time already
existingtables.
It's difficult, it seems hopeless at first,
It's inconvenient, but it's great practice and
gives you a deep understanding of how...
the Z-80 is running.
We actually recommend that you
tried to write in this way
a short program in machine language, i.e.
write them in assembly language and hand-
new translation into machine language -
before buying an assembly program
ra.
CONCLUSION.
CPU
The central processing unit of a computer. This is a chip, you
performs computing and control functions in computers
lying functions.
MACHINE LANGUAGE
Language perceived by the CPU. For CPU is the Z-80 machine language containing
about 696 teams.
LANGUAGE BASIC
Programming language developed by
so as to be understandable to humans. When
The computer executes a command in BASIC language
you have to translate this command to
sequence of machine language commands -
ka.Therefore programs in BASIC language
work much slower than programs
frames in machine language, but they are easier to write
sat.
ASSEMBLER LANGUAGE
Representation of machine language commands in
abbreviated, human-readable recording.For example, HALT is the assembly language equivalent
machine language commands 01110110.
ASSEMBLER PROGRAM
A program that translates language commands
assembler (readable and understandable language)
lovek) into machine language commands, playback
accepted computers.
ROM
Large machine language program,
usually called programmable hardware
dovaniya;program, hard-wired into
computer equipment; it is preserved even when
power off.For SPECTRUM ROM write-
programmed in Z-80 machine codes and
written specifically for him.ROM SPECT-
RUM occupies memory locations 0 to 16383.
You can access the contents of these
cells, while the rest of the memory you can
you can not only read, but also change how
required.
BASIC CONCEPTS OF MACHINE LANGUAGE
What is a CPU?
If we want to exchange information
with a computer, then we need to know what type
she will accept commands, and
what language does the computer brain (CPU) speak?
If we don't know what type of information
perceives the CPU, then we will not be able to
blows to explain computers, how wonderful they are
it must solve problems for us - from
rivalry inchess game before boo-
a galler who monitors our accounts.
There is nothing mysterious about the CPU. I like-
I want to imagine the CPU as a lonely person
the trapper sitting inside your SPECTRUM
who is constantly asked to do something.
In particular - to calculate.
But the poor man doesn't even have a pencil...
Sha and paper to record what is happening. How
is he doing this?
CONCLUSIONS
REGISTERS
The CPU has registers that it can
used for calculations.Eight of
they can be considered the hands of the CPU, and its two -
feet. Each hand has 8 fingers, and
16 for each leg.
MEMORY CELLS
The CPU can transmit information from one
his hand to the other, as well as in memory and
from her.
The programmer can assign specific
memory cells for representing specific
no information.
STACK
The CPU can use the stack to transfer
information that the programmer wants
temporarily remember. Information is transmitted
onto the stack by pushing into it and removing
repents by pushing out.
POSSIBLE COMMANDS
The CPU can only execute commands such as
type, as the simplest transmission of information
tions and simplearithmetic operations.
All programs must be composed of
the sequences of these simplest co-
mand.
HOW DOES A COMPUTER COUNT?
The computer writes all numbers in binary
(bit) format. For example, the number 54 is
written in bits like this: 01100110. Well
if the decimal number is, for example, ta-
kim:8880.In order to translate this
number to binary for convenience, first
convert it to hexadecimal
format. Such numbers are written as follows:
In general: the number 1 corresponds to 1;
the number 2 corresponds to 2;
and so on until the number 9, but you probably
you think that after 9 comes 10, but this
not quite like that. See what happens next
a number series is constructed: number 10 - #0A;
number 11 - #0B;
number 12 - #0C;
and so on until the number 15; 15 - #0F;
And the number 16 is written like this: #10, i.e.
if you add 1, then the entry goes to the next
next digit of the number. All hexadecimal
The numbers from #00 to #FF (255) occupy
memory is 1 byte, and numbers greater than 255
occupy 2 bytes, for example, the number #4000
(decimal equivalent to 16384).
For example, if you take the assembler command
LD HL,#7FFD, then it will be equivalent to
mande LD HL,32765 or
LD HL,%0111111111111001
As you noticed, there is an icon here<%>.We will use it in the future
to denote binary calculus.
Now we will show you how to translate
numbers from one number system to another
Guyu. First the notations:
BIN - binary (% icon)
DEC - decimal
HEX - hexadecimal (# sign)
Now the translation from BIN to DEC:
Let's take the number %01101101 as an example. This
the decimal equivalent of 109. To
you need to get this number first
decompose the number %01101101 into two tetra-
Yes, thus: %0110 and %1101. First
tetrad will mean the second digit
numbers, and the second - the first. Now the values
significant bits:
0 0 0 0 0 0 0 0
128 64 32 16 8 4 2 1
These bit values are only significant
yes, when the bit that belongs to
value,set to 1.
If we now substitute our value,
then we get:
0 1 1 0 1 1 0 1
0 64 32 0 8 4 2 1
Adding these values, we get the value
109. As you can see, this is very simple, it is necessary
we only need to know the value of the corresponding
the bit blowing at him. It's even easier to get HEX
number. To do this you should remember
tetrads. So:
%0110 %1101
When calculating, we will get the value in le-
howl tetrad 6, and in the right - 13. Now, es-
can we convert these two values to HEX, then
we will get the value #6D, but what if you don't
believe me, then translate it yourself
number in DEC and you will see that these two
DEC and HEX values are the same. How are you in
in the future you will see - hexadecimal format
the way data is entered into the computer memory is significant
much more convenient than decimal or binary
new ways.
Now we will do the translation from HEX to
DEC:
For example, let's take the number #9C40.
Let's denote the numbers 9,C,4,0 by X,Y,Z,T.
Let's get the number #XYZT. Now let's break it down
by 4 numbers this way:
9 C 4 0
X*4096 Y*256 Z*16 T*1
Now let's calculate our expression
9*4096+12*256+4*16+0*1. It will be
equals 40000! With this maker you can-
You can translate any numbers from 0 to 65535.
Well, so that we don’t waste extra pa-
crumple for the text, we will just write the formula
for transfer from DEC to HEX. Here it is:
HEX=INT(X/4096+(INT(Y/256)+(INT(Z/16))+T
Now after this short excursion
you will be able to translate numbers from these 3
number systems such as BIN, DEC, HEX.
* * *
Share your thoughts about the article