Optron #25
19 апреля 1999

Likbez - Assembler view from afar: Working with bats, Comparison of the numbers, team comparisons.

<b>Likbez</b> - Assembler view from afar: Working with bats, Comparison of the numbers, team comparisons.
        Assembler: a view from afar

{} Infarh


  Continued. Home - a | | 20, 21, 24


             Working with bits


  Logical operations, we reviewed
last time, made over the whole byte. Now pay attention to the 
team working with individual bits. Well, that

They can be done? Obviously, to assign
their specific value, and check the status ... everything! 
Let's start with plants. 

  The team that set a specific
bit can be written as "SET" (from the English.
"Set"). And its parameters are
guidance on the processed bytes and bits
for installation. As usual, we give the spellings of this 
command: 


              SET b, r

              SET b, (HL)

              SET b, (ii + n)


  Do you think that such a "b"? Yes, quite right! This is the 
number of bits that we tormented the team. And these are 
numbered bits from junior to senior level. Here,

look:


 D7 D6 D5 D4 D3 D2 D1 D0



  Thus, if the processor meets
accidentally click


               SET 4, E

then discharge "D4" register "E" will be
unit.

  Now we turn to the team "RES".

  It is not hard to guess that its action
just the opposite team "SET", and it is in the reset of the 
specified bit. Here options for its writing:



              RES b, r

              RES b, (HL)

              RES b, (ii + n)


  So, we can already set and reset bits. But there is another 
very important effect. It consists in verifying bits, and Z80 
such a team, of course, there.


  Her mnemonic - "BIT". And the result of its implementation we 
get to the flag "Z", which is set if the checked bits is zero 
or, more precisely, is cleared. 

  Here vozozhnye options:


              BIT b, r

              BIT b, (HL)

              BIT b, (ii + n)


  As you can see all the spellings
the above instructions are absolutely identical. We only need 
to remember that when you run it might influence

the flags and see what it is expressed ...



      Mnemonic Register F Bits

                       (Flags)


    Operator
     pa-Operand C Z P / V S N H

     tion


     BIT b, r. x? ? 0 1

     BIT b, (HL)

     BIT b, (ii + n)


     RES b, r. . . . . .

     RES b, (HL)

     RES b, (ii + n)


     SET b, r. . . . . .

     SET b, (HL)

     SET b, (ii + n)



  Legend:

  "." - Flag is not changed as a result of the operation;

  "X" - flag is set depending
on the result of the operation;

  "?" - The value of the flag is not defined;

  Other designations - see | 21.


  The table shows that only a team
"BIT" affects flags, while
Other teams leave them unchanged.

  Well, as soon as we are talking about the verification
bits, it is appropriate to recall and control methods
total bytes. So ...



             Comparison of the numbers


  As you probably created the program
need to make a comparison of some
numbers for subsequent process control in the program itself.

  But how to compare the numbers and get the result in a form 
understandable to the processor? AND what is meant by "the 
numbers match? 

  So it is that they are equal. If this
fact express arithmetically, it will be


                A - B = 0


  And when compared to the A number greater than
(Because the comparison involves the ratio
between two numbers)? Then subtract the result will be 
negative. And if less, then yes.


  And now, based on subtracting the command SUB
try to develop a system comparison
Assembler.

  Suppose you want to compare the number of a certain range 
with the number 16: 


  LD A, 16, the number of available

  SUB n; compare the number


  Then we obtain the following:

  - If n = 16, then the zero flag (Z) installed, and the carry 
flag (CY) - cleared; 

  - If n <16, the zero flag and carry
reset;

  - If n> 16, the zero flag is cleared, and
carry flag set.

  As you can see, the method is quite efficient.
However, there is in him, and the lack of: changing the 
contents of the register "A". 

  And here to us comes to the rescue ...


            Team comparison


  It has the mnemonic "CP" (short for
English "compare" - to compare). Team
completely analogous to the subtraction, except that the 
contents of "A" does not change. The result affects only the 
flags. 

  Traitsionno present possible options:



      Mnemonic Register F Bits

                       (Flags)


    Operator
     pa-Operand C Z P / V S N H

     tion


      CP r x x V x 1 x

      CP (HL)

      CP n

      CP (ii + n)



  Explanation:

  Flag of the P / V (parity / overflow) indicates
just two different terms relating to
two fundamentally different groups of teams.
When performing the comparison operation availability
Overflow flag indicates that as a result of the arithmetic 
steps to change the sign operand.


  And at the end look at a small
table: it will help you choose which
operands in the registers which should be placed for best use 
of team comparisons. 



    Result Status Mnemonic

    compare flag conditions


       A = X Z = 1 Z


      A <> X Z = 0 NZ


     Unsigned comparisons (0 ... 255)


       A <X CY = 1 C


      A> = X CY = 0 NC


     In view of the sign (-128 ... 127)


       A <X S = 1, P


      A> = X S = 0 M



  Legend:

  1) The table shows which flags are set when equality or 
difference of operands in any direction. 

  2) In the "mnemonic conditions" describes testable flags when 
entering commands conventional type.


  3) The notation in the table below:

  CY = C = Carry

  NZ = (Z = 0)

  NC = (C = 0)


  I should note that I, for example, while
such a table in front of his eyes did not hang,
all time in terms confused.


             Until next time!







Other articles:

ZX-waggons - Overview of electronic media: Fanzine 7, Kr News, 7 February Polesie, ZX-News in 1945, Don News 4.

Iron - HDD at the Spectrum - Myths and Realities.

Likbez - Assembler view from afar: Working with bats, Comparison of the numbers, team comparisons.

Lit. Page - Grief "Y-II" (Diary - continued).

Advertising - Advertisements and announcements ...

Category X - Game Review: Twilight, Mirror, White Eagle, Kolobok Zoom 2, Quadrax, Chaos Zone.

Category X - Electronic media: yesterday, today and tomorrow.


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

Similar articles:
Demolition - Game Description THE DOOBLE.
Entry - ZXNet in Minsk.
Advertising - Advertisements and announcements ...

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