Nicron #10
05 декабря 1996

Programming - a course of study assembler Wlodek Black, continued.

<b>Programming</b> - a course of study assembler Wlodek Black, continued.
                                                         Z80

(Continued).

(C) WLODEK BLACK

            Logic team.

Logical operations are always performed bitwise. 
Rassmarivayutsya operands as sets of 8 bits, without linking 
them to the whole byte. From This, incidentally, implies that 
the logical operations never transfer occurs. Indeed, the 
output of all logic operations flag C = 0. 

Logical "AND": AND.
The truth table for AND:
1 AND 1 = 1
1 AND 0 = 0
0 AND 1 = 0
0 AND 0 = 0.
In the mnemonic indicates only the second operand:
AND E
AND (IX +0)
AND A.
AND A team does not change the contents of the battery, but the 
effect on flags. This team had to figure out (by the flag Z),

If A is equal to zero, as it is used to reset the flag C.
For its intended purpose AND is used, for example, the 
so-called masking. AND% 00011111, for example, would leave 
unchanged the lowest 5 bits, and 3 senior will be reset to 0. 

Boolean "OR" - OR.
The truth table for OR:
1 OR 1 = 1
1 OR 0 = 1
0 OR 1 = 1
0 OR 0 = 0.
Examples of mnemonics:
OR A
OR (HL)
OR 0A5H.
OR A similar command on the use of that AND A. Which
They use it - a matter of personal taste of the programmer.

A logical "EXCLUSIVE OR" - XOR.
XOR - a function that gives 1 only if both
operands are different.
The truth table for XOR:
1 XOR 1 = 0
1 XOR 0 = 1
0 XOR 1 = 1
0 XOR 0 = 0.
It is easy to see that XOR over itself always gives 0. XOR A 
team effectively resets to zero the battery, and this has 
gained popularity among programmers. Another valuable property 
of XOR is widely used: two consecutive XOR with the same second 
operand gives the starting number. In the computer graphics 
used are extremely simple and effective way: to completely 
remove superimposed on the background image, it must be ... 
apply again. Both times, the logic XOR, of course.



                     Team inversion battery.

Inversion means bit-reversal bytes. All units
in a byte will be zeros and all zeros - ones. Flags of the 
command is not touches.

Mnemonic: CPL (from ComPLement - opposite). Addressing -
Implicit to the battery. In conjunction with logical operators
CPL can be regarded as a function of NOT - denial.

Digression. Theoretically it is proved that anyone, even
most complex algorithm can be reduced to a finite sequence of 
operations "AND" and "NOT". 


       Operations on numbers in the decimal system.

It should immediately declare: Decimal arithmetic is 
inefficient. Presence in the system processor commands at least 
some decimal arithmetic can be explained only "atavism," the 
70-ies, when the scope of the microprocessor has only acquired 
its first vague shape. At present, the decimal system in the 
microprocessor systems used only at the stage input-output data 
that is, at the junction of the man-machine. All internal 
arithmetic in BASIC and other high-level languages, applied 
computational The program is taught in the binary system.



          Binary-decimal representation of numbers.

The number in binary-decimal system is represented as a 4-bit 
groups, each of which placed a number from 0 to 9. In a byte, 
thus, fit 2 digits, and the maximum value is 99 bytes: 
10011001BD = 99. 


            BCD data conversion.

Team DAA (Denary Adjust Accumulator) converts a number in the 
accumulator from the usual 8-bit representation in BCD form. 
For example, 66 in binary is equal to 01,000,010, and BCD - 
01100110. To add two binary-decimal numbers, you need to put 
them in the usual way through the ADD or ADC, and then execute 
DAA. The result then will and BCD. Similarly, running and 
subtraction. DAA team automatically detects the previous action 
by the flag N (it's unverifiable software flag, so he did not 
meet our teams go on the condition) and is also suitable for 
addition, and subtraction. Due to the fact that the command to 
work properly DAA possible only at-one establishing the fact of 
the previous addition or subtraction, there are some 
difficulties for the case convert a number, not the result of 
arithmetic operations. Such is the case, particularly in the 
initial appeal to this when the original binary number is 
loaded into the register of memory and must be converted to 
BCD. If you just issue the command DAA, it is even doing the 
right transformation may incorrectly set the flags. DAA does 
not change the value of the flag tag subtracting N, and the 
wrong value of this flag can proceed further. To avoid trouble 
before the first use of DAA should act on the flag N, following 
the example, the addition of a dummy with zero: ADD A, 0.


  As you can see, BCD arithmetic, really
ineffective. Byte is not fully used (99 instead of 255)
Programming is cumbersome ... And finally, there is no command, 
feedback DAA.



                  Teams for 16-bit arithmetic.

In the role of 16-bit accumulator performs a pair HL (rarely - 
registers IX, IY). ADD HL, DE ADC HL, DE ADD IX, DE ADD IY, DE 
SBC HL, DE ADD HL, BC ADC HL, BC ADD IX, BC ADD IY, BC SBC HL, 
BC ADD HL, HL ADC HL, HL ADD IX, IX ADD IY, IY SBC HL, HL

ADD HL, SP ADC HL, SP ADD IX, SP ADD IY, SP SBC HL, SP.

No teams ADC for index registers. You can not add IX or IY
with HL.
No team SUB general and SBC - to IX, IY.
Effect of instruction on flags:
ADD HL, rr, ADD I *, rr - carry flag C;
ADC - all flags;
SBC - all the flags.

Increment and decrement commands exist for all couples and 
index registers. INC HL; DEC IX, etc. Teams INC and DEC for 
16-bit pair does not affect the flags. Typically, these 
commands are used to increment address pointer, or various 
counters, the impact on the flags in such situations would only 
disturbing factor. 


                      Multiplication and division.

Teams MUL (multiple - multiply) and DIV (divise - split) can be 
used in programs running under DOS, allows you to set the 
current date. The only acceptable option date - 01 th of the 
04-th month of any year. In other days of the correct execution 
of these commands is possible only after the N-th cup: DIV A, 3 
- figure for three. Under repeated last set overflow flag P / 
V. At still over multiple repetitions may fail DRAM

(So-called failures of memory). Further abuse of this 
construction could lead to a serious accident is - overheating 
of the processor to the level of white heat (so-called delirium 
tremens). 

  But seriously, alas - multiplication and division in finished 
form no. Part of them, it happens, teams can replace the shift, 
but In the general case - the voluminous written procedures for 
the program implementation of multiplication and division.


[To be continued].





Other articles:

Entry - the contents of rooms.

BBS - list of stations BBS ZXNet.

Iron - an overview of the microprocessor Zilog Z380, continued.

Programming - a course of study assembler Wlodek Black, continued.

Graphics - kartinka ANSI graphics.

Search - search for game programs.

Humor - jokes and stories from life.

Advertising - advertising and announcements.

Feedback - contact the publisher.


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

Similar articles:
System - Overview of system programming: ZX Tools DeLuxe v 2.0
Mailbox - letters from readers.
Iron - scheme of the three drives in the Scorpius-ZS 256.
Hi Tech - Stingrey about the world of technology.
Question - why no one said a glitch in ACEdit?

В этот день...   3 May