|
Inferno #05
30 апреля 2004 |
|
For Coderz - Small programmers' tricks.

Etudes
1. Increment of 32-bit number
Done as follows:
INC (HL), HL
JR Z, $ -2
... And all:) And, as you can see, the procedure
universal - for 16/32/64/nn..-razryadnyh
numbers - if the passage through zero is guaranteed not to
happen. (It is in this form fragment is useful for counting
passage of a piece of software.)
Decrement under the same conditions realizable tsya
complicated:
XOR A
CP (HL)
DEC (HL)
INC HL
JR NC, $ -3
Or, if the likely passage through zero:
SCF
LD B, 4; number of bytes in the number of
LD A, (HL)
SBC A, 0
LD (HL), A
INC HL
DJNZ $ -5
And the growth rate for the same case:
SCF
LD B, 4; number of bytes in the number of
LD A, 0
ADC A, (HL)
LD (HL), A
INC HL
DJNZ $ -5
Zero can be recorded in C, if it is not in
other registers. INC HL in special cases
You can replace or at INC L INC H.
In the register, as you can imagine,
both operations look even simpler:
increment: decrement:
INC HL LD A, H
LD A, H OR L
OR L DEC HL
JR NZ, $ +3 JR NZ, $ +3
INC DE DEC DE
2. How to avoid unnecessary INCBIN'ov
You know, how can a alasme podgruzit
file one INCBIN'om in two different places? A
maybe more? :) I just needed this for Pro Tracker'a: Player on
my drive is a whole, but in memory it must
razrezan.A be done so with the help of feasting to the memory
through the braces:
ORG kuda_kopirovat, str_kuda_otkuda
DISP otkuda_kopirovat
DUP dlina/16
DW {$}
DW {$}
DW {$}
DW {$}
DW {$}
DW {$}
DW {$}
DW {$}
EDUP
ENT
Page Memory otkuda_kopirovat and
page kuda_kopirovat "should be the same page" str_kuda_otkuda.
I've tried all the options grouping DW:
through DUP'REPEAT / UNTIL, by enumerating
{$},{$+ 2}, etc., tried to change the $ a variable, but it
turned out that the above option is the fastest. In addition,
it is shorter, than {$},{$+ 2} ... :) The speed at 3.5 MHz -
about 1.5 kilobytes per second. For comparison, the rate of
DS - about 8 kbytes / sec.
3. One important note
It turned out the alignment of the boundary section (256
bytes), which I described in the ZX-Guide, obsolete. In the new
alasmah admissible even shorter design:
DS .(-$)
Her whole trick is that the DS 0 none
does not:)
Alignment on an even byte in this case is written as:
DS - $ '1
A byte alignment at a multiple of 8:
DS - $ '7
etc.
But the alignment of the nearest address
significant byte is equal to # F0:
ORG $ +15 / 256 <8 + # F0
or
ORG $ +15' # FF00 + # F0
(Generally, $ + a '# FF00 + b, where a = 255-b)
4. Control memory assembly
You never had to make in the source control memory overflow
for program? In order for oversized
Compilation display an some sort of message? Usually it is done
through IF, in which there is a comparison. A
Comparison of the syntax alasma - is subtraction, and check the
top bit. But not '# 8000, as one might think, but ...
<1'1. Much shorter:) Author - Capry.
Now, when our condition in the IF to perform (check its
working can be artificially extending the program for what some
DS'ami) to display a message. This makes DISPLAY. And then you
can (but not required) and abort the compilation - it is
make the directive INCBIN with some
wild-file name.
A. Coder 03/08/2004
Other articles:
Similar articles:
В этот день... 29 November