Deja Vu #08
31 мая 1999

CODING - The Optimization - Building a table repetition of bytes.

<b>CODING</b> - The Optimization - Building a table repetition of bytes.
AY-Track: L I G H T
__________________________________________


(C) 1999 DaniEl / PGC / BDA and MAX / Cyberax / BDA
__________________________________________



           The optimization # 02



   If you are already coded and soptimizirivali
All that could, today I offer you
smash his head.

   Objective: Build a table repetition of bytes. Based on an 
array of length CODLEN. The first byte of the table is the most 
frequent, last, respectively, the rarest,

if some codes in the array not applicable,
the frequency of repetition of this byte is equal to
zero.

   Below is a listing that performs
this task. This requires you to try
soptimizirovat this protsedurku (to reduce the volume of the 
object code). Results necessarily be published in subsequent 
issues Deja VU. 

   Describe the algorithm will not, try to understand 
themselves. I can only say that first creates a table of 512

bytes, the first two bytes - the number of codes # 00 in the 
array length CODLEN, second two bytes - the number of codes # 
01, etc., to # FF.



; (C) 19.02.1999 DaniEl / BDA
; Last optimization 22.02.1999



       ORG # 8000


CODLEN EQU # 4000; the length of the code block
STRTAD EQU # C000; start code block

START DI

       LD HL, D_BUFF

       PUSH HL

       LD DE, D_BUFF +1

       LD BC, # 2FF

       SUB A

       LD (HL), A

       LDIR



       LD B, A

       POP IX; IX = D_BUFF
M1 PUSH BC

       LD DE, 0

       LD BC, CODLEN

       LD HL, STRTAD
LOOP CPIR

       JR NZ, JUMP

       INC DE

       JP PE, LOOP
JUMP LD (IX +0), E

       LD (IX +1), D

       INC IX

       INC IX

       POP BC

       INC A

       DJNZ M1



       LD IY, KERNAL

       LD DE, CODLEN
L2 LD IX, D_BUFF

       LD BC, 0
L1 LD L, (IX +0)

       LD H, (IX +1)

       OR A

       SBC HL, DE

       CALL Z, MAX
L3 INC IX

       INC IX

       INC C

       DJNZ L1



       DEC DE

       LD A, D

       OR E

       JR NZ, L2

       LD IY, 23610

       EI

       RET


MAX LD (IY +0), C

       INC IY

       RET


D_BUFF DEFS # 200; first 2 bytes - number
                ; Honors # 00 bytes, then

                ; Two bytes - the number of bytes

                , # 01, etc., up to # FF.

KERNAL DEFS # 100; result of work-tabulated
                ; Ka repetition rate

                ; Bytes. First, the hour
                , Th, the last-best Ed
                ; Cue.


   The length of the procedure exactly 100 bytes. Disadvantage 
- very slow work, and about 40 seconds on one bank of memory 
(depends on density data).


   After writing this procedure, it decided to soptimizirovat 
MAX / Cyberax / BDA. The result of his work was the procedure 
length of 93 bytes and a maximum of 4 working seconds at one 
bank. 

   Disadvantages - bind to address, aligned along the boundary 
of 256 bytes (from the beginning of this section), in addition, 
a small deviation from the goal, and specifically, the 
resulting table contains the full range bytes from # 00 to # 
FF, while it is not should contain bytes that are absent in

the test array.

   The algorithm of this procedure is absolutely
another. First, a table 512 bytes (two sections), in the first 
paragraph are the low byte, the second-highest. However, the 
major and minor B form the number of repetitions in the test 
array in the range from # 00 to # FF. Further sorting occurs in 
the following way - compares the first two items in the table 
if the second than the first, then they change places, and then 
compare the elements of the second and third ..., etc. As a 
result, sorted both tables. (But we need

only the second - 256 bytes)

   For maximum speed MAX
decided to almost completely eliminate the use of index 
registers, as well as used in large loops team JP

instead of JR.

   Here's listing of this procedure:

; (C) MAX / CYBERAX / BDA, 02.1999
; OPTIMIZATION


       ORG # 7000


BUFF EQU # 80; SENIOR address byte # 8000

               ; For tables of 512 bytes.
TABLE EQU BUFF +2; STARSH.BAYT address # 8200

                 ; FOR TABLES 256 bytes.

BLOCK EQU # C000; STARTING ADDRESS BLOCK.
CODLEN EQU # 4000; block length

