Introduction To Computer System-1
Introduction To Computer System-1
INTRODUCTION TO PROCESSOR
A processor is the logic circuitry that responds to and processes the basic instructions that drive a
computer. The term processor has generally replaced the term central processing unit (CPU). The
processor in a personal computer or embedded in small devices is often called a microprocessor. The
processor (CPU, for Central Processing Unit) is the computer's brain. It allows the processing of
numeric data, meaning information entered in binary form, and the execution of instructions stored in
memory.
Evolution of Microprocessor:
A microprocessor is used as the CPU in a microcomputer. There are now many different
microprocessors available. Microprocessor is a program-controlled device, which fetches the
instructions from memory, decodes and executes the instructions. Most Micro Processor are single
chip devices. Microprocessor is a backbone of computer system which is called CPU. Microprocessor
speed depends on the processing speed depends on DATA BUS WIDTH.
A common way of categorizing microprocessors is by the no. of bits that their ALU can work
with at a time
The address bus is unidirectional because the address information is always given by the
microprocessor to address a memory location of an input / output devices.
The data bus is Bi-directional because the same bus is used for transfer of data between
microprocessor and memory or input / output devices in both the direction.
It has limitations on the size of data. Most Microprocessor does not support floating point
operations.
Microprocessor contain ROM chip because it contain instructions to execute data.
Types of Microprocessor
1. 4-bit Microprocessor:
The first microprocessor (Intel 4004) was invented in 1971. It was a 4-bit calculation device
with a speed of 108 kHz. Since then, microprocessor power has grown exponentially. So what
exactly are these little pieces of silicone that run our computers (" Common Operating Machine
Particularly Used For Trade Education And Research ")
It has 3200 PMOS transistors.
It is a 4-bit device used in calculator.
2. 8-Bit microprocessor:
In 1972, Intel came out with the 8008 which is 8-bit.
In 1974, Intel announced the 8080 followed by 8085 is a 8-bit processor Because 8085 processor has
8 bit ALU (Arithmetic Logic Review). Similarly 8086 processor has 16 bit ALU. This had a larger
instruction set then 8080. used NMOS transistors, so it operated much faster than the 8008. The 8080
is referred to as a “Second generation Microprocessor”
Buses are the means by which data is transmitted from one part of a computer to another,
connecting all major internal components to the CPU and memory. A standard CPU system bus is
comprised of aa control bus, data bus and address bus.
Address Bus Carries the addresses of data (but not the data) between
the processor and memory
Data Bus Carries data between the processor, the memory unit
and the input/output devices
ASSEMBLER DIRECTIVES
Assembler directives are the directions to the assembler which indicate how an operand or section of
the program is to be processed. These are also called pseudo operations which are not executable by
the microprocessor. The various directives are explained below.
i. ASSUME: The ASSUME directive is used to inform the assembler the name of the logical
segment it should use for a specified segment.
Ex: ASSUME DS: DATA tells the assembler that for any program instruction which refers to
the data segment ,it should use the logical segment called DATA.
ii. DB -Define byte. It is used to declare a byte variable or set aside one or more storage
locations of type byte in memory.
For example, CURRENT_VALUE DB 36H tells the assembler to reserve 1 byte of memory
for a variable named CURRENT_ VALUE and to put the value 36 H in that memory location
when the program is loaded into RAM .
iii. DW -Define word. It tells the assembler to define a variable of type word or to reserve
storage locations of type word in memory.
iv. DD(define double word) :This directive is used to declare a variable of type double word or
restore memory locations which can be accessed as type double word.
v. DQ (define quadword) :This directive is used to tell the assembler to declare a variable 4
words in length or to reserve 4 words of storage in memory .
vi. DT (define ten bytes):It is used to inform the assembler to define a variable which is 10
bytes in length or to reserve 10 bytes of storage in memory.
vii. EQU –Equate It is used to give a name to some value or symbol. Every time the assembler
finds the given name in the program, it will replace the name with the value or symbol we
have equated with that name
viii. ORG -Originate : The ORG statement changes the starting offset address of the data. It
allows to set the location counter to a desired value at any point in the program.
For example the statement ORG 3000H tells the assembler to set the location counter to
3000H.
ix. PROC- Procedure: It is used to identify the start of a procedure. Or subroutine.
x. END- End program .This directive indicates the assembler that this is the end of the program
module. The assembler ignores any statements after an END directive.
xi. ENDP- End procedure: It indicates the end of the procedure (subroutine) to the assembler.
xii. ENDS-End Segment: This directive is used with the name of the segment to indicate the end
of that logical segment.
Ex: CODE SEGMENT: Start of logical segment containing code CODE ENDS : End of the
segment named CODE.
ARCHITECTURE OF 8086:
The 8086 has two blocks BIU (BUS INTERFACE UNIT) and EU (EXECUTION UNIT)
• The BIU performs all bus operations such as instruction fetching, reading and writing operands
for memory and calculating the addresses of the memory operands. The instruction bytes are
transferred to the instruction queue.
• EU executes instructions from the instruction system byte queue.
• Both units operate asynchronously to give the 8086 an overlapping instruction fetch and
execution mechanism which is called as Pipelining. This results in efficient use of the system
bus and system performance.
• BIU contains Instruction queue, Segment registers, Instruction pointer, and Address adder.
• EU contains Control circuitry, Instruction decoder, ALU, Pointer and Index register, Flag
register.
•
1. BUS INTERFACR UNIT:
It provides a full 16 bit bidirectional data bus and 20 bit address bus.
The bus interface unit is responsible for performing all external bus operations
Instruction fetch, Instruction queuing, Operand fetch and storage, Address relocation and Bus
control.
The BIU uses a mechanism known as an instruction stream queue to implement a pipeline
architecture.
This queue permits pre-fetch of up to six bytes of instruction code. Whenever the queue of the
BIU is not full, it has room for at least two more bytes and at the same time the EU is not
requesting it to read or write operands from memory, the BIU is free to look ahead in the
program by prefetching the next sequential instruction.
These prefetching instructions are held in its FIFO queue. With its 16 bit data bus, the BIU
fetches two instruction bytes in a single memory cycle
The BIU is also responsible for generating bus control signals such as those for memory read
or write and I/O read or write
2. EXECUTION UNIT
The Execution unit is responsible for decoding and executing all instructions.
The EU extracts instructions from the top of the queue in the BIU, decodes them, generates
operands if necessary, passes them to the BIU and requests it to perform the read or write bys
cycles to memory or I/O and perform the operation specified by the instruction on the
operands.
During the execution of the instruction, the EU tests the status and control flags and
updates them based on the results of executing the instruction.
If the queue is empty, the EU waits for the next instruction byte to be fetched and shifted to
top of the queue.
When the EU executes a branch or jump instruction, it transfers control to a location
corresponding to another set of sequential instructions.
Whenever this happens, the BIU automatically resets the queue and then begins to fetch
instructions from this new location to refill the queue.
INSTRUCTION FORMATS
The number of address fields in the instruction format of a computer depends on the internal
organization of its registers. Most computers fall into one of three types of CPU organizations:
1 Single accumulator organization.
2 General register organization.
3 Stack organization.
The instruction format in this type of computer needs three register address fields. Thus the
instruction for an arithmetic addition may be written in an assembly language as
ADD R1, R2, R3 denote the operation R1 ← R2 + R3.
The number of address fields in the instruction can be reduced from three to two if the destination
register is the same as one of the source registers.
ADD R1, R2 denote the operation R1 ← R1 + R2.
Only register addresses for R1 and R2 need be specified in this instruction.
Computers with multiple processor registers use the move instruction with a mnemonic MOV to
symbolize a transfer instruction.
MOV R1, R2 denotes the transfer R1 ← R2 (or R2 ← R1,
Depending on the particular computer). Thus transfer-type instructions need two address fields to
specify the source and the destination.
General register-type computers employ two or three address fields in their instruction format. Each
address field may specify a processor register or a memory word. An instruction symbolized by
ADD R1, X R1 ← R + M [X]. It has two address fields, one for register R1 and the other
for the memory address X.
Computers with stack organization would have PUSH and POP instructions which require an address
field.
PUSH X will push the word at address X to the top of the stack. The stack pointer is
updated automatically. Operation-type instructions do not need an address field in stack-organized
computers. This is because the operation is performed on the two items that are on top of the stack.
THREE-ADDRESS INSTRUCTIONS
Computers with three-address instruction formats can use each address field to specify either a
processor register or a memory operand. The program in assembly language that evaluates X = (A +
B) ∗ (C + D) is shown below, together with comments that explain the register transfer operation of
each instruction.
ADD R1, A, B R1 ← M [A] + M [B]
ADD R2, C, D R2 ← M [C] + M [D]
MUL X, R1, R2 M [X] ← R1 ∗ R2
It is assumed that the computer has two processor registers, R1 and R2. The symbol M [A] denotes
the operand at memory address symbolized by A.
The advantage of the three-address format is that it results in short programs when evaluating
arithmetic expressions. The disadvantage is that the binary-coded instructions require too many
bits to specify three addresses. An example of a commercial computer that uses three -address
instructions is the Cyber 170. The instruction formats in the Cyber computer are restricted to
either three register address fields or two register address fields and one memory address field.
TWO-ADDRESS INSTRUCTIONS
Two address instructions are the most common in commercial computers. Here again each a ddress
field can specify either a processor register or a memory word. The program to evaluate X = (A + B) ∗
(C + D) is as follows:
MOV R1, A R1 ← M [A]
ADD R1, B R1 ← R1 + M [B]
MOV R2, C R2 ← M [C]
ADD R2, D R2 ← R2 + M [D]
MUL R1, R2 R1 ← R1∗R2
MOV X, R1 M [X] ← R1
The MOV instruction moves or transfers the operands to and from memory and processor registers.
The first symbol listed in an instruction is assumed to be both a source and the destination where the
result of the operation is transferred.
ONE-ADDRESS INSTRUCTIONS
One-address instructions use an implied accumulator (AC) register for all data manipulation. For
multiplication and division there is a need for a second register. However, here we will neglect the
second and assume that the AC contains the result of tall operations. The program to evaluate X = (A
+ B) ∗ (C + D) is
LOAD A AC ← M [A]
ADD B AC ← A [C] + M [B]
STORE T M [T] ← AC
LOAD C AC ← M [C]
ADD D AC ← AC + M [D]
MUL T AC ← AC ∗ M [T]
STORE X M [X] ← AC
All operations are done between the AC register and a memory operand. T is the address of a
temporary memory location required for storing the intermediate result.
ZERO-ADDRESS INSTRUCTIONS
A stack-organized computer does not use an address field for the instructions ADD and MUL. The
PUSH and POP instructions, however, need an address field to specify the operand that communicates
with the stack. The following program shows how X = (A + B) ∗ (C + D) will be written for a stack
organized computer. (TOS stands for top of stack)
PUSH A TOS ← A
PUSH B TOS ← B
ADD TOS ← (A + B)
PUSH C TOS ← C
PUSH D TOS ← D
ADD TOS ← (C + D)
MUL TOS ← (C + D) ∗ (A + B)
POP X M [X] ← TOS
OVERVIEW OF 8086
In1978, Intel came out with the 8086 processor. The Intel 8086 is a 16-bit microprocessor, the term
16-bit means that its ALU, its internal registers, and most of its instructions are designed to work with
16-bit binary words. The instruction set as 8086.(8086: 16-bit add.bus and 8-bit data bus).
Implemented in N–channel, depletion load, silicon gate technology (HMOS) and packaged it in a 40
pin dual in line package.
8086 CPU has 8 general purpose registers; each register has its own name:
i. AX - the Accumulator Register (divided into AH / AL): Accumulator register consists of 2-
8-bit registers AL and AH, which can be combined together and used as a 16-bit register AX.
AL in this case contains the low-order byte of the word, and AH contains the high-order byte.
Accumulator can be used for I/O operations and string manipulation.
a. Generates shortest machine code
b. Arithmetic, logic and data transfer
c. One number must be in AL or AX
d. Multiplication & Division
e. Input & Output
ii. BX - the Base Address Register (divided into BH / BL): Base register consists of 2 8-bit
registers BL and BH, which can be combined together and used as a 16-bit register BX. BL in
this case contains the low-order byte of the word, and BH contains the high-order byte. BX
register usually contains a data pointer used for based, based indexed or register indirect
addressing.
iii. CX - the Count Register (divided into CH / CL): Count Register consists of 2 8-bit registers
CL and CH, which can be combined together and used as a 16-bit register CX. When
combined, CL register contains the low-order byte of the word, and CH contains the high
order byte. Count register can be used as a counter in string manipulation and shift/rotate
instructions
a. Iterative code segments using the LOOP instruction
b. Repetitive operations on strings with the REP command
c. Count (in CL) of bits to shift and rotate
iv. DX - the Data Register (divided into DH / DL): Data register consists of 2 8-bit registers DL
and DH, which can be combined together and used as a 16-bit register DX. When combined,
DL register contains the low-order byte of the word, and DH contains the high-order byte.
Data register can be used as a port number in I/O operations. In integer 32-bit multiply and
divide instruction the DX register contains high-order word of the initial or resulting number.
a. DX: AX concatenated into 32-bit register for some MUL and DIV operations
b. Specifying ports in some IN and OUT operations
i. Segment registers: Is a 16-bit address to form a 20-bit address. The physical address of the
8086 is 20 bit wide to access 1 Mbyte memory locations. 1 Mbyte of memory is divided into
segments, with a maximum size of segment as 64 Kbytes The 8086 allows only four active
segments at a time, as shown the below figure, these four registers are:
a. Code segment (CS) is a 16-bit register containing address of 64 KB segment with
processor instructions.
b. Stack segment (SS) is a 16-bit register containing address of 64KB segment with program
stack
c. Data segment (DS) is a 16-bit register containing address of 64KB segment with program
data.
d. Extra segment (ES) is a 16-bit register containing address of 64KB segment, usually with
program data.
Memory organization:
The total memory of 1MB is divided into 16 segments and each segment can store 64kb of data and
the segments available are CS, DS, ES, and SS
Physical address calculation:
Physical address calculation = segment address+offset address. In segment we use always four
registers i.e. CS, DS, ES, and SS. Offset register are BP, SP, SI, DI, IP
Move the code segment address to left side and add zero
Eg: let 4000
40000 8000-offset
4000-segment address
Physical address represented as 4000:8000
For CS we use IP, for DS we use SI, DI, for Es we use SI, DI, for SS we use SP
1. Data Transfer instructions: These instructions are used to transfer the data from source operand
to destination operand. All the store, move, load, exchange, input and output instructions belong to
this group.
i. General purpose byte or word transfer instructions :
MOV: Copy byte or word from specified source to specified destination
PUSH: Push the specified word to top of the stack
POP: Pop the word from top of the stack to the specified location
PUSHA: Push all registers to the stack
POPA: Pop the words from stack to all registers
XCHG: Exchange the contents of the specified source and destination operands one of which
may be a register or memory location.
XLAT: Translate a byte in AL using a table in memory
ii. Simple input and output port transfer instructions
IN: Reads a byte or word from specified port to the accumulator
OUT: Sends out a byte or word from accumulator to a specified port
iii. Special address transfer instructions
LEA : Load effective address of operand into specified register
LDS : Load DS register and other specified register from memory
LES : Load ES register and other specified register from memory.
iv. Flag transfer registers
LAHF : Load AH with the low byte of the flag register
SAHF : Store AH register to low byte of flag register
PUSHF : Copy flag register to top of the stack
POPF : Copy word at top of the stack to flag register
2. Arithmetic instructions : These instructions are used to perform various mathematical operations
like addition, subtraction, multiplication and division etc….
i. Addition instructions
ADD : Add specified byte to byte or word to word
ADC : Add with carry
INC : Increment specified byte or specified word by 1
AAA : ASCII adjust after addition
DAA : Decimal (BCD) adjust after addition
ii. Subtraction instructions
SUB : Subtract byte from byte or word from word
SBB : Subtract with borrow
DEC : Decrement specified byte or word by 1
NEG : Negate or invert each bit of a specified byte or word and add 1(2’s complement)
CMP : Compare two specified byte or two specified words
AAS : ASCII adjust after subtraction
DAS : Decimal adjust after subtraction
iii. Multiplication instructions
MUL : Multiply unsigned byte by byte or unsigned word or word.
IMUL : Multiply signed bye by byte or signed word by word
AAM : ASCII adjust after multiplication
iv. Division instructions
DIV : Divide unsigned word by byte or unsigned double word by word
IDIV : Divide signed word by byte or signed double word by word
AAD : ASCII adjust after division
CBW : Fill upper byte of word with copies of sign bit of lower byte
CWD : Fill upper word of double word with sign bit of lower word.
3. Bit Manipulation instructions : These instructions include logical , shift and rotate instructions in
which a bit of the data is involved.
i. Logical instructions
NOT : Invert each bit of a byte or word.
AND : ANDing each bit in a byte or word with the corresponding bit in another byte or word.
OR : ORing each bit in a byte or word with the corresponding bit in another byte or word.
XOR : Exclusive OR each bit in a byte or word with the corresponding bit in another byte or
word.
TEST :AND operands to update flags, but don’t change operands.
ii. Shift instructions
SHL/SAL : Shift bits of a word or byte left, put zero(S) in LSBs.
SHR : Shift bits of a word or byte right, put zero(S) in MSBs.
SAR : Shift bits of a word or byte right, copy old MSB into new MSB.
iii. Rotate instructions
ROL : Rotate bits of byte or word left, MSB to LSB and to Carry Flag [CF]
ROR : Rotate bits of byte or word right, LSB to MSB and to Carry Flag [CF]
RCR :Rotate bits of byte or word right, LSB TO CF and CF to MSB
RCL :Rotate bits of byte or word left, MSB TO CF and CF to LSB
4. String instructions
A string is a series of bytes or a series of words in sequential memory locations. A string often
consists of ASCII character codes.
REP : An instruction prefix. Repeat following instruction until CX=0
REPE/REPZ : Repeat following instruction until CX=0 or zero flag ZF=1
REPNE/REPNZ : Repeat following instruction until CX=0 or zero flag ZF=1
MOVS/MOVSB/MOVSW: Move byte or word from one string to another
COMS/COMPSB/COMPSW: Compare two string bytes or two string words
INS/INSB/INSW: Input string byte or word from port
OUTS/OUTSB/OUTSW : Output string byte or word to port
SCAS/SCASB/SCASW: Scan a string. Compare a string byte with a byte in AL or a string
word with a word in AX
LODS/LODSB/LODSW: Load string byte in to AL or string word into AX
7. Interrupt instructions
INT : Interrupt program execution, call service procedure
INTO : Interrupt program execution if OF=1
IRET : Return from interrupt service procedure to main program
ADDRESSING MODES:
The operation field of an instruction specifies the operation to be performed. This operation must be
executed on some data stored in computer registers or memory words. The way the operands are
chosen during program execution in dependent on the addressing mode of the instruction. The
addressing mode specifies a rule for interpreting or modifying the address field of the instruction
before the operand is actually referenced.
Computers use addressing mode techniques for the purpose of accommodating one or both of the
following provisions:
1 To give programming versatility to the user by providing such facilities as pointers to Memory,
counters for loop control, indexing of data, and program relocation
2 To reduce the number of bits in the addressing field of the instruction.
3 The availability of the addressing modes gives the experienced assembly language programmer
flexibility for writing programs that are more efficient with respect to the number of instructions
and execution time.
The different ways in which a source operand is denoted in an instruction are known as the addressing
modes. There are 8 different addressing modes in 8086 programming. They are
1. Immediate addressing mode
2. Register addressing mode
3. Direct addressing mode
4. Register indirect addressing mode
5. Based addressing mode
6. Indexed addressing mode.
7. Based indexed addressing mode
8. Based Indexed with displacement.
Immediate addressing mode: The addressing mode in which the data operand is a part of the
instruction itself is called Immediate addressing mode.
For Ex: MOV CX, 4847 H
ADD AX, 2456 H
MOV AL, FFH
Register addressing mode : Register addressing mode means, a register is the source of an
operand for an instruction.
For Ex : MOV AX, BX copies the contents of the 16-bit BX register into the 16-bit AX
register.
EX : ADD CX,DX
Direct addressing mode: The addressing mode in which the effective address of the memory
location at which the data operand is stored is given in the instruction.i.e the effective address
is just a 16-bit number is written directly in the instruction.
For Ex: MOV BX, [1354H]
MOV BL,[0400H]
The square brackets around the 1354 H denotes the contents of the memory location. When
executed, this instruction will copy the contents of the memory location into BX register. This
addressing mode is called direct because the displacement of the operand from the segment
base is specified directly in the instruction.
Register indirect addressing mode : Register indirect addressing allows data to be addressed
at any memory location through an offset address held in any of the following registers: BP,
BX, DI and SI.
Ex: MOV AX, [BX]. Suppose the register BX contains 4675H ,the contents of the 4675 H are
moved to AX.
ADD CX, {BX}
Based addressing mode: The offset address of the operand is given by the sum of contents of
the BX or BP registers and an 8-bit or 16-bit displacement.
Ex: MOV DX, [BX+04]
ADD CL,[BX+08]
Indexed Addressing mode : The operands offset address is found by adding the contents of
SI or DI register and 8-bit or 16-bit displacements.
Ex: MOV BX,[SI+06]
ADD AL,[DI+08]
Based -index addressing mode : The offset address of the operand is computed by summing
the base register to the contents of an Index register.
Ex: ADD CX,[BX+SI]
MOV AX,[BX+DI]
Based Indexed with displacement mode: The operands offset is computed by adding the
base register contents, an Index registers contents and 8 or 16-bit displacement.
Ex : MOV AX,[BX+DI+08]
ADD CX,[BX+SI+16]
The most common names for addressing modes (names may differ among architectures)
Addressing Example Meaning When used
modes Instruction
Register Add R4,R3 R4 <- R4 + R3 When a value is in a register
Immediate Add R4, #3 R4 <- R4 + 3 For constants
Displacement Add R4, R4 <- R4 + M[100+R1] Accessing local variables
100(R1)
Register Add R4,(R1) R4 <- R4 + M[R1] Accessing using a pointer or a computed
Indexed address
Indexed Add R3, (R1 + R3 <- R3 + M[R1+R2] Useful in array addressing:
R2) R1 - base of array
R2 - index amount
Direct Add R1, (1001) R1 <- R1 + M[1001] Useful in accessing static data
Memory Add R1, @(R3) R1 <- R1 + M[M[R3]] If R3 is the address of a pointer p, then
deferred mode yields *p
Auto- Add R1, (R2)+ R1 <- R1 +M[R2] Useful for stepping through arrays in a
increment R2 <- R2 + d loop.
R2 - start of array
d - size of an element
Auto- Add R1,-(R2) R2 <-R2-d Same as autoincrement.
decrement R1 <- R1 + M[R2] Both can also be used to implement a
stack as push and pop
Scaled Add R1, R1<- Used to index arrays. May be applied to
100(R2)[R3] R1+M[100+R2+R3*d] any base addressing mode in some
machines.