Assembly basic's #1 - Bits Bytes and other Shyte :)
First thing ya need to know is a little jargon so you can talk about
the basic data structures with your friends and neighbors. They are (in
order of increasing size) BIT, NIBBLE, BYTE, WORD, DWORD, FWORD, PWORD and
QWORD, PARA, KiloByte, MegaByte. The ones that you'll need to memorize are
BYTE, WORD, DWORD, KiloByte, and MegaByte. The others aren't used all that
much, and you wont need to know them to get started. Here's a little
graphical representation of a few of those data structures:
(The zeros in between the || is a graphical representation of the number of
bits in that data structure.)
1 BIT : |0|
The simplest piece of data that exists. Its either a 1 or a zero.
Put a string of them together and you have a BASE-2 number system.
Meaning that instead of each 'decimal' place being worth 10, its only
worth 2. For instance: 00000001 = 1; 00000010 = 2; 00000011 = 3, etc..
1 NIBBLE: |0000|
4 BITs
The NIBBLE is half a BYTE or four BITS. Note that it has a maximum value
of 15 (1111 = 15). Not by coincidence, HEXADECIMAL, a base 16 number
system (computers are based on this number system) also has a maximum
value of 15, which is represented by the letter 'F'. The 'digits' in
HEXADECIMAL are (in increasing order):
"0123456789ABCDEF"
The standard notation for HEXADECIMAL is a zero followed by the number
in HEX followed by a lowercase "h" For instance: "0FFh" = 255 DECIMAL.
1 BYTE |00000000|
2 NIBBLEs AL
8 BITs
The BYTE is the standard chunk of information. If you asked how much
memory a machine had, you'd get a response stating the number of BYTEs it
had. (Usually preceded by a 'Mega' prefix). The BYTE is 8 BITs or
2 NIBBLEs. A BYTE has a maximum value of 0FFh (= 255 DECIMAL). Notice
that because a BYTE is just 2 NIBBLES, the HEXADECIMAL representation is
simply two HEX digits in a row (ie. 013h, 020h, 0AEh, etc..)
The BYTE is also that size of the 'BYTE sized' registers - AL, AH, BL, BH,
CL, CH, DL, DH.
1 WORD |0000000000000000|
2 BYTEs AH AL
4 NIBBLEs AX
16 BITs
The WORD is just two BYTEs that are stuck together. A word has a maximum
value of 0FFFFh (= 65,535). Since a WORD is 4 NIBBLEs, it is represented
by 4 HEX digits. This is the size of the 16bit registers on the 80x86
chips. The registers are: AX, BX, CX, DX, DI, SI, BP, SP, CS, DS, ES, SS,
and IP. Note that you cannot directly change the contents of IP or CS in
any way. They can only be changed by JMP, CALL, or RET.
1 DWORD
2 WORDs |00000000000000000000000000000000|
4 BYTEs ³ AH AL
8 NIBBLEs ³ AX
32 BITs EAX
A DWORD (or "DOUBLE WORD") is just two WORDs, hence the name DOUBLE-WORD.
This can have a maximum value of 0FFFFFFFFh (8 NIBBLEs, 8 'F's) which
equals 4,294,967,295. Damn large. This is also the size or the 386's
32bit registers: EAX, EBX, ECX, EDX, EDI, ESI, EBP, ESP, EIP. The 'E '
denotes that they are EXTENDED registers. The lower 16bits is where the
normal 16bit register of the same name is located. (See diagram.)
1 KILOBYTE |-lots of zeros (8192 of 'em)-|
256 DWORDs
512 WORDs
1024 BYTEs
2048 NIBBLEs
8192 BITs
We've all heard the term KILOBYTE byte, before, so I'll just point out
that a KILOBYTE, despite its name, is -NOT- 1000 BYTEs. It is actually
1024 bytes.
1 MEGABYTE |-even more zeros (8,388,608 of 'em)-|
1,024 KILOBYTEs
262,144 DWORDs
524,288 WORDs
1,048,576 BYTEs
2,097,152 NIBBLEs
8,388,608 BITs
Just like the KILOBYTE, the MEGABYTE is -NOT- 1 million bytes. It is
actually 1024*1024 BYTEs, or 1,048,578 BYTEs
Now that we know what the different data types are, we will investigate
an annoying little aspect of the 80x86 processors. I'm talking about
nothing other than SEGMENTS & OFFSETS!