MK_TAB LD HL, BUFF * 256

        LD DE, BUFF * 256 1

        LD BC, # 200

        LD (HL), L

        LDIR
MK_TB LD (HL), L

        INC L

        JP NZ, MK_TB

        LD H, BUFF

        LD DE, BLOCK

        LD C, CODLEN/256; SENIOR BYTES LONG

                      ; B = 0
TB_LP LD A, (DE)

        LD L, A

        INC (HL)

        JP NZ, NO_HIGH

        INC H

        INC (HL)

        DEC H
NO_HIGH INC DE

        DJNZ TB_LP

        DEC C

        JP NZ, TB_LP


; Start sorting

SORT0 LD HL, BUFF * 256

        LD HX, 0
SORT1 LD E, (HL)

        INC H

        LD D, (HL)

        INC H

        LD A, (HL)

        INC L

        DEC H

        LD B, (HL)

        DEC H

        LD C, (HL)

        EX DE, HL

        AND A

        SBC HL, BC

        EX AF, AF '

        ADD HL, BC

        EX AF, AF '

        EX DE, HL

        JR NC, NO_SWAP

        LD (HL), E

        INC H

        LD (HL), D

        INC H

        LD E, (HL)

        LD (HL), A

        DEC L

        LD (HL), E

        DEC H

        LD (HL), B

        DEC H

        LD (HL), C

        INC L

        LD HX, # FF
NO_SWAP LD A, L

        INC A

        JP NZ, SORT1

        INC HX

        JP Z, SORT0

        RET



   You may be interested area
application of these procedures? My answer is that their
can be applied, for example, when writing
different packers. I wonder - what
thinks about Dmitry Pyankov of
Gorno-Altaisk?


      And let the luck you can not leave!




Other articles:

Aperativchik - On the control of the shell DEJA VU

Aperativchik - Number came late in the month.

Aperativchik - Freebies will be no more.

Topic - Provision # 2. Perspective.

Topic - On working with electronic drive in the IS-Dos.

Topic - A new crossroads - some of the complexities of the game The Castle.

Topic - the printer and the ZX-Spectrum (command system printer family Epson).

drop of solder - Ode to watch.

drop of solder - Scanner v1.3.

drop of solder - Disk protector v1.4 (scheme).

SOFTWARE - Overview of new products demos: Iris UltraDemo, Lazarus Trackmo, Russian Fields of Experiments, Pressure Trackmo.

SOFTWARE - Overview of new products games: White Eagle, Leprekon, Kozel, Puzzle (prerelease of Flash), Space, Translate Worlds, Devil-s Curse, Choppers: death match, Twilight: The Land of Shadows, Falen Angel, 12 Secret Book, The Cezar, Chainick horror in Flat.

SOFTWARE - Review sistemok: ASCII Convertor v2.71, Global Commander v1.31, BA v1.0, X-Copy.

SOFTWARE - Men like gods: the script for the game Elite III

SOFTWARE - The work of the program to print images XL-graph.

CODING - The Optimization - Building a table repetition of bytes.

CODING - Universal Player - Pro Tracker v3.31.

CODING - an undocumented feature of the processor Z80.

CODING - Conversion of graphics into text format ASCII.

CODING - How to create uncopyable whereas sector.

CODING - BUGS in Plaeyer-e Pro Tracker 3.x

ANOTHER WORLD - CPU Pentium III.

ANOTHER WORLD - At the crossroads of three worlds.

ANOTHER WORLD - News from the world of Amiga.

ANOTHER WORLD - My Choice - PC?.

Hall of Fame - What do we think about the scene.

Hall of Fame - Everyone on party!

Hall of Fame - On CD-ROM project from the city of Kemerovo.

Seven and 1 / 2 - April Fools' Day.

Seven and 1 / 2 - Purposely not think: seven stories from the seller to ZX software.

Seven and 1 / 2 - Anecdotes.

attempt at writing - Amiga rulez or suxx?

Advertising - Advertisements and announcements ...


Темы: Игры, Программное обеспечение, Пресса, Аппаратное обеспечение, Сеть, Демосцена, Люди, Программирование

Similar articles:
Razbiralka - Prohodilka the game BLINKY'S SCRAPY SCHOOL.
solid jokes - Collected sayings of Soviet officers (continued).
Advertising - Advertisements and announcements ...
Iron - scheme of adjustment signals Wait and Int for multicolor.
ZXNet - Supertusovka sisopov ZXNet will ...

В этот день...   21 November