Inferno #10
30 апреля 2007

For Coderz - Gray code and optimization programs.

<b>For Coderz</b> - Gray code and optimization programs.
     Gray code and optimization software

Lord Vader


             I. What is it


   Gray code commonly used in those cases
cases in which the measured parameter changes
by 1 sequentially in time, the NAM
Example, a mechanical valkoderah, some
ADC, etc. A classic example of the use
of Gray code - the signals from the optocouplers mechanical
cally mouse, having the form

X: _/~~~___/~~~_
Xq: ___/~~~___/~~~

and is a 2-bit Gray code.


   The main property of the Gray code - in the transition
progress to the next state in the N-bit ve
The quantity in the Gray code changes only one bit.
For example, for a 4-bit value sequence
sequence of Gray codes is as follows:



  0000

  0001

  0011

  0010

  0110

  0111

  0101

  0100

  1100

  1101

  1111

  1110

  1010

  1011

  1001
 1000


   Hence it is clear the rules for codes
Gray: at each step you have to change the most
LSB, which will not repeat
Niya code.


   It is also possible, and directly re
Led the usual binary code in the Gray code and
ago. Translated from the usual code in Gray code
(Examples in Assembler Z80) for 8-bit
quantity:

 Bin2Gray

         ; IN: A - in binary code

         ; OUT: A - in Gray code

         LD C, A

         SRL C

         XOR C

        RET


   Translated back:

 Gray2Bin

         ; IN: A - in Gray code

         ; OUT: A - in binary code

         LD C, A

        XOR A
 G2B_L

         XOR C

         SRL C

         JR NZ, G2B_L

        RET


   More details about the Gray code may be other
a thief in [1] and [2].



         II. Examples of optimization


   Imagine that you want napecha
thief character 8x8 in a linear screen buffer
(Where the lines go to each other and for ne
transition to the next should be added to the address
32).

   Code is received as follows:



        DUP 8

         LD A, (DE)

         INC E

         LD (HL), A

         ADD HL, BC; BC = 32

       EDUP


   For the addition of 32 required chains already
register a pair of barking. You can do this:



         LD A, L

         ADD A, 32

        LD L, A


   But either it is quite slow, or triangle
requires additional registers to store
number 32.


   Now try to sort out the address in
Gray code:



         LD A, (DE)

         INC E; SET 0, E

         LD (HL), A

        SET 5, L; 000> 001



         LD A, (DE)

         SET 1, E

         LD (HL), A

        SET 6, L; 001 011



         LD A, (DE)

         DEC E; RES 0, E

         LD (HL), A

        RES 5, L; 011 010



         LD A, (DE)

         SET 2, E

         LD (HL), A

        SET 7, L; 010> 110



         LD A, (DE)

         INC E

         LD (HL), A

        SET 5, L; 110 111



         LD A, (DE)

         RES 1, E

         LD (HL), A

        RES 6, L; 111 101



         LD A, (DE)

         DEC E

         LD (HL), A

        RES 5, L; 101> 100



         LD A, (DE)

        LD (HL), A; 100


   Thus, we at least got rid of
the use of additional registers
adding nearly beat to every copy
(Instead of INC E: ADD HL, BC - 2 SET / RES 'a).
If you also change the font according Baitik
tstvuyuschim way, you can always write
INC E - winning is obvious.


   A similar technique can be used
in other cases (no - he think:).
For the convenience of writing we can introduce two maximal
dew (example for the Arab assembler aka
Al-asma;).



        MACRO GRAY



         INC E

         SET 5, L



         SET 1, E

         SET 6, L



         DEC E

         RES 5, L



         SET 2, E

         SET 7, L



         INC E

         SET 5, L



         RES 1, E

         RES 6, L



         DEC E

         RES 5, L



       ENDM



        MACRO DOIT

         LD A, (DE)

         LD (HL), A

       ENDM

 And further:


        GRAY DOIT

lvd ^ mHm lvd@dgap.mipt.ru


               Literature:

1. P. Horowitz, W. Hill.
"The Art of circuitry," Chapter 8.
2. http://en.wikipedia.org/wiki/Gray_code




Other articles:

Likbez - Batteries. Practices.

Likbez - Batteries. Results of experiments with different batteries.

Opportunities Spectrum - The format ani-files on the ZX.

Inferno - The authors of the magazine.

Opportunities Spectrum - How to play multichannel music on beeper.

Opportunities Spectrum - Support for the DVD format on ZX.

Gameland - On the competition absurd (or clumsy) games for the ZX Spectrum - Crap Games Competition.

Graphics - How to quickly draw colorful pictures.

Inferno - Entered from the editor.

Inferno - Errors in the previous numbers.

For Coderz - Gray code and optimization programs.

For Coderz - Building a graphical user interface.

Formats - details on the decoder jpeg.

Iron - Description of Products K561PU4.

Inferno - Letters to the Editor.

Formats - The format of a packed file MegaLZ.

Scorpion ZS - The structure of the markup on a computer hard drive Scorpion.

ZX Clones - multiplatform on the ZX Spectrum. Computers SAM Coupe and MSX.

Advertising - Advertising NedoPC.

Inferno - On the shell.

Activities - The "Spectrum" at the competition on the night orienteering Okinchitsa 2004.

Softinka - Comparative table of the results of packing code files with various packers.

Advertising - Advertising King of Evil.

Softinka - Software for printing in the annex to the magazine.

Softinka - Music Editor Pro Tracker v3.71. Revision history.

Advertising - Ads by V. Bogdanovich.

Iron - Some RND-generators.

Opportunities Spectrum - A hardware scrolling on ZX Spectrum.

Pentagon - Sinhroselektor video at Pentagon. Problems and the scheme.

DIY - Universal TAPE interface. Scheme of loading and recording tapes.

Sound - Features audio device TurboSound FM.

DIY - The scheme of the analyzer state TTL output.

Future Spectrum - Video Display V9990. Enhanced graphics capabilities ZX Spectrum.

Softinka - Updates to the image viewer: ANSI viewer, MCX viewer.

Interview - An interview with musician X-Raizor of Omega Hackers Group.


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

Similar articles:
B.B.S. News - The work B.B.S. 'ca.
Comics - comics about cat Kesha.

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