Discovery Zone: Keeping Knowledge Free!
Search:
Keywords:
In Association with Amazon.com
Another great reference
cover
Assembly Language Programs and Organizations of the IBM PC

ASSEMBLY PROGRAMMING AND OS DESIGN


2. Intro to Assembly
2.1 Data Types
2.2 Registers
2.3 DOS Int Calls
2.4 Basic Commands
2.4.1 DOS Hello World
2.5 BIOS Int Calls
2.5.1 BIOS Hello World
2.6 String Routines

<HOME>

 

 

 

Another great reference
cover 80X86 IBM PC and Compatible Computers: Assembly Language, Design and Interfacing Vol. I and II

 

 

 

 

 

 

 

 

 

 

 

 

Need a good reference?
cover
Assembly Language Step-by-Step: Programming with DOS and Linux, 2nd Edition
CH2.1 Data Types

<HOME><TOC><PREV><UP><NEXT>

The BIT

As you have probably gathered from TV or casual reading, the world of computers is all about 0's and 1's. Microprocessors are made from millions of transistors which are basically like microscopic light switches. They can either be off (0) or on (1). Transistors can be looked at individually or in groups. Individually, a single off(0)/on(1) value is referred to as one BIT of information.

The system of numbers dealing with 0's and 1's is called the binary system. In the decimal system, the lowest value that a digit can represent is 0. The highest value is 9. In the binary system the only values that exist are 0 and 1. There is no '2' in binary. But there is a 2's place just as in decimal there is a 10's place. Each binary place moving from right to left represents a power of 2. In decimal, whenever we add and go above 9, we carry the one over into the next decimal place. Binary addition is the same except we carry whenever we go above 1. For example 9 + 1 = 10 in decimal. 11 + 1 = 100 in binary.

The NIBBLE

The first grouping of BITs we will look at is the NIBBLE. A NIBBLE consists of four consecutive BITS and is read from left to right. Each BIT in a nibble represents a power of two and can be summed together to get the number the NIBBLE holds. The powers begin with zero at the right most BIT and proceed up to three at the leftmost BIT.
1 1 1 1 8 + 4 + 2 + 1 = 15
1*2^3 = 8 1*2^2 = 4 1*2^1 = 2 1*2^0 = 1

0 1 0 1 0 + 4 + 0 + 1 = 5
0*2^3 = 0 1*2^2 = 4 0*2^1 = 0 1*2^0 = 1


With the NIBBLE comes a new way of writing numbers. The way we've already shown using 1's and 0's is called binary. Because each NIBBLE can be anything between 0 and 15, a new numbering system had to be invented to write 10 through 15 using only one symbol each. The method chosen was to use the first 6 letters of the roman alphabet where A or a = 10, B or b = 11, C or c = 12, D or d = 13, E or e = 14, and F or f = 15. Since this numbering system has 16 values per digit it is called hexadecimal. This works the same way as our decimal system where each digit represents values of 0 through 9 except that each place represents a power of sixteen instead of 10. The following figure demonstrates the difference.

Decimal

1 2 3 100 + 20 + 3 = 123
1*10^2 = 100 2*10^1 = 20 3*10^0 = 3

Hexadecimal

1 2 3 256 + 32 + 3 = 291
1*16^2 = 256 2*16^1 = 32 3*16^0 = 3

For the rest of this text, all binary numbers will have a 'b' tacked on the end and all hexadecimal numbers will have an 'h' tacked on the end. Decimal numbers will be written as usual so 0101b is the same as 5, 20h is the same as 32, and 1111b is the same as fh.

The BYTE

The next larger grouping of BITs is the BYTE. It consists of eight consecutive BITs or two consecutive NIBBLEs. The BYTE is the most common data type seen in computing because for a great deal of time it was the standard for computing technology. Even in the powerful processors of today, we can still see some traces of their distant 8 BIT pasts.

If you have done some playing around with the binary system, you may have noticed two things. #1 you can figure out how many different numbers can be represented by a given binary number by raising 2 to the power of the binary number's size. For example, a NIBBLE, or 4 BIT binary number can represent 24 or 16 different numbers. A BYTE can represent 28 or 256 different numbers. #2 Because 0 is always one of these numbers, the max value of an N BIT binary number is always 2N-1. So a BYTE can give you values from 0 to 255.

Because the BYTE consists of two NIBBLEs, it will always be represented with two hexadecimal digits even if it doesn't need it. The reason for doing this is because in the world of computing, every BIT is important. The reason why every bit is important is because we have to be able to deal with negative numbers. This pattern will continue as we get into larger data sizes, but let's look at negative numbers first.

Two's Compliment

The method for representing negative numbers in a binary system is called Two's Compliment. The history of its inception and how and why it works are beyond the scope of this text. For our purposes, we will accept that it was created to work with the circuitry of microprocessors and leave the why's and how's to a course on computer architecture.

Two's compliment works by taking the positive number you wish to make negative, inverting it, and then adding one to it. By inverting, I meant to take each of the BITs of the number and switching them to their opposite value, so 1010b becomes 0101b. The catch to this is that in order for the number to be recognized as negative, the first BIT of the number must end up being a 1. This means that we cannot take 255 and make it negative with only 8 BITs at our disposal. If we attempted to we would have 255 or 11111111b. Inverted, it becomes 00000000b. Adding one gives us 00000001b which is 1. The largest 8 BIT number that can be made negative is 128. 128 written out is 10000000b. Inverted, it becomes 01111111b. Adding 1 gives us 10000000b. The fact that negative 128 and positive 128 have the same binary form is merely coincidence. For the rest of this text, we will assume that all data types are signed, or capable of representing negative numbers, unless they are specified as being unsigned, or only capable of representing positive numbers.

The WORD

The next step up in data sizes is the 16 BIT WORD. WORDs are made up of 16 BITs or two BYTEs. Their usage will be fairly limited in this text beyond booting the machine. A word is capable of representing values between -32768 and +32767 or unsigned between 0 and 65535.

The WORD starts getting us into numbers large enough to group them into chunks. Just as 1000 meters can be read as 1 Kilo-meter, 1024 BYTES can be read as a Kilo-BYTE. The reason why we use 1024 instead of 1000 is because 1024 works out as a power of two. Specifically 1024 is the 10th power of two. The next sized chunk, Mega, is the 20th power of two. A word can represent 64Kilo-BYTES or 64KB which is the same as 0 through 65535.

The Double WORD or DWORD

The main data size we will use is the 32 BIT Double WORD. It consists of 32 BITs, or 4 BYTES of data. It is the default size of data used by modern day processors and will constitute the bulk of what our OS will do.

The Quad WORD or QWORD

The very near future will bring us into the world of 64 BIT computing. We will occasionally use QWORDs in our code, but OS's designed for AMD's new x86-64 64 BIT microprocessor will see the entire OS written with this as the base data type. 

<HOME><TOC><PREV><UP><NEXT>
 

www.cynergysoft.com

Email any questions to the author, Nathan Daniels.

Copyright © 2001