Hello! We continue the cycle of
topics dedicated to teaching programming
language in ASSEMBLY. And today we'll talk
about things like:
FORMS OF REPRESENTATION OF NUMBERS
IN THE Z-80 PROCESSOR
_________________________________________
1.Numerical systems.
In order to master programming
writing in machine codes and in Ac-language
a assembler needs to know how to organize
storage of information in memory cells is essential
and in processor registers. Main unit
The information storage unit is a byte,
which in turn consists of eight
bits Bit can be turned on (equal to 1)
or disabled (equal to 0), i.e. may
take only two values, and the byte corresponds
respectively, can accept 256 (two per
eighth power) values and has a range
zones from 0 to 255.
The numbers we deal with
everyday practice are called ten-
teric. They are built from categories (single
prostrations, tens,hundreds, etc.), each of
which can be expressed by a power of number
10. So 567=5*10E2+6*10E1+7*10E0. Computer
teru to work in decimal system
very inconvenient. Since the information in
it is represented by electric charges
and only two stable ones can be identified
states - there is a charge / no charge, then
the most convenient thing is to store the numbers in
computer in binary system. For example
the usual decimal number 156 can be
written in binary form as 10011100B.
Here the letter B at the end means that
the number is written in the binary (BINARY) system
meh. Convert it to decimal form
mu can be expanded by power of 2
just like we did for the number 567 you-
further, arranging it in powers of 10.
10011100 = 1*2E7+0*2E6+0*2E5+1*2E4+1*2E3+
+1*2E2+0*2E1+0*2E0 = 128+0*64+0*32+16+8+
+4+0*2+0*1 = 128+16+8+4= 156
You see the obvious disadvantages of binary
registration forms. Firstly it's very
loud recording, and therefore very tiring
solid. Secondly, it is difficult to translate
is divided into our familiar decimal form.
All this would cause a lot of errors if
programmers developing a program,
used binary representation of numbers.
Much more convenient to work withhexadecimal
ny system. It has as a basis
The number is 16, so it’s already two digits
you can express 256 integers from 0 to
255 (since 16E2 = 256). Because for
hexadecimal system is missing
Arabic numerals, then to express hexadecimal
decimal digits 10...15 account for the
go to the letter designations:
10-A
11-B
12-C
13-D
14th
15-F
The same number 156 in sixteen-
ric form will be written as 9Сh. Here
the letter h at the end of the number indicates that
it is written in hexadecimal
(NEXDECIMAL) system.
9C = 9*16E1+12*16E0 = 144+12 = 156
A novice programmer faces
question: which system to work in - ten-
teric or hexadecimal? For ten-
teric there is only one argument - many
summer practice. Hexadecimal system
The topic is convenient due to the simplicity with which
the binary form is translated into it, but
binary formreflects the physical essence
operations, which makes hexadecimal
basic system for programmers.
Ease of conversion from binary to
hexadecimal and vice versa providing
is due to the fact that the number is sixteen
can be expressed by the fourth clause
penu number two: 2E4=16. Therefore, what-
would be to convert numbers from binary form to
hexadecimal can be translated
for every nibble (for every four
bits separately). Choosing which system
In the future, you also need to work
take into account that most application programs
frameworks that support programming in
machine codes work in hexadecimal
new system. According to MAXWELL 'Pos-
le transition to the hexadecimal system
started to sleep peacefully: no need hundreds of times
recalculate screen addresses - the numbers themselves
are lined up the way I want.'
Below is a table for the relationship between
systems:
DEC BIN NEX DEC BIN NEX
0 0000 0 1 0001 1
2 0010 2 3 0011 3
4 0100 4 5 0101 5
6 0110 6 7 0111 7
8 1000 8 9 10019
10 1010 A 11 1011 V
12 1100 C 13 1101 D
14 1110 E 15 1111 F
2.Binary complement form.
The above binary form is possible
allows you to work with positive integers
numbers from 0 to 255. This binary form
ma is called absolute, and operations with
such numbers - absolute binary
arithmetic.
At the same time, there are operations in which
Negative integers are required
numbers. For example, these are transition operations
(analogous to GO TO). The transition can be carried out
distributed both forward N steps and forward
ass .
When the processor encounters such a command
it accepts the following code
operations operand N is not as written in
absolutely binary form, but as written -
numeric in complement binary form. B
integers can be written to this form
from 0 to 127 and from -128 to -1. This way
So, it can be used to record whole
signed numbers. Let's look at an example with
gradual battery expansion foradditional binary arithmetic.
Flag C register F Register A HEX DEC
0 0000 0000 00 00
0 0000 0001 01 01
.......................
0 0111 1111 7F 127
0 1000 0000 80 -128
0 1000 0001 81 -127
.......................
0 1111 1111 FF -1
1 0000 0000 00 0
.........it.d.........
Remember the simple rule of binary
additional arithmetic: to change
sign of the number, you need to replace all its units
to zeros, and all zeros - to ones and to re-
add 1 to the result.
+5 is 0000 0101
-5 is 1111 1010 + 1 = 1111 1011
Addition and subtraction in thissystem
are executed as usual (bitwise), but
carry when the most significant bit overflows
ignored.
So 5 + (-5) = 0
0000 0101
+
1111 1010
=
0000 0000
3. Decimal arithmetic in binary
expression.
This is a special type of representation of integer numbers.
sat in the processor registers. It's called
BCD arithmetic. BCD - BINARY CODE
DECIMAL (BINARY CODE OF DECIMAL CHI-
SEL).
This form is based on the fact that everyone
the digit of a decimal number can be represented
expressed as four binary bits:
0 - 0000
1 - 0001
2 - 00103 - 0011
4 - 0100
5 - 0101
6 - 0110
7 - 0111
8 - 1000
9 - 1001
Values from 1010 to 1111 - not used
there are .
A four-bit group is called a half-bye
volume and thus one byte in this
form may contain a two-digit ten-
teric number from 0 to 99.
As you can see, one nibble in BCD is
in arithmetic can contain a number from 0 to
9, while in absolute binary
arithmetic from 0 to 15. Obviously, BCD
- arithmetic is quite wasteful
telny, but it has its advantages.
For two numbers in BCD arithmetic the usual
basic principles of addition and subtraction
menima. This happens because in ab-
In absolute binary arithmetic, a nibble is
is filled when it is equal to 1111 and
then there is a transition to the older one
category. In BCD arithmetic, a nibble is
full when it is 1001 and already here
transition occursto an older age
row.
The processor instruction set contains only
three teams that work with numbers,
presented in this form, but they are
are quite common, because they
application greatly simplifies the pre-
generating numbers before displaying them on the screen
in decimal form.
BCD arithmetic involves the flags N and
N.
Flag N - addition/subtraction flag.
It is equal to 1 for all subtraction operations and
equals 0 for all addition operations.
Flag H is a half-carry flag.
It turns on when the junior overflows
nibble when padding begins
high nibble.
* * *
Well that's all for today. I hope that I
expressed himself in not very learned language and to you
everything was clear. And I say goodbye to you. Before
meeting in the third issue of 'REALTIME'!
Share your thoughts about the article