Number Systems
The first thing you need to know to program assembler is the basic terms.
A bit is short for BInary digiT, this is either a 1 or a 0. If a bit is
1 it is on or set. If it is zero it is off, or clear. 4 bits form a nibble.
8 bits form a byte. 2 bytes form a word. The Z80's commands mostly use
bytes and words. Some affect only bits, but not many. A byte, having 8
bits can hold numbers from 0 to 255 (unsigned) or -128 to 127 (signed).
I said earlier that there are 4 bits in a nibble, and 8 in a byte, but
that the Z80 was concerned with bytes. Why worry about nibbles? You use
them to represent any byte with symbols, rather than 1 to 3 (1 to 4 if
unsigned). If you had to type every byte in either your hand would grow into
your numeric keypad (PC users only, I think) or you would need a 256 key (at
least) keyboard. Since the nibbles are composed of 4 bits they can have any
of 16 values as shown below:
Number Nibble
0 0
1 1
2 2
3 3
4 4
5 5
6 6
7 7
8 8
9 9
10 A
11 B
12 C
13 D
14 E
15 F
When use in this way the nibble is called a hexit, for HEXadecimal digIT.
Just remember that we count in decimal / base 10, nibbles are hexadecimal /
base 16 and bits are binary / base 2. To tell which you're looking at in
an assembler program look before, after, and at the number. Decimal numbers
sit there looking normal or are followed by a "d" or "D". Hexadecimal numbers
start with a "$" or end with a "h" or "H". Binary numbers end in "b" or "B"
and are almost in groups of 8 or 16. Some languages let you specify a number
as hexadecimal by putting "0x" in front of it, but most people get along fine
with "d", "h" or "$", and "b".
Back to top
The Stack