Part A Fundamentals of PC Hardware and Software


Chapter 1 Introduction to PC Hardware


Introduction


1. The fundamental building blocks of a computer are the bit and the byte. By these data and instructions are represented in the computers memory.

2.The main internal features of a computer are a microprocessor, memory and registers.

3.The main external features are input and output devices such as keyboard, monitor, and disk. Software consists of various programs and data files on disk.

4.To run or execute a program it first must be loaded into the computer memory.

5. The microprocessor executes the program’s instructions and the registers handle arithmetic, data movement and addressing.


6. An assembly language program consists of one or more segments for defining data and for storing machine instructions and a segment named the stack that contains stored addresses.


Bits and Bytes


1. The smallest unit of data in a computer is a bit.

     A. A bit may be unmagnetize, or off for a value of 0, or it may be magnetized or on for a value of 1.

     B. The word bit comes from two words binary and digit. A bit is a binary digit.

     C. A group of nine bits is called a byte which represents storage locations both in internal memory and

          on external disk.

     D. From left to right the first eight bits are used for data and the ninth bit is for parity.

     E. The total number of on bits must be odd, so the parity bit is on or off depending upon the number

          of 1's in the data bits. If an even parity is detected this is usually a result of a hardware error or an

          electrical disturbance.


2. From now on, we will not be concerned with the parity bit and when we discuss the byte we will

     concentrate on the eight data bits which we will number from right to left with 0 through 7.


Related Bytes


1. A program can treat a group of bytes as a unit of data commonly called a field. A computer supports

    certain sizes that are natural to it:

    A. Word on a PC consists of 2-byte field. The bits are labeled from right to left as 0 to 15.

    B. Doubleword is a 4-byte (32-bit) field

    C. Paragragh is a 16-byte (128-bit) field

    D. Kilobyte (KB) 210 = 1024 bytes; referred to as a K

    E. Megabyte (MB) 220 = 1,048,576 bytes; referred to as a M or one megabyte




Binary Numbers


1. Because a computer can only distinguish between 0 and 1, it works in base-2 or binary.

    A. A collect of bits can represent any numeric value.

    B. A byte can represent the integer values of 0 to 255.

    C. A byte can represent the ASCII code which is a collating sequence.

         For example, the letter A is a decimal 65.

         Depending upon the programs focus a 65 can be either the letter A or the decimal value of 65.

    D. If we are working with 16 bits then we can represent numbers between 0 and 216 - 1 = 65,535.

    E. If we are working with 32 bits then we can represents numbers between

         0 and 232 - 1 = 4,294,967,295.


Binary Arithmetic


1. A microprocessor performs arithmetic only in binary format. Thus an assembly language programmer

     must be familiar with binary format and binary addition.

2. In binary 0+0 = 0, 0+1 = 1, 1+0 = 1, and 1+1 = 11 or 3 in decimal.



Negative Numbers


1. To do subtraction we must use two’s complements.

2. The two’s complement of a number is found by first reversing each bit of the number and

    then adding 1. For example, +65 = 01000001, if we reverse its bits we get 10111110. Adding 1,

     yields -65 = 01000001.

3. If we were count backwards from +3 to -3, we would get 00000011, 00000010, 00000001, 00000000,

    11111111, 11111110, 11111101.


Hexadecimal Representation


1. If we use base 16 or hexadecimal representation, we can more easily represent bytes.

2. By dividing the byte into two 4 bit sequences we can replace the four bits with one hexadecimal

    number.

3. The hexadecimal numbers range from 0 to F where F corresponds to 15. A through F are used to

     represent 10 through 15.

4, Assembly language makes considerable use of hexadecimal format.

5. To indicate a hex a number in a program, code an “H” immediately after the number;

     thus 25h= decimal 37.

6. By convention, a hex. number always begins with a decimal digit 0-9, so you should code

    B8H as 0B8H.

