EXCHANGE OF EXPERIENCE
those who know much, read the forbidden
(C), Konstantin Breeders
(C) NEVER Music
Today we highlight some issues of programming in
assembler, frequently encountered by novice programmers.
Perhaps this article will repeat some of their contents printed
or electronic publications, and someone may accuse our magazine
in it. Although it's worth remembering that not everyone has
home binder ZX-REVIEW though, would be for some
year. So who is strong in the codes and knows
many techniques, can safely leave
this article. And those who remained, we postaraemsya something
to figure out for the common good.
To start touch on a few procedures that are in ROM:
CLEAR xxxxx - Cleanup of variables BASICa, display,
install the stack and variable RAMTOP in new values. To emulate
this team in the codes of register pair BC must contain address
setting the stack. In this assembly would look like:
LD BC, xxxxx
CALL 7855 (# 1EAF).
If the BC contains 0 then there will
only treatment variables and the display area.
CLS - a program clearing the screen. Attributes are set,
respectively value of the variable ATTR-P (23693). When
accessing this program, enter data into the registers is not
necessary. It is called:
CALL 3435 (# 0D6B).
CLEAR-LINES - routine cleaning
the lower N rows of the screen. In case B recorded the number
of cleared lines:
LD B, N
CALL 3652 (# 0E44).
PAUSE - complete analog command
BASICa. The register contains a number of delays in BC, if it
is zero then return from the procedure will be accomplished
only while pressing:
LD BC, pause
CALL 7997 (# 1F3D).
Causing the program, do not forget to enable interrupts and
enable the first mode Interrupt (IM1), otherwise from this
procedure, you will be able to return only on the button RESET.
BREAK_KEY - a procedure that checks
Pressing BREAK (not to be confused
with a key SPACE). Called it:
CALL 8020 (# 1F54).
After returning from the procedure, thrown
carry flag indicates that there was
pressed BREAK.
PLOT - This procedures provided lights (or
quench, depending on system variables), on-screen point. In the
registration C - the X, Register B - Y:
LD B, Y
LD C, X
CALL 8933 (# 22E5).
DRAW - Program of the screen image a straight line. Here,
as well as in the procedure PLOT, in registers B and C are the
Y and X, but not fixed - the coordinates of the displacement.
In case D sign of the shift on the X, the sign in E
offset Y. That is, if the sign of the displacement of some
coordinates are: 255 (# FF), then the corresponding shift
will be treated with a minus-1 - a
offset will be with a plus sign; 0 - offset by a given
coordinate is simply ignored.
LD B, Y
LD C, X
LD D, the sign of Y
LD E, the sign for X
CALL 9402 (# 24BA).
CHAN-OPEN - routine used to
discovery channel. Novice programmers often forget to open a
channel "S" for using the routine from the ROM,
then with a puzzled look on the home it will be their message,
but still not where necessary, or, more interestingly,
pops "OUT OF SCREEN". To correct this procedure call, the
register A must find the number in the range from 253
(# FD) to 3. These numbers are the flows
leading to the channels: key "K", the screen "S", printer "P"
and the work area "R". Before you fluxes, leading
to the standard channels:
253 (# FD) - opens a channel "K"
254 (# FE) - opens a channel "S"
255 (# FF) - opens a channel "R"
0 (# 00) - opens a channel "K"
1 (# 01) - opens a channel "K"
2 (# 02) - opens a channel "S"
3 (# 03) - opens a channel of "P".
So, again, the procedure call
battery must contain the number of flow
(See table). Moreover, the procedure should
called in the thresholds and reduced
following lines:
LD A, the thread number
CALL 5633 (# 1601).
And in order to print properly in
the entire screen, it is necessary to register A Record
number 2 and call the procedure CHAN-OPEN.
SET_ADDR - calculation program addresses
familiarity on the screen. When referring to
This procedure must register B containing the coordinates X,
and the register C coordinate Y required familiarity. Instead
of a point entrance to the ROM, I present to you this listing
program.
LD B, Y coordinate
LD C, X coordinate
CALL SET_ADDR
............
SET_ADDR
LD A, B
RRCA
RRCA
RRCA
AND # E0
LD L, A
LD A, B
AND # 18
OR # 40
LD H, A
LD B, # 00
ADD HL, BC
RET.
After calling the procedure SET_ADDR address
familiarity in register HL.
SET_ATTR - This procedure calculates the address
attribute for the corresponding addresses from the field
points. At the entrance to the procedure of HL register must
contain the desired address from the field points. Also give
listing of this procedure.
LD HL, address
CALL SET_ATTR
............
SET_ATTR
LD A, H
RRCA
RRCA
RRCA
AND # 0B
OR # 50
LD H, A
RET.
Here in HL returned address attribute.
And now, here are a few simple
techniques required for writing programs in assembler.
Division registrovoy pairs at 2, 4, 8
etc. :
AND A
RR B
RR C.
If you repeat this example, N times you divide the number by 2
to the power N. This method can be divided and separate
registers.
Multiply the register-pair can be
analogy with the previous example, replacing
RR command on the RL:
AND A
RL C
RL B.
And if you need to multiply the register HL, then
it is better to make the team composition ADD:
ADD HL, HL multiplied by two
ADD HL, HL for four
ADD HL, HL for eight
........... etc.
Now, specific examples:
Multiplication HL six:
ADD HL, HL
LD B, H
LD C, L
ADD HL, HL
ADD HL, BC,
multiplication of the forty-HL:
ADD HL, HL
ADD HL, HL
ADD HL, HL
LD B, H
LD C, L
ADD HL, HL
ADD HL, HL
ADD HL, BC,
A division into six:
LD A, dividend
LD B, # 00
LABEL SUB # 06 (divider)
RET C
INC B
JR LABEL
the output of this procedure will be private
in register B (do not forget that
this method can only perform integer division ").
If you use to add
or subtraction of register pairs team:
ADC and SBC, remember - in the calculations they
use carry flag (CARRY FLAG).
Therefore, before the ADC or SBC for
correct results, this flag should
fold. Very convenient to do this by running AND A. The content
does not change the battery.
Incidentally, the ROM is SPECTRUMa
special powerful tool for a variety of mathematical
calculations. But she has several disadvantages, because of
which it It might be hard to use:
1.Vychisleniya made slowly enough. Therefore inappropriate to
use a calculator, for example, to calculate the coordinates of
the programs with dynamic vector graphics. 2.Rabota done with a
calculator somewhat unusual way, however,
familiar to those who ever worked at PMC (programmable
calculator. The essence of the paper is as follows: first STACK
Calculator (not a car!) Recorded values, and then operations
are performed with them. After which, again, with calculator
stack is lifted result. Without going deeply into details, we
give some entry points required for:
A value from the stack # 2D28
value from the stack in the A # 2DD5
value from BC on stack # 2D2B (*)
zanachenie from the stack in BC # 2DA2
*) When you return from this subroutine in
IY register is set to
23,610 (# 5C3A).
Now a small example of the practical application of the
calculator.
Necessary to calculate (21-Y) * 8 +3:
LD A, 21, puts on the stack
CALL # 2D28
LD A, (Y); values in order
CALL # 2D28
LD A, 8; Re computing
CALL # 2D28
LD A, 3, ie Y 21 March 8
CALL # 2D28
And now we will assume
RST # 28; incl. calculator
DEFB # 03; subtract
DEFB # 04; multiply
DEFB # 0F; we add
DEFB # 38; off. calculator
; Remove the result from the stack
CALL # 2DD5; result in A
Try to write your own
routine computations using this formula
without using a calculator and compare
and these two procedures.
Table of operation codes calculator
you can find in three volumes on programming in native firm
Inforkom. And if you can not find this literature, we will
share information in future editions of the magazine.
To enable this to take leave, and
if someone something is not clear or there
Questions - contact the Editor,
We will do our best and try to
help!
*