ASSEMBLER FOR BEGINNERS
(C) THINKER
Hi, everyone who wants to learn how to program in assembler
Zx-Spectrum!
First I will say that you have not told about all the
registers of microprocessor. There are a few of you do not
know, as well as an extra set of ... But first things first.
It contains the SP register address to which is
top of the stack. When performing "PUSH xx", this
register is decreased by 2. If you go to any procedure (CALL
xx) and then it changed SP, then change and address of the
stack and the routines you already do not normally go out. I
note that under the "POP xx", SP increases, and also at 2.
Register PC This shestnadtsatibitny Reg. also called counter
commands. It is performed at this address
moment of the team.
Register R Generally, this reg. used in hardware, for re
generation of memory, but it can be used in
their programs. The fact is that after each operation, the
value stored in it increases by 1 and reached the value 127,
reset. It can be used as a pseudorandom number generator.
Index A very useful thing. They can be used as
registers of conventional reg. couples, but it's not all. Have
you ever IX and IY apply a combination BASIC type perem +10 or
perem + x? Takuyu opportunity to give IX and IY in
assembler. Suppose we have a reg. A Record number which
stored at perem +10. How to do it, because you can not write or
HL +10 BC +10. But you can write and IX +10 IY +10! That is so
it looks like:
LD IX, PEREM; puts the number IX in PEREM
LD A, (IX +10); record in the A number that is stored
; Xia at PEREM +10. I note that
; PEREM-is any number
Now on the additional set. In addition to the basic register
pairs (AF, HL, BC, DE), there are others who are no different.
So, there are two basic sets of registers, among which you can
switch. In the microprocessor has two registers A, two reg.
pair HL, two BC, two DE, which do not depend from each other.
Inactive currently set Reg. call alternative. Write anything in
an inactive Reg. impossible without switching the set. At the
same time, determine programmatically what a set of registers
is active at the moment, there is no opportunities.
Alternative microprocessor registers are denoted as follows:
A ', B', C '... etc. The apostrophe after the name of the
register indicates its membership in the alternative set.
Switching between a set of HL, DE, BC, by using
Team EXX. Switching between active AF and alternative AF '
A team of EX AF, AF '. Reg. IX, IY, SP, PC, I, R is not
switched, the processor they are in the same instance ...
Set up a table of registers Z80:
Now, let's popraktikuemsya in writing programs.
The task: to fill the attributes of AFA 'F'
random numbers. As an OD
random number generator used HL-C O H 'L'
Use the register R. As always, NP
Yes, try to find a solution on BC about B 'C'
independently, but if not, VL
luchilos, here is the answer. Reminiscent of the N D E N D 'E'
it address the attributes of the RA-O and
Veins # 5800. J I X T
E
LD HL, # 5800 N I Y N
MET LD A, R A L
LD (HL), A B S P H
INC HL About Li
LD A, H P I R J
CP # 5B
JR NZ, MET P C
RET
Now some explanation:
First, we are sending to the battery reg. R, and then throws it
into the screen. Why? The fact is that Z80 is no command LD
(HL), R. And therefore had to use battery (reg. A). Next, we
check in the mail late HL screen. Is done as follows: the end
of the screen - this is # 5B00 (23,296), so if HL = # 5B00,
then H = # 5b, and L = # 00. Here we check to see if H # 5B or
not equal. If not equal, then repeat cycle, or - leave.
Now do the same thing yourself, but do not fill
attributes, and pixels. Let me remind you that the beginning of
the screen - # 4000 and the end it - # 5800.
C registers clear. Now do not interfere with several
new mnemonic.
OUT IN these entities are similar teams BASIC OUT and IN.
With their help you can send the value to the port
(OUT), or get the value from the port (IN). These commands are
used to work with external devices, when queried by a keyboard,
joystick, you are working with a disk ... As you probably
know the curb, too set in the port. Port recorder, loudspeaker,
and the curb - is port 254 (# FE). Through him you are working
with the keyboard.
The value of bits of port 254 (# FE):
■ - not used
■ ■ ■ S M B O R S - speaker
M - recorder
BOR - 3-bit value to the curb
I must say that these values work only on the record,
reading - they're different.
Now we can set the color of the curb. To do this, we must
send to port number 254 in color.
LD A, 7; installation
OUT (254), A; white
RET; curb
Rapidly changing color border can be achieved certain
effects. By the way, multi-colored stripes on the latter,
formed specifically for very rapid change in its color. But
more on that later.
How can extract the sounds from the speaker? Very simply, we
need only change the 4-th bits in 254 port. The faster you
change this bit the higher the sound.
Well, enough for today? Leave you to digest the information.
Till we meet again in the pages of Polesie.