7. In this book, we indicate a hexadecimal value with the word hex or “H” following the number

     (such as hex 4C or 4CH); a binary value with the word binary or a “B” following the number

     (such as binary 01001100 or 01001100B); and a decimal value simply by a number (such as 76).




Converting from Decimal to Hexadecimal and from hexadecimal to Decimal


Appendix A give as explanation of this technique.

Given any number in a base 16, we have h1h2h3...hn = hn + 16(hn-1 + 16(hn-2 + 16(... +16 h1)...) in decimal.


Example: A4B6H = 6 + 16(B + 16(4 + 16A))


To convert from decimal to hexadecimal, we use the division algorithm, a = 16q + r where q is quotient when a is divided by 16 and r is the remainder. Note that r is between 0 and 15 inclusive. For example, the number

2548 = 16(159) + 4; 159 = 16(9) + 15. So 2548 = 16(15 + 16(9)) + 4 = 9F4.


ASCII Code


To standardize the representation of characters, micro computer manufacturers have adopted he ASCII (American National Standard Code for Information Interchange) code. The 8-bit extended ASCII code that the PC uses provides 256 characters, including symbols foreign alphabets. Appendix B provides a list of the 256 ASCII characters.


The Processor


An important hardware element of the PC is the system unit, which contains system board, power supply, and expansion slots for optional boards. Features of the system board are an Intel microprocessor, read-only memory (ROM), and random access memory (RAM).


The brain of the PC and compatibles is a microprocessor based on the Intel 8086 family that performs all processing of instructions and data. Processors vary in their speed and capacity of memory, registers, and data bus. A data bus transfers data between the processor, memory, and external devices, in effect, managing data traffic.


8088/80188. These processors have 16-bit registers and 8-bit data bus and can address up to 1 million bytes of internal memory. The registers can process two bytes at a time, whereas the data bus can transfer only one byte at a time. The 80188 is a soup-up 8088 with a few additional instructions. Both types of processor run in what is know as real mode, that is, one program at a time.


8086/80186. These processors have a 16-bit data but and can run faster. The 80186 is a soup-up 8086 with a few additional instructions.

 

Both the 8086 and 8088 have a 20-bit address bus, allowing them to address up to 1MB of memory.


80286. This processor can run faster than the preceding processors and can address up to 16 million bytes. It can run in real mode or protected mode for multitasking. This processor has a 24-bit address but which allows it to address up to 16MB of memory.


80386. This processor has 32-bit registers and a 32-bit data bus and can address up to 4 billion bytes of memory. It also can run in real or protected mode for multitasking.


80486. This processor has 32-bit registers and a 32-bit data bus and is designed for enhanced performance. It also can run in real or protected mode for multitasking.


Pentium ( or P5). This processor has 32-bit registers and a 64-bit data bus and can execute more than one instruction per clock cycle.


Pentium Pro (or P6) This processor is connected to a built-in storage cache by a 64-bit wide bus.

Pentium II, III, and IV. These processors have a Dual Independent Bus Design that provides separate paths to the system cache and to memory.

 

Starting with the 80386 throught the Pentium , these processors have 32-bit address bus for accessing memory. This allows them to access up to 4GB of memory. However, by using the segment registers as selectors, this gives a virtual 48-bit address which allows the processor to access up 64TB of virtual memory. Note 2-bits of the segment registers is not used in the addressing of memory.

The Pentium Pro and Pentium II can address up to 64 GB of physical memory.

What size address bus would they have?

 

Execution Unit and Bus Interface Unit for 8086/88 Processors


The processor is partitioned into two logical units: and execution unit EU and a bus interface unit BIU. (Use overhead) The EU executes instructions and the BIU delivers instructions and data to the EU

The EU consists of the ALU, CU, and a number of registers These features provide for execution of instructions and arithmetic and logical operations.

 

The most important function of the BIU is to manage the bus control unit, segment registers, and instruction queue.

The BIU controls the buses that transfer data to the EU, to memory, and to external input/output devise, whereas the segment registers control memory addressing.

The BIU is also used to fetch instructions from memory and store them in the instruction queue. Depending upon the processor this queue is from 4 to 32 bytes in size.

The BIU is able to look ahead and fetch instructions so that there is always a queue of instructions ready to execute.

The EU and BIU work in parallel, with the BIU keeping one step ahead.

The EU notifies the BIU when it needs access to data in memory or an I/O device. The EU requests machine instructions from the BIU instruction queue.

The top instruction is the currently executable one, and while the EU is occupied executing an instruction, the BIU fetches another instruction from memory. This fetching overlaps with execution and speeds up processing.

All these processors up through the 486 have what is known as a single pipeline, which restricts them to completing one instruction before starting the next. The Pentium and later processors have a dual pipeline structure that enables it to run many operations in parallel.

 


 

Internal Memory


A microcomputer contains two type of internal memory: random access memory (RAM) and read-only memory (ROM). Bytes in memory are numbered consecutively, beginning with 00, so that each location has uniquely numbered address.


ROM. ROM is a special memory chip that can only be read. The ROM Basic Input/Output System (BIOS) begins at address 768K and handles input/output devices, such as a hard disk controller. ROM beginning at 960K controls the computer’s basic functions, such a power-on self test, dot patterns for graphics, and the disk self-loader. When you switch on the power, ROM performs various check-outs and loads special system data from disk into RAM


RAM. This is the part of memory that concerns the programmer. When the computer is turned on the COMMAND.COM program is loaded into RAM (memory). Since this program occupies a small part of memory, another program can be loaded into memory. This action will overwrite any previous program that was in this area of memory.

 

 


 

 

Addressing Memory Locations


Given a two byte sequence of numbers such as 0401H. The system stores these bytes in reverse order. The lower byte 01 is stored first and then 04 is stored from left to right. The processors expects data to be stored in reverse order and when it retrieves the data it reverses its order.



Segments and Addressing


A segment is a special area in a program that begins on a paragraph boundary, that is a location that is divisible by 16 or hex 10. A segment in real mode can be up to 64K bytes. There may be any number of segments. A segment is addressed placing its address in the appropriate segment register. The three main segments are the code, data, and stack segments.


 

Code Segment


The code segment contains the machine instructions that are executed. The CS registers references that segment of memory. If your code is requires more than 64K then it will need to occupy more than one segment.


Data Segment


The data segment contains a program’s defined data, constants and work areas. The DS register is used to reference this segment. Again if the data requires more than 64K your program may need to define more than one data segment.


Stack Segment


The stack contains any data and addresses that you need to save temporarily or for use by your own called subroutines. The SS register address the stack segment.


Segment Boundaries


The SS, DS, CS contain the starting address of these special segments. The ES register is for an extra segment and on the 80386 there is the FS and GS registers which have special uses. Since segment address start on paragraph boundaries they are divisible by hex 10. This means that the right most hex digit is a zero. The computer designers don’t store this in the segment register; that is , 045F0H is stored as 045F. The rightmost zero is understood.


Segment Offsets


To address a particular byte within in a segment a two byte 16 bit offset is used. With 16-bits 65,535 bytes (64K) can be addressed within any segment. For example, if the DS register contains 045F0H and the offset into the segment is 0032H then the actual address is 04622H.


Addressing Capacity


The PC addressing capacity varies by Intel processor used.


8086/8088 Uses 20 bits to form an address and thus can address up two 1,048,560 bytes

(1 MB). Recall that the rightmost hex digit of the segment address is zero so that a segment register being only 16 bits can store up to FFFF. So the address is actually FFFF0 which is equivalent to 1,048,560 in decimal.


80286. In real mode same as 8086. In protected mode the processor uses 24 bits for addressing so that FFFFF0 can address up to 16 million bytes. The 16-bit segment registers acts as a selectors for accessing a 24-bit segment address form memory and add this value to a 16-bit offset.


80386/486/586. In real mode same as 8086. In protected mode, the processor use 48 bits for addressing which allows for addressing segments up to 4 GB. The 16-bit segment registers act as selectors for accessing a 32-bit segment address from memory and add this value to a 32-bit offset address.


Registers


The processor’s registers are used to control instructions being executed, to handle addressing of memory, and to provide arithmetic capability. The registers are addressable by name. Bits are conventionally numbered from right to left, as in ... 15, 14, 13, 12, 11...1,0


Segments Registers.


CS register. Stores the starting address of the code segment. This segment plus an offset in the IP (instruction pointer register) indicates the next instruction to be fetched for execution. For normal programming purposes the CS register is not referenced by the programmer.


DS register. This is used to reference the data segment. This address value plus an offset will reference data stored in the data segment.


SS register. The SS register permits the implementation of a stack in memory, used for temporary storage of addresses and data. DOS stores the starting address of a program’s stack segment in the SS register. This address plus an offset value stored in the SP (stack pointer) register, indicates the current word in the stack being addressed.


ES register used for string handling. It is used in association with the DI (destination index) register to accessing this data segment.


FS and GS registers. Additional segment register available on the 80386 and later processors.


Instruction Pointer Register


IP register. The instruction pointer register is used in conjunction with the CS register to point to the next instruction to be executed. This is normally not altered by the programmer. However, using DEBUG this register can be alter. EIP (32 bits) is on the 80386 and up.



Pointer Register


SP and BP the stack pointer and Base pointer are associated with the stack segment. The SP points to the current word on the stack. The BP is used to reference parameters stored on the stack. The ESP and EBP are on the 80386 and up processors.



General Purpose Registers


The AX, BX, CX, and DX are the general purpose workhorses of the system. They can be address by the word or the byte using a high and low portion, AL and AH. The 80386 extends the two 32 bits in the EAX, EBX, ECX, and EDX,



AX register. The primary accumulator register is used for operations involving input/output and most arithmetic.


BX register. The BX is know as the base register since it is the only general purpose register that can be used as an index to extend addressing. It can also be use for computation.


CX register. The counter register has special instruction that allow it to be used for repetitive operations.


DX register. The DX is known as the data register Some I/o operations involve its use. Muliply and divide operations that involve large values assume the DX and AX together as a pair.


You may use any the general purpose registers for addition and subtraction of 8-bit, 16-bit, or 32-bit values.


Index Registers


SI register.16-bit source index register is required for some string operations in association with the DS.

 ESI (32-bit)


DI register. 16-bit destination index register is required for some string operations in association with the ES.

EDI (32-bit)


They are also available for addition and subtraction.

 


Flag Registers.

Of the 16-bits for the flag register 9 are common to the 8086 family. This register indicates results of certain operations. The common flag bits are

OF (overflow) Indicates overflow of a high-order (leftmost) bit following arithmetic.

DF(direction) Indicates left or right direction for moving or comparing string data.

IF(interrupt) Indicates that an external interrupt such as keyboard entry, is to be processed or ignored.

TF(trap) Permits operation of the processor in single step mode. This is set by DOS DEBUG allowing a program to be stepped through.

SF(sign) Contains the sign result of an arithmetic operation, 0 = positive, 1 = negative.

ZF(zero) Indicates the result of an arithmetic or comparison operation (0=nonzero, 1=zero result)

AF(auxiliary carry) Contains a carry out of bit 3 on eight-bit data, for specialized operation.

PF(parity) Indicates even or odd parity of a low-order (rightmost) eight-bit data operation.

CF(carr). Contains carries form a high-order (leftmost) bit following an arithmetic operation; also contains the bit content of last bit of a shift or rotate operation.

The 80386 has Eflags which is a 32-bit extended flag register. The O,S,Z, and C are the most relevant flags to the assembly language programmer.


15

14

13

12

11

10

9

8

7

6

5

4

3

2

1

0

 

 

 

 

O

D

I

T

S

Z

 

A

 

P

 

C