ZX Pilot #35
27 ноября 1999

Coding - code optimization techniques.

<b>Coding</b> - code optimization techniques.
                C O D I N G



(C) SERGIUS PUZZLER



                      - Dad, and Th me de
                      lat with this garbage?

                      - Yes, simply Zaksor

                      his son ...


                                  P. Fuzz.



   I'll be brief. If you frequently use a lot here this 
construction: 


        ...
M_FLAG1 EQU +1

        LD A, FLAG

        OR A

        CALL NZ, PROGA

        ...


   but want to simplify it and save a little, then I suggest 
you the following: 


        ...
M_FLAG1

        SCF; (or OR A)

        CALL C, PROGA

        ...


   Savings of 2 bytes multiplied
the number of such structures in your
program. - Not so much - you exclaim, - but I've not promised - 
will be response. SCF include a carry flag and work CALL C. OR 
A turn off the flag - CALL C naturally does not work.


   A controlled with a flag like this, Makar:

; ON FLAG

        LD A, # 37; SCF - FC = 1

        LD (M_FLAG1), A

        ...

; OFF FLAG

        LD A, # B7; OR A - FC = 0

        LD (M_FLAG1), A

        ...

; TOGGLE FLAG

        LD A, (M_FLAG1)

        XOR # 80

        LD (M_FLAG1), A

        ...


   Nothing new okromya XOR # 80, which
switches the seventh bit in the cell at
M_FLAG1 tinkering with SCF in OR A, or vice versa.

   If you have many addresses like M_FLAG1,
then, for programming convenience, I offer the following:


        ...

        LD HL, **; address of the selected flag

        CALL * _FLG; * - SET / RES / XOR

        ...


        ...
SET_FLG; INCLUDE

        RES 7, (HL)

        RET
RES_FLG; OFF

        SET 7, (HL)

        RET
XOR_FLG; SWITCH

        LD A, (HL)

        XOR # 80

        LD (HL), A

        RET

        ...


   Each procedure call SET / RES / XOR teperecha takes into RAM 
6/6/6 bts, and held - 5/5/8 bts. Thus the average We did not 
win, but not lost but, hopefully, become easier to program. And 
yet another procedure SET / RES / XOR (11 bts), ipolzuemaya for 
3 or more flags at the same time, saves. 


   Now a little about one another. In Miracle # 3
If my memory serves me (yes seems to be
no one) has an article about optimizing your code. Its author, 
PSV / Dream Team, led one procedure that requires clarification.


   To speed up the cycle of the form:


        ...

        LD BC, COUNT
LOOP

        ...

        cycle body

        ...

        DEC BC; works

        LD A, B; enough

        OR C; slowly

        JR NZ, LOOP

        ...


   He offered to do so:


        ...

        LD BC, COUNT
LOOP

        ...

        cycle body

        ...

        DEC C

        JR NZ, LOOP

        DEC B

        JR NZ, LOOP

        ...


   There is no doubt that this version works
faster, but it is checked (even in the mind) has identified an 
incorrect setting counter BC. Let me explain: if we run the 
following procedure (idiot actually has nothing to do with): 


        ...

        LD HL, 0

        LD BC, # 0101, 257 (DEC)
LOOP

        INC HL; cycle body

        DEC C

        JR NZ, LOOP

        DEC B

        JR NZ, LOOP

        ...


   at the exit of HL we find the value equal to 1, instead of 
the expected - 257. Conclusion: after setting the counter BC, 
it is necessary to adjust - to increase by 256. And here is the 
final version: 


        ...

        LD BC, COUNT

        INC B; missing team
LOOP

        ...

        cycle body

        ...

        DEC C

        JR NZ, LOOP

        DEC B

        JR NZ, LOOP

        ...


   Still not very tired? :) Yes? No? Press
"Y" for Yes or "N" for No. A better fit
stress. Right marker on the monitor.

   See you soon. In Kaa ...


                                    SP.WH!




Other articles:

News - news Kovroskogo Spectrum.

Event - Report from the Spectrum, Amiga pisishnoy exhibition and sale of Baltic Suscess.

Event - a survey of visitors Spectrum Amiga-pisishnoy exhibition and sale of Baltic Suscess.

Our Guest - the story Rion'a (ex ZSV) about the status of Spectrum in Apatity.

Humor - Hesereznaya story on the topic of Spectrum.

Coding - code optimization techniques.

We will understand - the passage of downhole toys Snoopy & Peanuts.

about different - Mitchell regards to spektrumistam.

about different - "Spectrum home computers as a class is disappearing. And it is a fact" ...

Hard & soft - bug-free music scheme of connection coprocessor AY-8910.

Birthday - spektrumistov congratulations on his birthday.

Poll - Questionnaire survey of Mitchell / Hardwave.

Poll - "Spectrum or very soon will die as a home computer or be reborn into something else" - respond or lose!

Advertising - advertising and announcements from spektrumistov.

Credits - the creators of the newspaper.


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

Similar articles:
IS-DOS - Information: The news in the world IS-DOS
Entry - poems and maintenance facilities.

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