Computer Organization Notes of Lesson-converted
Computer Organization Notes of Lesson-converted
1
ALPHA ARTS AND SCIENCE COLLEGE
(AFFILIATED TO THE UNIVERSITY OF MADRAS)
PORUR, CHENNAI – 600 116.
NOTES OF LESSON
FOR
Computer Organization
(SZ23C)
PREPARED BY
S. LAKSHMI & APARYAY KUMAR
II BCA A & B
THIRD SEMESTER
2
INDEX
1 UNIT- I 06
2 UNIT - II 43
3 UNIT - III 82
4 UNIT – IV 105
5 UNIT – V 121
6 APPENDIX – I 175
3
CORE - II COMPUTER ORGANIZATION
OBJECTIVES:
I YEAR / II SEM
• To understand the basic organization of computers and the working of each component and CPU
• To bring the programming features of 8085 Microprocessor and know the features of latest
microprocessors.
• To understand the principles of Interfacing I/O devices and Direct Memory accesses
OUTCOMES:
• Describe the major components of a computer system and state their function and purpose
• Describe the microstructure of a processor
• Demonstrate the ability to program a microprocessor in assembly language.
• Classify and describe the operation DMA and peripheral Interfaces.
SYLLABUS:
UNIT - I
Data Representation: Data Types – Complements – Fixed-Point and Floating-Point Representation Other
Binary Codes. Register Transfer and Microoperations: Register Transfer Language - Register Transfer -
Bus and Memory Transfers – Arithmetic, Logic and Shift Microoperations.
UNIT - II
Central Processing Unit: General Register and Stack Organizations - Instruction Formats - Addressing
Modes - Data Transfer and Manipulation - Program Control - RISC - Pipelining - Arithmetic and Instruction -
RISC Pipeline - Vector Processing and Array Processors.
UNIT - III
Microprocessor Architecture and its Operations - 8085 MPU - 8085 Instruction Set and Classifications.
Programming in 8085: Code Conversion – BCD-to-Binary and Binary-to-BCD Conversions – ASCII-to-
BCD and BCD-to-ASCII Conversions – Binary-to-ASCII and ASCII-to -Binary Conversions.
4
UNIT - IV
Programming in 8085: BCD Arithmetic - BCD addition and Subtraction - Multibyte Addition and
Subtraction - Multiplication and Division. Interrupts: The 8085 Interrupt – 8085 Vectored Interrupts.
UNIT - V
Direct Memory Access (DMA) and 8257 DMA Controller - 8255A Programmable Peripheral Interface. Basic
Features of Advanced Microprocessors - Pentium - I3, I5 and I7
TEXT BOOKS:
REFERENCE BOOKS:
WEB REFERENCES:
5
COMPUTER ORGANIZATION
UNIT – I
******************************************************************
Chapter 1 Data Representation
**********************************************************************
This Chapter shows how the various data types found in digital computers are represented in binary
form in computer registers. Emphasis is on the representation of numbers employed in arithmetic
operations, and on the binary coding of symbols used in data processing.
Number System
❖ A Number System of base, or radix, r is a system that uses distinct symbols for r digits.
❖ Numbers are represented by a string of digit symbols.
❖ To determine the quantity that the number represents, it is necessary to multiply each digit by
an integer power of r and then form the sum of all weighted digits.
❖ Computer Architecture supports the following 4 Types of Number Systems:
1. Decimal Number System
2. Binary Number System
3. Octal Number System
6
4. Hexadecimal Number System
• The Decimal Number System is also known as the base-10 number system.
• It uses ten symbols for representing numbers.
• They are 0, 1, 2, 3, 4, 5, 6, 7, 8 and 9.
• The Binary Number System is also known as the base-2 number system.
• It has only two digits 0 and 1.
• The Binary Number System is the most commonly used number system used in Digital
Computers.
• The octal number system is also known as the base-8 number system.
• It uses eight different symbols for representing numbers.
• They are 0, 1, 2, 3, 4, 5, 6 and 7.
• The Hexadecimal Number System is also known as the base-16 number system.
• It uses sixteen different symbols for representing numbers.
• They are 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, A, B, C, D, E and F. Here A is 10, B is 11, C is
12, D is 13, E is 14 and F is 15.
Steps:
7
The remainders are to be read from bottom to top to obtain the binary equivalent.
Steps:
Example 3:
8
Binary to Decimal Conversion
Steps:
1. Separate the digits of the given Binary number, if it contains more than 1 digit.
2. Multiply each digit of the Binary number with its increasing power of 2 from right to left.
3. Add all the individual results provide the equivalent decimal number
Example 1:
Convert the Binary Number (100011)2 to Decimal.
Binary Number: 1 0 0 0 1 1
Power of 2: 25 24 23 22 21 20
Example 2:
Table 2 Conversion table from Binary to Decimal, for the integer part and fractions
Power of 2: 26 25 24 23 22 21 20
Integer Part (1101011)2 = 1 x 26+1 x 25+0 x 24+1 x 23+0 x 22+1 x 21+1 x 20 = (107)10
Fraction Part (.1011) = 1 x 2-1+0 x 2-2+1 x 2-3+1 x 2-4 = (0.6875)10
9
Thus, (1101011.1011)2 = (107.6875)10
Steps:
Example 1:
Steps:
1. Multiply the number by 8.
2. Write the value of the integer part.
3. Repeat the above two steps until the fractional part becomes zero.
4. Read downwards the sequence of integer parts.
Example 2:
Convert the fractional decimal number (0.140869140625)10 to Octal.
Multiplication Resultant integer part
0.140869140625 x 8 = 0.12695313 1
0.12695313 x 8 = 0.01562504 1
0.01562504 x 8 = 0.12500032 0
0.12500032 x 8 = 0.00000256 1
0.00000256 x 8 = 0.000020544 0
Thus, (0.140869140625)10 = (11010)8
10
Octal to Decimal Conversion
Steps:
1. Separate the digits of the given octal number, if it contains more than 1 digit.
2. Multiply each digit of octal number with its increasing power of 8 from right to left
3. Add all the individual results provide the equivalent decimal number.
Example 1:
Convert the Octal number (75)8 to Decimal
Table 3 shows the conversion from Octal (75)8 to Decimal.
Table 3 Conversion Table from Octal to Decimal, for the integer part
Octal Number: 7 5
Power of 8: 81 80
(75)8 = 7 x 81 + 5 x 80 = (61)10
Thus, (75)8 = (61)10
Example 2:
Convert the Octal number (45.6)8 to Decimal.
Table 4 Conversion Table from Octal to Decimal for the integer part and fractions
Octal Number: 4 5 . 6
Power of 8: 81 = 8 80 = 1 . 8-1
4x8 5x1 . 6 x 1/8
Steps:
1. Separate the digits of the given Octal Number, if it contains more than one digit.
2. Find the equivalent Binary Number for each digit of the Octal Number. Add 0’s to the left if
any of the Binary equivalent is shorter than 3 bits.
3. Write all the binary numbers together, maintaining the same group order provides the
equivalent Binary for the given octal number.
11
Example:
Convert the Octal (7631)8 to its Binary equivalent.
7 6 3 1
111 110 011 001
Steps:
1. Separate the digits of a given Binary number into groups of 3 bits starting from right to left.
2. Find the equivalent octal number for each group.
3. Write all the group octal numbers together, maintaining group order provides the equivalent
octal number for the given binary.
Example:
Convert the Binary number (111110011001)2 into Octal.
111 110 011 001
7 6 3 1
Example:
12
Hexadecimal to Octal Conversion
Steps:
Example:
Steps:
13
b) Converting an Fractional Decimal Number to Hexadecimal
Steps:
1. Multiply the number by 16.
2. Write the value of the integer part.
3. Repeat the above two steps until the integer part became zero.
4. Read downwards the sequence of integer parts.
Example:
Steps:
= 15 x 16 +3
14
Hexadecimal to Binary Conversion
Steps:
1. Separate the digits of the given Hexadecimal Number, if it contains more than one digit.
2. Find the equivalent Binary Number for each digit of the Hexadecimal Number. Add 0’s to
the left if any of the Binary equivalent is shorter than 4 bits.
3. Write all the Binary numbers together, maintaining the same group order provides the
equivalent Binary for the given Hexadecimal number.
Example:
Steps:
1. Separate the digits of a given binary number into groups of 4 bits starting from right to left.
2. Find the equivalent Hexadecimal number for each group.
3. Write all the Hexadecimal numbers together, maintaining group order provides the equivalent
octal number for the given binary.
Example:
Convert the given Binary Number (1110100011010110)2 into its Hexadecimal equivalent.
15
Hexadecimal to Octal Conversion
Steps:
1. For each Hexadecimal digit, write the equivalent binary number. If any of the binary
equivalents are less than 4 digits, add 0’s to the left side.
2. Combine and make the groups of binary digits from right to left, each containing 3 digits. Add
0’s to the left if there are less than 3 digits in the last group.
3. Find the Octal equivalent of each binary group.
Example:
Convert the Hexadecimal Number (1BC)16 into its Octal equivalent.
1 B C
0 6 7 4
Thus, (1BC)16 = (674)8
Octal to Hexadecimal Conversion
Steps:
Example:
Step 1:
Octal to Binary Conversion
7 5 2
16
0001 1110 1010
1 E A
Thus, (752)8 = (1EA)16
Decimal, Binary, Octal and Hexadecimal Equivalence Table
Decimal Representation:
❖ The Binary Number System is the most natural system for a computer.
❖ A Binary Code is a group of n bits that assumes up to 2n distinct combinations of 1’s and 0’s
witheach combination representing one element of the set that is being coded.
❖ Binary Code that distinguishes among 10 elements must contain at least four bits.
❖ The bits assignment is most commonly used for the decimal digits.
❖ Table 6 shows the difference between the conversion of decimal numbers into binary and
thebinary coding of decimal numbers.
Example:
❖ When converted to binary number, the decimal number 99 is represented by the string of
bits 1100011.
❖ When represented in BCD, it becomes 1001 1001.
Table 6 Decimal and BCD
17
Decimal
Binary-Coded Decimal (BCD) number
Number
0 0000
1 0001
2 0010
3 0011
4 0100
5 0101
6 0110
7 0111
8 1000
9 1001
10 0001 0000
20 0010 0000
99 1001 1001
Alphanumeric Representation:
❖ An Alphanumeric character set is a set of elements that includes the 10 decimal digits,
the 26 letters of the alphabet and a number of special characters, such as $, +, =.
❖ Such a set contains between 32 and 64 elements (if only uppercase letters are included) or
between 64 and 128 (if both uppercase and lowercase letters are included).
• In the first case, the binary code will require six bits and in the second case, seven bits.
❖ The standard alphanumeric binary code is the ASCII (American Standard Code for
Information Interchange) which uses seven bits to code 128 characters.
▪ The binary code for the uppercase letters, the decimal digits, and a few special characters is
listed in Table 7.
❖ Binary Codes play an important part in Digital Computer operations.
❖ The codes must be in binary because registers can only hold binary information.
❖ Binary Codes change the symbols only not the meaning of the elements.
18
Table 7 ASCII
V 101 0110
W 101 0111
X 101 1000
Y 101 1001
Z 101 1010
1.2 Complements
❖ Complements are used in Digital Computers for simplifying the subtraction
operation and forlogical manipulation.
19
❖ There are two types of complements for each base r system: (Figure 1)
Types of Complements
• When the value of the base r is substituted in the name, the two types are referred to as the
2's and I's complement for binary numbers and the ID's and 9's complement for decimal
numbers.
❖ (Table 8 shows the relation between r’s and (r-1)’s complement. 10-6=4 ; 9-
6=3; 3+1=4
Table 8 Relation between r’s and (r-1)’s complement
(r-1)’s Complement
❖ Given a number N in base r having n digits, the (r-1)’s complement of N is defined as (rn - 1) - N.
❖ For decimal numbers r = 10 and r-1 = 9.
❖ So the 9’s complement of N is (10n - 1) - N.
(^3-1)-96=(1000-1)-967=999-967
32+1=33
Example 1:
20
❖ The 1’s complement of a binary number is formed by changing 1’s into 0’s and 0’s into 1’s.
❖ The (r - I)'s complement of octal or hexadecimal numbers are obtained by
subtracting each digit from 7 or F (decimal 15) respectively.
Example 2:
❖ The 2's complement of the binary number is obtained by adding 1 to the 1's
complement value.
❖ The complement of the complement restores the number to its original value. The r's
complement of N is rn - N. The complement of the complement is rn - (rn - N) = N giving
back the original number.
Example 1:
The 10’s complement of the Decimal (7)10 = 10-7 = 3
Example 2:
F i n d t h e 2’s Complement of the Binary (0010)2 number.
Step 1: Convert the binary into 1’s complement by replacing 1’s by 0’s and 0s, then get
0010 → 1101
Step 2: Add 1 into 1’s complement 1101 + 1 → 1110
Step 3: 2’s complement of (0010) = 1110.
Subtraction of Unsigned Numbers
21
3. If M < N, the sum does not produce an end carry and i s equal to r' - (N - M),
which is the r's complement of (N - M). To obtain the answer in a familiar form,
take the r' s complement of the sum and place a negative sign in front.
Consider, for example, the subtraction 72532 - 13250 = 59282. The l0's complement of 13250
is 86750. Therefore:
M = 72532
10's complement of N = +86750
Sum = 159282
Discard end carry 10' = - 1 00000
Answer = 59282
Now consider an example with M < N. The subtraction 13250 – 72532 produces negative
59282.
Using the procedure with complements, we have
M = 13250
10's complement of N = +27468
Sum = 40718
There is no end carry
22
• To represent negative integers, we need a notation for negative values.
• In ordinary arithmetic, a negative number is indicated by a minus sign and a
positive number by aplus sign.
• The convention is to make the sign bit equal to 0 for positive and to 1 for negative.
• A number may have a binary or decimal point.
• The position of the binary point is needed to represent fractions, integers, or
mixed integer-fraction numbers.
• There are two ways of specifying the position of the binary point in a register:
1. Fixed - Point Representation: The Binary point is always fixed in one position.
2. Floating - Point Representation: It uses a second register to store a number.
Arithmetic Addition
• The addition of two numbers in the signed magnitude system follows the rules of ordinary
arithmetic.
• If the signs are the same, we add the two magnitudes and give the sum the common sign.
• If the signs are different, we subtract the smaller magnitude from the larger and give the
result thesign of the larger magnitude.
Example 1:
Add ( + 15 ) , (- 18 )
= (+ 15) + (-18)
= (- 3)
• The rule for adding numbers in the signed 2’s complement system is very simple.
Example 2:
Arithmetic Subtraction
• Subtraction of two signed binary numbers when negative numbers are in 2’s complement
formis very simple and can be stated as follows:
o Take the 2’s complement of the subtrahend.
23
o Add it to the minuend.
o A carry out of the sign bit position is discarded.
• Changing a positive number to a negative number is done by taking its 2’s complement.
• The reverse is also true because the complement of a negative number in complement form
produces the equivalent positive number.
Example:
+7 = 0000 0111
Overflow
When two numbers of n digits each are added and the sum occupies n + 1 digits, then overflow
has occurred.
• An overflow is a problem in Digital Computers because the width of registers is finite.
• A result that contains n + 1 bits cannot be accommodated in a register with a standard
length of n bits.
• For this reason, many computers detect the occurrence of an overflow.
• When it occurs, a corresponding flip-flop is set which can then be checked by the user.
• The detection of an overflow after the addition of two binary numbers depends
on whether thenumbers are considered to be signed or unsigned.
• An overflow cannot occur after an addition if one number is positive and the other is
negative.
• The representation of decimal numbers in registers is a function of the binary code used to
represent a decimal digit.
• A 4-bit decimal code requires four flip-flops for each decimal digit.
• The representation of 4385 in BCD requires 16 flip-flops, four flip-flops for each digit.
The number will be represented in a register with 16 flip-flops as follows:
0100 0011 1000 010I
24
• The representation of signed decimal numbers in BCD is similar to the representation of
signed numbers in binary. We can either use the familiar signed-magnitude system or the
signed-complement system. The sign of a decimal number is usually represented with four
bits to conform with the 4-bit code of the decimal digits.
• The signed-magnitude system is difficult to use with computers. The signed-complement
system can be either the 9's or the 10's complement, but the 10's complement is the one most
often used. To obtain the 10' s complement of a BCD number, we first take the 9's complement
and then add one to the least significant digit. The 9's complement is calculated from the
subtraction of each digit from 9.
25
• The Gray Code was invented by Frank Gray (1939) for sending sequence of bits using a frequency
transmitting device.
• Gray Code has some applications in analog to digital converters, as well as being used for error
correction in digital communication.
• Gray Code counters are sometimes used to provide the timing sequences that control operations in a
digital system.
Steps:
1. The MSB of the Gray Code is the same as the MSB of the Binary.
2. Coding from left to right, add each adjacent pair of bits to get the next bit of the Gray Code.
3. Omit the carries if occurs.
Example:
Steps:
1. The Most Significant Bit (MSB) of the Binary number is the same as the MSB of the Gray code.
2. Add the next significant bit of the binary number to the next significant bit of the gray coded number to
obtain the next binary bit.
3. Repeat step 2 till all bits of the gray coded number have been added.
Example:
Convert the Gray Code 1010 to its equivalent Binary.
26
The answer is 1100.
Other Decimal Codes
• Binary Codes for decimal digits require a minimum of four bits.
• The 2421 is an example of a weighted code.
• In a weighted code, the bits are multiplied by the weights indicated and the sum
of the weightedbits given the decimal digit.
• For Example: The bit combination 1101, when weighted by the respective digits 2421,
2x1+4x1+2x0+1x1=7
• The excess-3 code is a decimal code that has been used in older computers.
• This is an un-weighted code.
• The ASCII code is the standard code commonly used for the transmission of binary
information.
• Each character is represented by a 7-bit code and usually an eighth bit is inserted for parity.
• The code consists of 128 characters.
• Alphanumeric Code used in IBM equipment is the EBCDIC (Extended BCD Interchange
Code).
• It uses eight bits for each character.
• EBCDIC has the same character symbols as ASCII but the bit assignment to
characters isdifferent.
• When alphanumeric characters are used internally in a computer for data processing.
EXERCISES:
1. Convert the following Decimal Numbers to Binary.
a) (120)10 b) (24.8)10
2. Convert the following Binary Numbers to Decimal.
27
a) (11011)2 b) (101011.11)2
3. Convert the following Hexadecimal Numbers to Decimal.
a) (4CE)16 b) (8B.A)16
4. Convert the following Decimal Numbers to Hexadecimal.
a) (48)10 b) (27.7)10
5. Convert the following Hexadecimal Numbers to Binary.
a) (C7)16 b) (FF.A)16
6. Convert the following Binary Numbers to Hexadecimal.
a) (111001)2 b) (11101.01)2
7. Convert the following Octal Numbers to Decimal.
a) (24)8 b) (23.43)8
8. Convert the following Decimal numbers to Octal.
a) (99)10 b) (19.6)10
9. Convert the following Octal Numbers to Binary.
a) (132)8 b) (76.9)8
10. Convert the following Binary Numbers to Octal.
a) (10101)2 b) (110.11)2
11. Perform the following additions in the binary number system.
a) +95 and +27 b) -95 and -27
12. Perform the following subtraction in the binary number system.
a) 4 from 13 b) 14 from 17
13. Give the 1’s and 2’s complement forms for the following binary numbers.
a) 11011 b) 11001 c) 101011
14. Convert the following decimal numbers into their 9’s and 10’s complements.
a) 6 b) 34 c) 99
***************************
28
********************************************************************
Chapter 2 Register Transfer and Micro-operations
********************************************************************
This Chapter introduces a Register Transfer Language and shows how it is used to express
microoperations in symbolic form. Symbols are defined for arithmetic, logic, and shift
microoperations.
• They are low-level instructions used in some designs to implement complex machine
instructions.
• For example, the register that holds an address for the memory unit is usually called a
memory address register and is designated by the name MAR. Other designations for
registers are PC (for Program Counter), IR (for Instruction Register, and R1 (for processor
register).
29
• The individual flip-flops in an n-bit register are numbered in sequence from 0 through n - 1,
starting from 0 in the rightmost position and increasing the numbers toward the left.
• Figure 2.1 shows the representation of registers in block diagram form. The most common
way to represent a register is by a rectangular box with the name of the register inside, as in
Fig. 2.1(a). The individual bits can be distinguished as in (b). The numbering of bits in a 16-
bit register can be marked on top of the box as shown in (c). A 16-bit register is partitioned
into two parts in (d). Bits 0 through 7 are assigned the symbol L (for low byte) and bits 8
through 15 are assigned the symbol H (for high byte). The name of the 16-bit register is PC.
The symbol PC (0-7) or PC (L) refers to the low-order byte and PC (8-15) or PC (H) to the
high-order byte.
• The Statement
R2 <--R1
• The basic symbols of the register transfer notation are listed in Table 2.1.
Table 2.1 Basic Symbols for Register Transfers
30
Different types of Register Transfer operations:
1. Simple Transfer R2 R1:
a. The content of R1 is copied into R2 without affecting the content of R1.
b. It is an unconditional type of transfer operation.
2. Conditional Transfer P: R2R1
o Figure 2.2 shows the block diagram that depicts the transfer from R1 to R2.
o The n outputs of register R1 are connected to the n inputs of register R2.
o The letter n indicates any number of bits for the register.
o Register R2 has a load input that is activated by control variable P.
o Control variable is synchronized with the same clock as the one applied to the register.
31
Figure 2.3 Bus Systems for four registers
S1 S2 Register Selected
0 0 A
0 1 B
1 0 C
1 1 D
32
A three state bus buffer is an integrated circuit that connects multiple data sources to a single bus. The open
drivers can be selected to be either a logical high, a logical low, or high impedance which allows other buffers to drive
the bus. A=1100;A0=0,A1=0;A2=1;A3=1
S0 S1 C REG
0 0 DECODER – OTH LINE A
0 1 DECODER-1ST LINE B
1 0 2ND LINE C
1 1 3RD LINE D
ii) Memory Transfer
• The transfer of information from a memory is called read operation.
• The transfer of new information to be stored into the memory is called write operation.
• A memory symbolized by the letter M.
• The particular memory is selected by the memory address during the transfer.
• A memory unit that receives the address from a register, called the Address Register (AR).
• The data are transferred to another register, called the Data Register (DR).
• The read operation can be stated as follows: Read
: DR M [ AR ]
• The write operation can be stated
as follows Write: M [AR] R1.
2.4 Arithmetic Microoperations
33
• Arithmetic microoperations perform arithmetic operations on numeric data stored in registers.
• Table 2.4 lists the various Arithmetic microoperations performed on the registers.
Addition:
In addition microoperation, the value in register R1 is added to the value in the
register R2 andthen the sum is transferred into register R3.
R3 R1 + R2
Subtraction:
In subtraction microoperation, the contents of register R2 are subtracted from
contents of theregister R1, and then the result is transferred into R3.
R3 R1 - R2
Increment:
In increment micro-operation, the value inside the R1 register is
increased by 1.R1 R1 + 1
Decrement:
In Decrement micro-operation, the value inside the R1 register is
decreased by 1.R1 R1 – 1
34
0+0=0 WITH NO CARRY
0+1=1 WITH NO CY
1+0=1 WITH NO CY
1+1=0 WITH CY 1
0 0 0 =0
0 0 1=1
0 1 0=1
0 1 1=0 WITH CY 1
100=0
1 0 1= 0 WITH CY 1
1 1 0 = 0 WITH CY 1
1 1 1 = 1 WITH CY 1
• The carries are connected in a chain through the full-adders.
• The input carry to the binary adder is C0 and the output carry is C,.
• The S outputs of the full-adders generate the required sum bits.
• An n-bit binary adder requires n full-adders.
• The output carry from each full-adder is connected to the input carry of the next-high-order
full-adder.
• The n data bits for the A inputs come from one register (such as R1), and the n data bits for the
B inputs come from another register (such as R2).
• The sum can be transferred to a third register or to one of the source registers (R1 or R2),
replacing its previous content. A = 1101 B= 1011 S=? CY=?
35
This Circuit Requires prerequisite knowledge of Exor Gate, Binary Addition and
Subtraction, Full Adder.
Lets consider two 4-bit binary numbers A and B as inputs to the Digital Circuit for the
operation with digits
A0 A1 A2 A3 for A
B0 B1 B2 B3 for B
The circuit consists of 4 full adders since we are performing operation on 4-bit
numbers.
There is a control line K that holds a binary value of either 0 or 1 which determines
that the operation being carried out is addition or subtraction.
As shown in the figure, the first full adder has control line directly as its input(input
carry Cin),
The input A0 (The least significant bit of A) is directly input in the full adder.
The third input is the exor of B0 and K. The two outputs produced are Sum/Difference
(S0) and Carry (C0).
If the value of K (Control line) is 1, the output of B0(exor)K=B0′(Complement B0).
Thus the operation would be A+(B0′). Now 2’s complement subtraction for two
numbers A and B is given by A+B’. This suggests that when K=1, the operation being
performed on the four bit numbers is subtraction.
Similarly If the Value of K=0, B0 (exor) K=B0. The operation is A+B which is simple
binary addition. This suggests that When K=0, the operation being performed on the
four bit numbers is addition.
Then C0 is serially passed to the second full adder as one of it’s outputs. The
sum/difference S0 is recorded as the least significant bit of the sum/difference. A1,
A2, A3 are direct inputs to the second, third and fourth full adders. Then the third
36
input is the B1, B2, B3 EXORed with K to the second, third and fourth full adder
respectively. The carry C1, C2 are serially passed to the successive full adder as one
of the inputs. C3 becomes the total carry to the sum/difference. S1, S2, S3 are
recorded to form the result with S0.
For an n-bit binary adder-subtractor, we use n number of full adders.
37
2.5 Logic Microoperations
• Logic Microoperations specify binary operations for strings of bits stored in registers.
• These operations consider each bit of register separately and treat them as binary variables.
• For example, the exclusive-OR microoperation with contents of two registers R1 and R2
is Symbolizedby the statement,
0011 1 0 1 0 C o n t e n t o f R1[58]
0101 1 1 0 0 C o n t e n t o f R 2 [ 9 2 ]
-------------------
0110 0 1 1 0 Content of R1 after P = 1
• The content of R1, after the execution of the microoperation, is equal to the bit-by-bit
exclusive-OR operation on pairs of bits in R2 and previous values of Rl .
• The logic microoperations are seldom used in scientific computations, but they are very
useful for bit manipulation of binary data and for making logical decisions.
• Table 2.5 lists the various Logic Microperations.
A^B’ = AND NOT B; A’^B= AND NOT A ; AvB’=OR NOT B;A’VB= OR NOT A
38
2.6 Shift Microoperations
• Shift Microoperations are used for serial transfer of data.
• They are also used in conjunction with arithmetic, logic, and other data-processing
operations.
• The contents of a register can be shifted to the left or the right.
• At the same time that the bits are shifted, the first flip-flop receives its binary information
fromthe serial input.
• During a shift-left operation the input transfers a bit into the rightmost position.
• During a shift-right operation the input transfers a bit into the leftmost position.
• The information transferred through the serial input determines the type of shift.
• There are three types of shifts micro-operations:
1. Logical Shift
➢ Logical Shift Left
➢ Logical Shift Right
2. Arithmetic Shift<<;>>
3. Circular Shift
Logical Shift
• Logical shift transfers the 0 through the serial input.
• Logical Shift Left:
o Figure 2.7(a) shows the Logical Shift Left Microoperation.
o In this shift one position moves each bit to the left one by one.
o The Empty Least Significant Bit (LSB) is filled with zero
o The Most Significant Bit (MSB) is rejected.
39
o Most Significant Bit (MSB) is filled with zero.
o Least Significant Bit (LSB) is rejected.
• Arithmetic Shift Microoperation shifts a signed binary number to the left or to the right
position.
• This Microoperation is divided into two categories:
1. Arithmetic Shift Left
2. Arithmetic Shift Right
• Arithmetic Shift Left:
o Figure 2.7(c) shows the Arithmetic Shift Left Microoperation.
o In this one position moves each bit to the left one by one.
o An Arithmetic Shift Left multiplies a signed binary number by 2.
o The leftmost bit in a register holds the sign bit.
o The reaming bits hold the number.
o The sign bit is 0 for positive and 1 for negative.
o Most Significant Bit (MSB) is rejected.
EXERCISES:
1. What is meant by Microoperation in Computer Organization?
2. What is Register Transfer Language?
3. Describe about Register Transfer in Computer Organization with neat Block Diagram
41
4. Write the basic symbols for Register Transfer.
5. Explain about Bus and Memory Transfers in Computer Organization.
6. Describe about Microoperations in Computer Organization.
7. Explain with an example for Logic Microoperations.
8. Describe about Shift Microoperation with suitable diagram.
**************************
42
UNIT – II
************************************************************************
Chapter 3 Central Processing Unit
************************************************************************
The main part of the Computer that performs the Data Processing is called the Central Processing Unit and is
referred to as the CPU. The Central Processing Unit consists of three main parts, such as, Register Set, ALU, and
Control Unit. The Register Set stores intermediate data used during the execution of the instructions. Arithmetic
and Logic Unit performs the microoperations for executing the instructions. The control unit supervises the
transfer of information among the registers and instructs the ALU as to which operation to perform.
43
Figure 3.1 Bus Organization for seven CPU Register
PUSH
o The stack pointer is incremented so that it points to the address of the next-higher word.
o A memory write operation inserts the word from DR into the top of the stack.
o SP holds the address of the top of the stack and that M [SP] denotes the memory word
specified by the address presently available in SP.
o The first item stored in the stack is at address L The last item is stored at address 0. If
SP reaches 0, the stack is full of items, so Empty is set to L
POP
o A new item is deleted from the stack if the stack is not empty (if EMTY = 0).
45
o The top item is read from the stack into DR.
o The stack pointer is then decremented.
o If its value reaches zero, the stack is empty, so EMTY is set to 1 This condition is
reached if the item read was in location 1
o Once this item is read out, SP is decremented and reaches the value 0, which is the initial
value of SP.
o An erroneous operation will result if the stack is pushed when FULL = 1 or popped when
EMTY = 1
ii) Memory Stack
• A Stack can exist as a stand-alone unit a s shown in Figure 3.2 or can be
implemented in a random-access memory attached to a CPU.
• The Program Counter (PC) points at the address of the next instruction in the program. It is
used during the fetch phase to read an instruction.
• The Address Register (AR) points at an array of data. It is used during the execute phase to read
an operand.
• The Stack Pointer (SP) points at the top of the stack. It is used to Push or Pop items into the
stack. A stack pointer is loaded with an initial value. This initial value must be at the bottom
address of an assigned stack in memory. SP is automatically decremented or incremented with
ever push or pop operation.
46
• Assume that the item in the stack with data register (DR).
• A new item is inserted with the push operation as follows:
SP SP – 1
M[SP] DR
❖ The stack pointer is decremented.
❖ A memory write operation inserts the word from DR into the top of the stack.
• A new item is deleted with a pop operation as follows:
DR M[SP]
SP SP + 1
❖ The stack pointer is incremented
❖ The top item is read from the stack into DR.
iii) Reverse Polish Notation
• Reverse Polish notation (RPN) is a method for representing expressions in which the
operator symbol is placed after the arguments being operated on.
• The Polish mathematician Lukasiewicz showed that arithmetic expressions can be
represented in prefix notation. This representation, often referred to as Polish
Notation, places the operator before the operands. The postfix notation, referred
to as Reverse Polish Notation (RPN), places the operator after the operands.
• The following examples demonstrate the three representations:
A + B Infix notation
+ AB Prefix or Polish notation
AB + Postfix or reverse Polish notation
• The reverse Polish notation is in a form suitable for stack manipulation. The expression
A*B+C*D
is written in reverse Polish notation as
AB * CD * + = 23*45*+ = 26
47
• Reverse Polish notation, combined with a stack arrangement of registers, is the most efficient
way known for evaluating arithmetic expressions.
• This procedure is employed in some electronic calculators and also in some computers.
• The stack is particularly useful for handling long, complex problems involving chain
calculations.
• It is based on the fact that any arithmetic expression can be expressed in parentheses-free
Polish notation.
• The procedure consists of first converting the arithmetic expression into its equivalent reverse
Polish notation.
• The operands are pushed into the stack in the order in which they appear.
• The following rnicrooperations are executed with the stack when an operation is entered in a
calculator or issued by the control in a computer:
(1) the two topmost operands in the stack are used for the operation, and
(2) the stack is popped and the result of the operation replaces the lower operand.
• By pushing the operands into the stack continuously and performing the operations as
defined above, the expression is evaluated in the proper order and the final result remains
on top of the stack.
• The following numerical example may clarify this procedure. Consider the arithmetic
expression
(3 * 4) + (5 * 6)
48
3.3 Instruction Formats
• A computer usually has a variety of Instruction Code Format.
• Figure 3.4 shows the Instruction Format with Mode Field.
• It is the function of the control unit within the CPU.
• The bits of the instruction are divided into groups called fields.
• The most common fields in Instruction Formats are:
o Operation Code: Specifies the operation to be performed.
o Operand /Address Field : Data / Designates a memory address.
o Mode Field : The effective address is determined.
3. Stack Organization
• Stack organization would have PUSH and POP instructions which require an address field.
➢ The instruction PUSH X
➢ Push the word at address X to the top of the stack.
❖ The stack pointer is updated automatically.
❖ The instruction ADD in a stack computer consists of an operation code only
49
with noaddress field.
❖ This operation has the effect of popping the two top numbers from the stack,
adding thenumbers, and pushing the sum into the stack.
Three- Address Instructions:
• Three-address instruction formats can use each address field to specify eithera processor
register or a memory operand.
• The program in assembly language that evaluates X= (A+B) * (C+D)
Two-Address Instructions:
• Two-address instructions are the most common in commercial computers.
• Each address field can specify either a processor register or a memory word.
• The program to evaluate X = (A+B) * (C+D) is as follows:
• The MOV instruction moves or transfers the operands to and from memory and processor
registers.
One-Address Instructions:
• One-address instruction uses an implied accumulator (AC) register for all data manipulation.
• For multiplication and division there is a need for a second register.
• The program to evaluate X = ( A + B ) * ( C + D ) is as follows:
LOAD A AC M[A]
ADD B AC AC + 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
50
• 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:
• Stack organized computer does not use an address field for the instructions ADD and MUL.
• The PUSH and POP instructions need an address field to specify the operand that
communicates with the stack.
• The following program shows how X = (A + B) * (C + D) w i l l be written for astack
organized computer.
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
• The name “zero address” is given to this type of computer because of the absence of an
address field in the computational instructions.
3.4 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 is dependent on the addressing
mode of the instruction.
• Addressing Mode specifies a rule for interpreting or modifying t he address field of
theinstruction before the operand is actually referenced.
• Computers use addressing mode techniques for the purpose of accommodating one or both of
the following provisions:
• To give programming versatility to the user by providing such facilities as
• Pointers to memory
• Counters for loop control,
• Indexing of data
• Program relocation
• To reduce the number of bits in the addressing field of the instruction.
• The control unit of a computer is designed to go through an instruction cycle that is divided into
51
three major phases:
• Fetch the instruction from memory
• Decode the instruction
• Execute the instruction
1. Implied Mode:
• In this mode the operands are specified implicitly in the definition of the instruction.
• For example, the instruction "complement accumulator" is an implied-mode instruction because the
operand in the accumulator register is implied in the definition of the instruction.
• In fact, all register reference instructions that use an accumulator are implied-mode instructions.
2. Immediate Mode:
• The operand field contains the actual operand to be used in conjunction with the operation specified
in the instruction.
• In this mode the operands are in registers that reside within the CPU. The particular register is
selected from a register field in the instruction.
• A k-bit field can specify any one of 2' registers.
• In this mode the instruction specifies a register in the CPU whose contents give the address of the
operand in memory.
52
• In other words, the selected register contains the address of the operand rather than the operand
itself.
• Before using a register indirect mode instruction, the programmer must ensure that the memory
address of the operand is placed in the processor register with a previous instruction. A reference to
the register is then equivalent to specifying a memory address.
• The advantage of a register indirect mode instruction is that the address field of the instruction uses
fewer bits to select a register than would have been required to specify a memory address directly.
5. Autoincrement or Autodecrement Mode:
• This is similar to the register indirect mode except that the register is incremented or decremented
after (or before) its value is used to access memory.
• When the address stored in the register refers to a table of data in memory, it is necessary to
increment or decrement the register after every access to the table.
• This can be achieved by using the increment or decrement instruction.
• The address field of an instruction is used by the control unit in the CPU to obtain the operand from
memory.
• The effective address is defined to be the memory address obtained from the computation dictated
by the given addressing mode. The effective address is the address of the operand in a type
instruction. It is the address where control branches in response to a branch-type instruction.
• In a branch-type instruction the address field specifies the actual branch address.
• The CPU register used in the computation may be the program counter, an index register, or a base
register.
53
8. Relative Addressing Mode
• In this mode the content of the program counter is added to the address part of the instruction
in order to obtain the effective address.
• The address part of the instruction is usually a signed number (in 2's complement
representation) which can be either positive or negative.
• When this number is added to the content of the program counter, the result produces an
effective address whose position in memory is relative to the address of the next instruction.
• The index register is a special CPU register that contains an index value.
• The address field of the instruction defines the beginning address of a data array in memory.
• Each operand in the array is stored in memory relative to the beginning address.
• The distance between the beginning address and the address of the operand is the index value
stored in the index register.
• Any operand in the array can be accessed with the same instruction provided that the index
register contains the correct index value.
• In this mode the content of a base register is added to the address part of the instruction to
obtain the effective address.
• This is similar to the indexed addressing mode except that the register is now called a base
register instead of an index register.
• The difference between the two modes is in the way they are used rather than in the way that
they are computed.
• An index register is assumed to hold an index number that is relative to the address part of the
instruction.
• A base register is assumed to hold a base address and the address field of the instruction gives
a displacement relative to this base address.
54
• The base register addressing mode is used in computers to facilitate the relocation of
programs in memory.
3.5 Data Transfer and Manipulation
• Computers provide an extensive set of instructions to give the user the flexibility to carry out
various computational tasks.
• The instruction set of different computers differ from each other mostly in the way the operands are
determined from the address and mode fields.
• Most computer instructions can be classified into three categories:
❖ Data Transfer Instructions
❖ Data Manipulation Instructions
❖ Program Control Instructions
Data Transfer Instructions
• Data Transfer Instructions move data from one place in the computer to another
withoutchanging the data content.
• The most common transfers are between memory and processor registers, between processor
registers and input or output, and between the processor register’s themselves.
• Table 3.1 gives a list of eight data transfer instructions used in many computers.
Name Mnemonic
Load LD
Store ST
Move MOV
Exchange XCH
Input IN
Output OUT
Push PUSH
Pop POP
• The Load instruction has been used mostly to designate a transfer from memory to a processor
register, usually an accumulator.
• The Store instruction designates a transfer from a processor register into memory.
55
• The Move instruction has been used in computers with multiple CPU registers to designate a
transfer from one register to another. It has also been used for data transfers between CPU
registers and memory or between two memory words.
• The Exchange instruction swaps information between two registers or a register and a memory
word.
• The Input and Output instructions transfer data among processor registers and input or
output terminals.
• The Push and Pop instructions transfer data between processor registers and a memory
stack.
1. Arithmetic Instructions
2. Logical and Bit Manipulation Instructions
3. Shift Instructions
1. Arithmetic Instructions
• Some small computers have only addition and possibly subtraction instructions. The
multiplication and division must then be generated by means of software subroutines.
• A list of typical arithmetic instructions is given in Table 3.2.
Table 3.2 Arithmetic Instructions
Name Mnemonic
Increment INC
Decrement DEC
Add ADD
Subtract SUB
Multiply MUL
Divide DIV
Add with carry ADDC
56
Subtract with borrow SUBB
• The Increment instruction adds 1 to the value stored in a register or memory word.
• The Decrement instruction subtracts 1 from a value stored in a register or memory word.
• The Add, Subtract, Multiply, and Divide instructions may be available for different types of
data.
• An arithmetic instruction may specify fixed-point or floating-point data, binary or
decimal data, single-precision or double-precision data.
Name Mnemonic
Clear CLR
Complement COM
AND AND
OR OR
Exclusive-OR XOR
Clear Carry CLRC
Set Carry SETC
Complement Carry COMC
Enable Interrupt EI
Disable Interrupt DI
A->20H = 0010 0000
8 BIT->FEH= 1111 1110
---------------------------
AND 0010 0000
OR 1111 1110
EXOR 1101 1110
3. Shift Instructions
Name Mnemonic
Logical Shift Right SHR
Logical Shift Left SHL
Arithmetic Shift Right SHRA
Arithmetic Shift Left SHLA
Rotate Right ROR
Rotate Left ROL
Rotate Right Through Carry RORC
Rotate Left Through Carry ROLC
• The logical shift inserts 0 to the end bit position. The end position is the leftmost bit for
shift right and the rightmost bit position for the shift left.
• The arithmetic shift-right instruction must preserve the sign bit in the leftmost position.
• The arithmetic shift-left instruction inserts 0 to the end position and is identical to the
logical shift-left instruction.
• The rotate instructions produce a circular shift.
• The rotate through carry instruction treats a carry bit as an extension of the register whose
word is being rotated.
• Thus a rotate-left through carry instruction transfers the carry bit into the rightmost bit
position of the register, transfers the leftmost bit position into the carry, and at the same
time, shifts the entire register to the left.
58
3.6 Program Control
Name Mnemonic
Branch BR
Jump JMP
Skip SKP
Call CALL
Return RET
Compare (by subtraction) CMP
Test (by ANDing) TST
59
• The bits are set or cleared as a result of an operation performed in the ALU.
1. Bit C (Carry):
a. Set to 1, if carry is 1
b. Set to 0, if carry is 0
2. Bit S (Sign):
a. Set to 1, if the highest order bit is 1.
b. Set to 0, if the bit is 0.
3. Bit Z (Zero):
a. Z=1, if the output is 0
b. Z=0, if the output is not zero.
4. Bit V (Overflow):
a. V=1 , if the output is greater than +127 or less then -128
b. V=0
Conditional Branch Instructions
60
BE Branch if equal A=B
BNE Branch if not equal A#B
Signed Compare Conditions (A –B)
BGT Branch if greater than A>B
Branch if greater than A >= B
BGE
equal
BLT Branch if less than A<B
BLE Branch if less or equal A <= B
BE Branch if equal A=B
BNE Branch if not equal A#B
• The instruction that returns from the last subroutine is implemented by the microoperations:
PC M[SP] Pop stack and transfer to PC
Program Interrupt
• Program Interrupt refers to the transfer of program control from a currently running
program to another service program as a result of an external or internal generated
request.
• Control returns to the original program after the service program is executed.
• The interrupt procedure is quite similar to a subroutine call except for three variations:
(1) The interrupt is usually initiated by an internal or external signal rather than from the
execution of an instruction;
(2) the address of the interrupt service program is determined by the hardware rather than from
the address field of an instruction; and
(3) an interrupt procedure usually stores all the information necessary to define the state of the
CPU rather than storing only the program counter.
• The state of the CPU at the end of the execute cycle (when the interrupt is recognized) is
determined from:
1. The content of the program counter
2. The content of all processor registers
3. The content of certain status conditions
• The collection of all status bit conditions in the CPU is sometimes called a program status
word or PSW.
• When the CPU is executing a program that is part of the operating system, it is said to supervisor
mode be in the supervisor or system mode.
Types of Interrupts
• An interrupt is a signal sent to the processor that interrupts the current process. It may be
generated by a hardware device or a software program.
• There are three major types of interrupts that cause a break in the normal execution of a program.
They can be classified as:
1. External Interrupts
2. Internal Interrupts
62
3. Software Interrupts
External Interrupts
➢ Come from I/O device, from a timing device, from a circuit.
➢ Monitoring the power supply, or from any other external source.
Software Interrupts
➢ Initiated by executing an instruction.
➢ Used by the programmer to initiate an interrupt procedure at any desired point in the
program.
• An important aspect of computer architecture is the design of the instruction set for the processor.
• The instruction set chosen for a particular computer determines the way that machine language
programs are constructed.
• A Computer with a large number of instructions is classified as a complex instruction set
computer, abbreviated CISC.
63
• RISC stands for Reduced Instruction Set Computer. It is a type of Computer that has a limited
number of instructions. They can execute their instructions very fast because instructions are
very small and simple.
CISC Characteristics
• The major characteristics of CISC architecture are:
RISC Characteristics
3. Compiler support for efficient translation of high-level language programs into machine
language programs
64
• A characteristic of some RISC processors is their use of overlapped register windows to provide the
passing of parameters and avoid the need for saving and restoring register values.
• Each procedure call results in the allocation of a new window consisting of a set of registers from
the register file for use by the new procedure.
• Each procedure call activates a new register window by incrementing a pointer, while the return
statement decrements the pointer and causes the activation of the previous window.
• Windows for adjacent procedures have overlapping registers that are shared to provide the passing
of parameters and results.
S. No RISC CISC
1 Focus on software Focus on hardware
Uses both hardwired and microprogrammed
2 Uses only hardwired control unit
control unit.
Transistors are used for more Transistors are used for storing complex
3
registers instructions
4 Fixed sized instructions Variable sized instructions
Can perform only register to Can perform REG to REG or REG to MEM or
5
register Arithmetic operations MEM to MEM
6 Requires more number of registers Requires less number of registers
7 Code size is large Code size is small
An instruction execute in single clock
8 An instruction take more than one clock cycle
cycle
9 An instruction fit in one word An instruction are larger than size of one word.
EXERCISES:
**********************************
66
************************************************************************
Chapter 4 Pipeline and Vector Processing
************************************************************************
In this Chapter, the concept of pipelining is explained and the way it can speed-up processing is
illustrated with several examples. Both arithmetic and instruction pipeline is considered. It is shown how
RISC processors can achieve single-cycle instruction execution by using an efficient instruction pipeline
together with the delayed load and delayed branch techniques. Vector processing is introduced and
examples are shown of floating-point operations using pipeline procedures.
4.1 Pipelining
• Pipelining is a technique of decomposing a sequential process into sub operations, with each sub
process being executed in a special dedicated segment that operates concurrently with all
other segments.
• Pipelining can be visualized as a collection of processing segments through which binary
information flows.
• Each segment performs partial processing dictated by the way the task is partitioned.
• The result obtained from the computation in each segment is transferred to the next segment in the
pipeline.
• The final result is obtained after the data have passed through all segments.
• The Pipeline organization will be demonstrated by means of a simple example:
Ai * Bi + Ci for i = 1, 2, 3, …7
• Each sub operation is to be implemented in a segment within a pipeline.
• Each segment has one or two registers and a combinational circuit as shown in Figure 4.1.
• R1 through R5 are registers that receive new data with every clock pulse.
• The multiplier and adder are combination al circuits.
• The sub operations performed in each segment of the pipeline are as follows:
R1 Ai, R2 Bi Input Ai, and Bi
R3 R1 * R2, R4 Ci multiply and input Ci
R5 R3 + R4 Add Ci to product
67
Figure 4.1 Pipeline Processing
• The five registers are loaded with new data every clock pulse.
• The effect of each clock is shown in Table 4.1.
Table 4.1 Effect of Registers with Clock
68
of the pipelines.
4.2 Arithmetic Pipeline
• Arithmetic Pipeline units are usually found in very high speed computers.
• They are used to implement floating-point operations, multiplication of fixed-point numbers, and
similar computations encountered in scientific problems.
• A pipeline multiplier is essentially an array multiplier.
• Special adders designed to minimize the carry propagation time through the partial products.
• Floating-point operations are easily decomposed into sub operations.
• Inputs to the floating-point adder pipeline are two normalized floating-point binary numbers:
X = A x 2a
Y = B x 2b
A and B are two fractions representing mantissas (two Fractions) and a, b are the exponents.
• The Floating-point addition and subtraction can be performed in four segments, as shown in
Figure.4.2. The registers labeled R are placed between the segments to store intermediate results.
• The sub operations that are performed in the four segments are:
Z = 1.0324 x 103
70
➢ The Decode Instruction stage is responsible for decoding the instruction
➢ Sending it into out the various control lines to the other parts of the processor.
➢ The Fetch operand and Execute Instruction stages are responsible for storing and
loading values to and from memory.
71
Figure 4.3 Instructio n Cycle in the CPU
Pipelining Conflicts
• There are three major difficulties that cause the instruction pipeline to deviate from its normal
operation.
1. Resource Conflicts
2. Data Dependency
3. Branch Difficulties
1. Resource Conflicts
➢ Caused by access to memory by two segments at the same time.
➢ Most of these conflicts can be resolved by using separate instruction and data memories.
2. Data Dependency
➢ A Data Dependency occurs when an instruction needs data that are not yet available.
➢ The data dependency conflict can be solved by using the following methods:
o Hardware Interlocks: The most straight forward method is to insert hardware
interlocks.
o An interlock is a circuit that detects instructions whose source operands or
72
destination of instructions farther up in the pipeline.
o Detection of this situation causes the instruction whose source is not available to be
delayed by enough clock cycles to resolve the conflict.
o This approach maintains the program sequence by using hardware to insert the
required delay.
o Operand Forwarding: The operand forwarding technique uses special hardware to
detect a conflict and avoid the conflict path by using a special path to forward the
values between the pipeline segments.
o Delayed Load: The delayed load operation is nothing but when executing an
instruction in the pipeline.
o Simply delay the execution starting the instruction such that all the data that is needed
for the instruction can be successfully updated before execution.
3. Branch Difficulties
➢ Arise from branch and other instructions that change the value of PC.
➢ The following are the solutions for solving the branch conflicts that obtained in the
pipelining concept.
o Pre-fetch Target Instruction: In this branch instructions which are to be executed
are pre-fetch detect if any errors are present in the branch before execution.
o Branch Target Buffer: BTB is the Associative memory implementation of the branch
conditions.
o Loop Buffer: The loop buffer is a very high speed memory device.
o Branch Prediction: Before a branch is to be executed, the instructions along with the
error checking conditions are checked.
o Delayed Branch: This concept is same as the delayed load process in which we are
delaying the execution of a branch process, before all the data is fetched by the system
for beginning the CPU.
A: ALU Operation
E: Execute Instruction
• The instruction is decoded and an ALU operation is performed in the A segment. The ALU is
used for three different functions, depending on the decoded instruction. It performs an
operation for a data manipulation instruction, it evaluates the effective address for a load or
store instruction, or it calculates the branch address for a program control instruction.
• The E segment directs the output of the ALU to one of three destinations, depending on the
decoded instruction.
Delayed Load
1. LOAD: R1 ← M[address 1]
2. LOAD: R2 ← M[address 2]
3. ADD: R3 ← R1 + R2
74
4. STORE: M[address 3] ← R3
• If the three-segment pipeline proceeds without interruptions, there will be a data conflict in
instruction 3 because the operand in R2 is not yet available in the A segment.
• This can be seen from the timing of the pipeline shown in Figure 4.6(a).
• Figure 4.6(b) shows the same program with a no-op instruction inserted after the load to R2
instruction.
➢ Image Processing
Vector Operations
• Consequently, operations on Vectors must be broken down into single computations with
subscripted variables.
• The element Vi of Vector V is written as V(I) and the index I refers to a memory address or
register where the number is stored.
• To examine the difference between a conventional Scalar Processor and a Vector Processor,
consider the following Fortran DO loop:
DO 20 I = 1, 100
20 C (I) = B (I) + A (I)
• This is a program for adding two vectors A and B of length 100 to produce a vector C. This is
implemented in machine language by the following sequence of operations.
Initialize I = 0
20 Read A (I)
Read B (I)
Store C (I) = A (I) + B (I)
Increment I = I + 1
If I<=100 go to 20
Continue
• A computer capable of vector processing eliminates the overhead associated with the time it takes
to fetch and execute the instructions in the program loop.
• It allows operations to be specified with a single vector instruction of the form
76
• It is also possible to design the processor with a large number of registers and store all operands
in registers prior to the addition operation.
• In that case the base address and length in the vector instruction specify a group of CPU registers.
Matrix Multiplication
• Matrix multiplication is one of the most computational intensive operations performed in computers
with vector processors.
• The multiplication of two n x n matrices consists of n' inner products or n' multiply-add operations.
• An n x m matrix of numbers has n rows and m columns and may be considered as constituting a set of
n row vectors or a set of m column vectors.
• The product matrix C is a 3 x 3 matrix whose elements are related to the elements of A and B by
the inner product:
• For example, the number in the first row and first column of matrix C is calculated by letting i = 1, j
= 1, to obtain
• In general, the inner product consists of the sum of k product terms of the form
• The inner product calculation on a pipeline vector processor is shown in Figure 4.8.
• When addition operation is taking place in the adder pipeline the next set of values will be brought
into the multiplier pipeline.
• All the operations can be performed simultaneously using the parallel processing concepts by the
implementation of pipeline.
Memory Interleaving
• Memory Interleaving is a technique which divides the memory into a number of modules. In
an interleaved memory, different sets of addresses are assigned to different memory modules.
• A memory module is a memory array together with its own address and data registers.
• The modular system permits one module to initiate a memory access while other modules are in the
process of reading or writing a word and each module can honor a memory request independent of
the state of the other modules.
• A modular memory is useful in systems with pipeline and vector processing.
• A vector processor that uses an n-way interleaved memory can fetch n operands from n different
modules.
Supercomputers
• A commercial computer with vector instructions and pipelined floating-point arithmetic operations is
referred to as a supercomputer.
• Supercomputers are very powerful, high-performance machines used mostly for scientific
computations.
• Supercomputers also use special techniques for removing the heat from circuits to prevent them from
burning up because of their close proximity.
• The instruction set of supercomputers contains the standard data transfer, data manipulation, and
program control instructions of conventional computers.
• A supercomputer is a computer system best known for its high computational speed, fast and large
memory systems, and the extensive use of parallel processing.
• It is equipped with multiple functional units and each unit has its own pipeline configuration.
• Supercomputers are not suitable for normal everyday processing of a typical computer installation.
They are limited in their use to a number of scientific applications, such as numerical weather
forecasting, seismic wave analysis, and space research.
78
• They have limited use and limited market because of their high price.
• A measure used to evaluate computers in their ability to perform a given number of floating-point
operations per second is referred to as flops.
• The term megaflops is used to denote million flops and gigaflops to denote billion flops.
• An Array Processor is a processor that performs computations on large arrays of data. The
term is used to refer to two different types of processors.
• An attached array processor is an auxiliary processor attached to a general-purpose computer.
• It is intended to improve the performance of the host computer in specific numerical computation
tasks.
• An SIMD array processor is a processor that has a single-instruction multiple-data organization.
• It manipulates vector instructions by means of multiple functional units responding to a common
instruction. Although both types of array processors manipulate vectors, their internal organization
is different.
Attached Array Processor
• An attached array processor is designed as a peripheral for a conventional host computer, and its
purpose is to enhance the performance of the computer by providing vector processing for complex
scientific applications.
• It achieves high performance by means of parallel processing with multiple functional units.
• It includes an arithmetic unit containing one or more pipelined floating point adders and multipliers.
• The array processor can be programmed by the user to accommodate a variety of complex arithmetic
problems.
• Figure 4.9 shows the interconnection of an attached array processor to a host computer.
• The host computer is a general-purpose commercial computer and the attached processor is a back-end
machine driven by the host computer.
• The array processor is connected through an input-output controller to the computer and the computer
treats it like an external interface.
• The data for the attached processor are transferred from main memory to a local memory through a
high-speed bus.
• The general-purpose computer without the attached processor serves the users that need conventional
data processing.
• The system with the attached processor satisfies the needs for complex arithmetic applications.
79
Figure 4.9 Attached Array Processor with host computer
SIMD Array Processor
• An SIMD array processor is a computer with multiple processing units operating in parallel.
• The processing units are synchronized to perform the same operation under the control of a
common control unit, thus providing a single instruction stream, multiple data stream (SIMD)
organization.
• A general block diagram of an array processor is shown in Figure 4.10.
80
EXERCISES:
1. Explain about pipelining with an example.
2. Discuss about Arithmetic pipeline with an example.
3. What is the six and four segment instruction pipeline in computer organization?
4. Explain the six stages of instruction pipelining.
5. How many segments are there in the pipeline?
6. Write in detail about RISC pipeline concept.
7. Explain about Vector Processing with an example.
8. Discus about Array Processors.
***********************************
81
UNIT – III
******************************************************************************
Chapter 5 Microprocessor Architecture and Microcomputer Systems
******************************************************************************
This chapter describes about the Microcomputer Systems that consist of main components such
as Microprocessor, Memory, and I/O (Input / Output). The internal logic design of the
microprocessor, called its architecture. Also, the internal architecture of the 8085
Microprocesssor is discussed.
♦ Microprocessor-initiated operations
♦ Internal data operations
♦ Peripheral (or externally) initiated operations.
82
• To perform these functions, the microprocessor requires a group of logic circuits and a set
of signals called control signals.
• The first microprocessor was the Intel 4004, introduced in 1971. The 4004 was not very powerful.
[Computer's Central Processing Unit (CPU) built on a single Integrated Circuit (IC) is called
a microprocessor.
A digital computer with one microprocessor which acts as a CPU is called microcomputer.]
Applications of Microprocessor
❖ Calculators
❖ Accounting System
❖ Games Machine
❖ Complex Industrial Controllers
❖ Traffic Light
❖ Control Data
❖ Military Applications
❖ Defense Systems
❖ Computation Systems
• All these operations are part of the communication process between the MPU and peripheral
devices (including memory).
• To communicate with a peripheral (or a memory location), the MPU needs to perform the
following steps:
Step 1: Identify the peripheral or the memory location (with its address).
83
Step 3: Provide timing or synchronization signals.
• The 8085/8080A MPU performs these functions using three sets of communication lines called
buses :
• Figure 5.1 shows the 8085 Bus Structure as one group, called the system bus.
• Address Bus:
o The address bus is a group of 16 lines generally identified as A0 to A15.
o The address bus is unidirectional: Bits flow in one direction – from the MPU to peripheral
devices.
o The MPU uses the address bus to perform the first function: identifying a peripheral or a
memory location.
• Data Bus:
o This is a bi-directional bus, because data can flow to or from the CPU.
o The CPU’s eight data pins, D0 through D7, can be either inputs or outputs, depending on
whether the CPU is performing a read or a write operation.
o During data bus by the memory or I/O element. During a write operation the CPU’s data
pins act as outputs and place data on the data bus, which are then sent to the selected
memory or I/O element.
• Control Bus:
o This is the set of signals that is used to synchronize the activities of the separate µC
84
elements.
o Some of these control signals, such as RD and WR are sent by the CPU to the other
elements to tell them what type of operation is currently in progress.
o The I/O elements can send control signals to the CPU.
• Memory Unit:
o Operation of the memory is controlled by the control unit which signals for either a read
or a write operation.
o A given location in memory is accessed by the control unit that provides the appropriate
address code.
o Information can be written into the memory from the ALU or the input unit, again
under control of the control unit.
o Information can be read from memory into the ALU or into the output unit.
• Input Unit:
o The input unit consists of all of the devices used to take information and data that are
external to the computer and put them into the memory unit or the ALU.
o The control unit determines where the input information is sent.
o The input unit is used to enter the program and data into the memory unit or in to the
ALU from an external device during the execution of a program.
o Some of the common input devices are keyboards, Joysticks, mouse, OCR, OMR
etc.
• Output Unit:
o The output unit consists of the devices used to transfer data and information from the
computer to the “outside world.”
o The output devices are directed by the control unit and can receive data from
memory or the ALU.
o Examples of common output devices are printers, disk or tape units, video monitors,
and digital-to-analog converters (DACs).
Registers
o The 8085/8080A has six general - purpose registers to perform the first operation listed
above, that is, to store 8-bit data during a program execution.
o These registers are identified as B, C, E, H, and L.
o They can be combined as register pairs - BC, DE, and HL - to perform some 16-bit
operation.
o These registers are programmable, meaning that a programmer can use them to load or
transfer data from the registers by using instructions.
Accumulator
o The accumulator is an 8-bit register that is part of the arithmetic logic unit (ALU).
o This register is used to store 8-bit data and to perform arithmetic and logical operations.
o The result of an operation is stored in the accumulator.
o The accumulator is also identified as register A.
Flags
o The ALU includes five flip-flops that are set or reset according to data conditions in the
accumulator and other registers.
o The microprocessor uses them to perform the third operation; namely testing for data
conditions.
o The 8085/8080A has five flags to indicate five different types of data conditions. They
86
are called Zero (Z), Carry (CY), Sign (S), Parity (P), and Auxiliary Carry (AC) flags.
o The most commonly used flags are Zero and Carry.
1. What is CPU?
2. What basic operations occur in computer?
3. Name the five basic units of a computer and describe the major functions of each.
4. What is the function of central processing unit?
5. Draw the typical structure of a micro computer and show its bus organization.
**********************************
87
****************************************************************************
Chapter 6 Microprocessor Architecture and Memory Interfacing
****************************************************************************
This chapter deals with the Architecture of 8085 Microprocessor and its Memory Interfacing
concepts. The term microprocessor unit (MPU) is similar to the term central processing unit
(CPU) used in computers.
88
o RD (Read): This is a Read control signal (active low). This signal indicates that
the selected I/O or memory device is to be read and data are available on the
data bus.
o WR (Write): This is a write control signal (active low). This signal indicates
that the data on the data bus are to be written into a selected memory or I/O
location.
o IO/M: This is a status signal used to differentiate between I/O and memory
operations. When it is high, it indicates an I/O operation; when it is low, it
indicates a memory operation.
o S1 and S0: These status signals can identify various operations, nut they are
rarely used in small systems.
• Power Supply and Clock Frequency:
The power supply and frequency signals are as follows:
1. Vcc : +5 V Power supply.
2. Vss : Ground Reference
3. X1, X2 : A crystal is connected at these two pins.
4. CLK (OUT) : This signal can be used as the system clock
forother devices.
• READY (Input):
o If Ready is high during a read or writes cycle, it indicates that the memory or
peripheral is ready to send or receive data.
o If Ready is low, the CPU will wait for Ready to go high before completing the
read or write cycle.
• HOLD (Input):
o HOLD: indicates that another Master is requesting the use of the Address and
Data Buses.
o The CPU, upon receiving the Hold request will relinquish the use of buses as
soon as the completion of the current machine cycle.
o Internal processing can continue. The processor can regain the buses only after
the Hold is removed.
o When the Hold is acknowledged, the Address, Data, RD, WR, and IO/M lines
are 3stated.
89
• HLDA (Output):
o HOLD ACKNOWLEDGE: indicates that the CPU has received the Hold
request and that it will relinquish the buses in the next clock cycle. HLDA goes
low after the Hold request is removed.
o The CPU takes the buses one half clock cycle after HLDA goes low.
• INTR (Input):
o INTERRUPT REQUEST is used as a general purpose interrupt.
o It is sampled only during the next to the last clock cycle of the instruction.
o If it is active, the Program Counter (PC) will be inhibited from
incrementing and an INTA will be issued.
o During this cycle a RESTART or CALL instruction can be inserted to jump to
the interrupt service routine.
o The INTR is enabled and disabled by software. It is disabled by Reset and
immediately after an interrupt is accepted.
• INTA (Output):
o INTERRUPT ACKNOWLEDGE: is used instead of (and has the same timing as) RD
during the Instruction cycle after an INTR is accepted.
• RESTART INTERRUPTS:
o These three inputs have the same timing as INTR except they cause an
internal RESTART to be automatically inserted.
o RST 7.5 Highest Priority
o RST 6.5
o RST 5.5 Lowest Priority
• TRAP (Input):
o Trap interrupt is a non maskable restart interrupt.
o It is recognized at the same time as INTR.
o It is unaffected by any mask or Interrupt Enable.
o It has the highest priority of any interrupt.
• RESET IN (Input):
o Reset sets the Program Counter to zero and resets the Interrupt Enable
and HLDA flip-flops.
o None of the other flags or registers (except the instruction register) are
affected The CPU is held in the reset condition as long as Reset is applied.
o
90
• RESET OUT (Output):
o Indicates CPU is being reset. Can be used as a system RESET.
o The signal is synchronized to the processor clock.
Figure 6.1 Pin Diagram of 8085
• Program Counter: It is a 16-bit register used to store the memory address location of the next
instruction to be executed. Microprocessor increments the program whenever an instruction is
being executed, so that the program counter points to the memory address of the next instruction
that is going to be executed.
• Stack Pinter: It is also a 16-bit register works like stack, which is always incremented /
decremented by 2 during push & pop operations.
• Temporary register: It is an 8-bit register, which holds the temporary data of arithmetic and
logical operations.
• Flag register: Table 6.1 shows the flag register. It is an 8-bit register having five 1-bit flip-flops,
which holds either 0 or 1 depending upon the result stored in the accumulator.
These are the set of 5 flip-flops −
❖ Sign Flag (S): After the execution of an arithmetic or logic operation, if bit D7 of the result
is 1, the sign flag is set.
❖ Zero Flag (Z): The Zero flag is set if the ALU operation results in 0, and the flag is reset if
the result is not 0.
❖ Auxiliary Carry Flag (AC): In an arithmetic operation, when a carry is generated by digit
D3 and passed on to digit D4, the AC flag is set.
❖ Parity Flag (P): After an arithmetic or logical operation, if the result has an even number of
1’s, the flag is set. If it has an odd number of 1’s, the flag is reset.
❖ Carry Flag (CY): If an arithmetic operation results in a carry, the carry, theCarry Flag is set;
otherwise it is reset.
D7 D6 D5 D4 D3 D2 D1 D0
S Z AC P CY
• Instruction register and decoder: It is an 8-bit register. When an instruction is fetched from
memory then it is stored in the Instruction register. Instruction decoder decodes the information
92
present in the Instruction register.
• Timing and control unit: It provides timing and control signal to the microprocessor to
perform operations. Following are the timing and control signals, which control external and
internal circuits −
93
IO Interfacing
• Figure 6.3 shows the Memory Interface diagram. This consists of various communication
devices like keyboard, mouse, printer, etc.
• To interface the keyboard and other devices with the microprocessor, latches and buffers are
used.
• This type of interfacing is known as I/O interfacing.
2. Arithmetic Instructions
3. Logical Instructions
4. Branch Instructions
5. Control Instructions
• These instructions move data between registers, or between memory and registers.
94
• These instructions copy data from source to destination.
• While copying, the contents of the source are not modified.
Arithmetic Instructions
▪ Addition
▪ Subtraction
▪ Increment
▪ Decrement
Addition
• Any 8-bit number or the contents of register, or the contents of memory location can be
added to the contents of accumulator.
• The result (sum) is stored in the accumulator.
• No two 8-bit registers can be added directly.
Subtraction
• Any 8-bit number or the contents of register, or the contents of memory location can be
subtracted from the contents of accumulator.
• The result is stored in the accumulator.
• Subtraction is performed in 2’s complement form.
• If the result is negative, it is stored in 2’s complement form.
• No two other 8-bit registers can be subtracted directly.
Increment / Decrement
Logical Instructions
❖ These instructions perform logical operations on data stored in registers, memory and
status flags.
❖ The logical operations are:
• AND
• OR
• XOR
95
• Rotate
• Compare
• Complement
• Any 8-bit data, or the contents of register, ot memory location can logically have
• AND operation
• OR operation
• XOR operation
Rotate
• Each bit in the accumulator can be shifted either left or right to the next position.
Compare
• Any 8-bit data or the contents of register or memory location can be compared for:
• Equality
• Greater Than
• Less Than
Complement
Branching Instructions
Control Instructions
96
EXERCISES:
1. What is bus?
2. What is the function of the accumulator?
3. What is a flag? What are its types?
4. Specify the four control signals commonly used by the 8085 MPU.
5. Explain about 8085 MPU Architecture with neat diagram.
6. Discuss about 8085 MPU pin concept with neat diagram.
7. Explain in detail about memory interface.
8. Explain about 8085 MPU instruction set.
97
******************************************************************************
Chapter 7 Programming in 8085: Code Conversion
******************************************************************************
In microcomputer applications, various number systems and codes are used to input data or to
display results. In the microprocessor, Data Processing is usually performed in binary. This
Chapter discusses about the various programming techniques used in the 8085 Microprocessor.
Code Conversion allows the user to translate a number that is represented using one coding
system to other coding system.
The code conversion involves operations like:
1) BCD to Binary
2) Binary to BCD
3) ASCII to BCD
4) BCD to ASCII
5) Binary to ASCII
6) ASCII to Binary
Algorithm:
1. Load the BCD number into the accumulator
2. Move the accumulator value into the B register.
3. Obtain BCD2 by ANDing the accumulator with 0FH and store it in C
98
4. Restore the original value of the accumulator by moving the value in B to A. AND the
accumulator with F0H
5. If the value in the accumulator equals 0, then BCD 2 is the final answer and store it in the
memory location, 2020H (arbitrary)
6. Else, shift the accumulator to right 4 times to obtain BCD 1. Next step is to multiply
BCD1 by 0AH
7. Multiplication: Move BCD1 to D and initialize E with 0AH as the counter. Clear the
accumulator to 0 and add D to it E number of times
8. Finally, add C to the accumulator and store the result in 2020H
ADDRESS LABEL MNEMONIC
2000H LDA 201FH
2001H
2002H
2003H MOV B, A
2004H ANI 0FH
2005H
2006H MOV C, A
2007H MOV A, B
2008H ANI F0H
2009H
200AH JZ LOOP1
200BH
200CH
200DH RRC
200EH RRC
200FH RRC
2010H RRC
2011H MOV D, A
2012H XRA A
2013H MVI E, 0AH
2014H
2015H LOOP2 ADD D
2016H DCR E
2017H JNZ LOOP2
2018H
2019H
201AH LOOP1 ADD C
201BH STA 2020H
99
201CH
201DH
201EH HLT
Input:
Address Data
201F 72
Output:
Address Data
2020 48
Address Data
8000 34
Output:
Address Data
8050 52
100
7.3 ASCII to BCD Conversion
Write an Assembl
ALGORITHM:
STEP 1 : Start.
STEP 2: Take the ASCII number in accumulator.
STEP 3: Subtract NUMBER from the accumulator.
STEP 4: Store the BCD result in memory
STEP 5: End.
PROGRAM:
ADDRESS OPCODE MNEMONICS COMMENTS
4000 3A,50,40 LDA 4050H Take the ASCII number in accumulator
Subtract the number 30 from the
4003 D6,30 SUI 30H
accumulator.
4005 32, 51, 40 STA 4051H Store the Binary result in memory
4008 76 HLT End of program
Input:
Address Data
4050 39
Output:
Address Data
4051 09
Write an assembly language program to convert 8 bit BCD number to its respective ACSII Code.
Algorithm:
101
Program
Address Mnemonics Comments
2000 LDA 2050 Load the content of memory location 2050 to accumulator
2003 MOV B, A Copy the content of accumulator to register B
2004 ANI 0F AND the content of accumulator with immediate data 0F
2006 ADI 30 ADD 30 to accumulator
2008 STA 3050 Store the content of accumulator to memory location 3050
200B MOV A, B Copy the content of register B to accumulator
200C ANI F0 AND the content of accumulator with immediate data F0
200E RLC Rotate the content of accumulator left without carry
200F RLC Rotate the content of accumulator left without carry
2010 RLC Rotate the content of accumulator left without carry
2011 RLC Rotate the content of accumulator left without carry
2012 ADI 30 ADD 30 to accumulator
2014 STA 3051 Store the content of accumulator to memory location 3051
2017 HLT Stop the Execution
Input:
Address Data
2050 98
Output:
Address Data
3050 38
3051 39
Address Data
4050 0A
Output:
Address Data
4051 41
Test Data:
Steps:
2. If the ASCII number is less than 3AH then 30H is subtracted from the number to get its Binary
equivalent.
3. If the number is between 41H and 5AH then 37H is subtracted to get the Binary equivalent of the
letter A-F.
Example:
41 H (ASCII) = 41 H – 37 H
= 04 H (BINARY)
Program:
103
400E 40
400F 76 HLT Halt the execution
TEST DATA:
INPUT:
4050: 42H
OUTPUT:
4051: 0BH
EXERCISES:
3. Write the steps for conversion process of ASCII to Binary and Binary to ASCII.
4. Write an assembly language program to convert Binary to ASCII.
5. Write an assembly language program to convert ASCII to Binary
104
UNIT – IV
******************************************************************************
Chapter 8 Programming in 8085: BCD Arithmetic
******************************************************************************
In microcomputer applications, various number systems and codes are used to input data or to
display results. The ASCII (American Standard Code for Information Interchange) keyboard is
a commonly systems. However, in this chapter includes arithmetic operations that are
performed in BCD numbers.
8.1 BCD Addition:
• In some application, input/output data are presented in decimal numbers.
• The addition of two BCD numbers may not represent an appropriate BCD value.
Example: The addition of BCD (34, 26) results is 5AH.
3410 = 0 0 1 1 0 1 0 0 BCD
2610 = 0 0 1 0 0 1 1 0 BCD
=
6010 0 1 0 1 1 0 1 0 → 5A (Result)
• Table 8.1(b) shows the illustrative program for Addition of two BCD numbers.
Table 8.1(b) Program for 8-bit Addition of BCD Numbers
Multibyte Addition:
Address 8500 8501 8502 8503 8504 8505 8506 8507 8508
Data 04 19 68 12 85 88 25 17 20
107
F017 JNZ LOOP When bytes are not considered, loop
C2,0F,F0
again
F01A JNC SKIP When carry = 0, jump to store
D2,21,F0
F024 F1 L1 POP PSW Pop AF to get back bytes from the stack
Store Acc data at the memory location
F025 77 MOV M, A
pointed by HL
108
Table 8.3(c) Output of Multibyte Addition
Address 8500 8501 8502 8503 8504 8505 8506 8507 8508
Data 04 19 68 12 85 88 25 17 20
Multibyte Subtraction:
• The numbers are stored into memory, and one additional information is stored and the byte
count of the multi-byte BCD number.
• This program uses 3-byte BCD numbers for multibyte subtraction.
• Numbers are stored at location 8001H to 8003H, and another number is stored at location8004H
to 8006H.
• The location 8000H is holding the byte count. In this case the byte count is 03H.
• For the subtraction, using the 10’s complement method for subtraction.
• In this case the numbers are: 672173 – 275188 = 376985
• Table 8.3(d) (e) (f) shows the Input, Program, and Output of the Multibyte Subtraction.
109
F012 27 DAA Decimal adjust
110
Table 8.4(b) Program for BCD Multiplication
111
Division:
• The 8085 has no division operation. To get the result of the division, we should use the repetitive
subtraction method.
• By using this program, we will get the quotient and the remainder.
• 8020H will hold the quotient, and 8021H will hold the remainder.
• The table 8.4(d) (e) (f) shows the Input, Program, and Output of Division.
112
Table 8.4(e) 8085 Division Program
EXERCISE:
1. Define the term BCD.
2. Illustrate the program for addition of two BCD numbers.
3. Write the steps and program to calculate the BCD subtraction.
4. Describe about Multibyte Addition with a simple program.
5. Explain about BCD Multiplication with an example.
6. What are the steps followed to calculate the BCD division.
113
******************************************************************************
Chapter 9 Interrupts
******************************************************************************
An interrupt I/O is a process of data transfer whereby an external device or a peripheral can
inform the processor that it is ready for communication and it requests attention. The process is
initiated by an external device and is asynchronous, meaning that it can be initiated at any time
without reference to the system clock. However, the response to an interrupt request is directed
or controlled by the microprocessor.
This chapter includes a brief explanation of the interrupt requests that are classified in two
categories: Maskable and Non-Maskable. The 8085 microprocessor includes four maskable and
one Non-maskable interrupt. The interrupts in 8085 microprocessor and vector interrupts are also
described later in the chapter.
When microprocessor receives any interrupt signal from peripheral(s) which are requesting its
services, it stops its current execution and program control is transferred to a sub-routine by
generating CALL signal and after executing sub-routine by generating RET signal again
program control is transferred to main program from where it had stopped.
114
3. Non-Vectored Interrupts
➢ In this vector address is not predefined and the interrupting device gives the address
of sub-routine for these interrupts.
➢ INTR is the only non-vectored interrupt in 8085 microprocessor.
Step 2:
❖ When the microprocessor is executing a program, it checks the INTR line during the
execution of each instruction.
115
Step 3:
❖ If the line INTR is high and the interrupt is enabled, the microprocessor completes
thecurrent instruction.
❖ It disables the Interrupt Enable flip-flop and sends a signal called INTA (Interrupt
Acknowledge (active low)).
❖ This processor cannot accept any interrupt requests until the interrupt flip-flop is enabled
again.
Step 4:
❖ The signal INTA is used to insert a restart (RST) instruction or CALL instruction through
external hardware.
❖ The RST instruction is a 1-byte call instruction that transfers the program control to a
specific memory location.
Step 5:
❖ When the microprocessor receives an RST instruction or CALL instruction, it saves the
memory address of the next instruction on the stack.
❖ The program is transferred to the CALL location.
Step 6:
❖ The task to be performed is written as a subroutine at the specified location, the
processor performs the task.
❖ This subroutine is known as a service routine.
Step 7:
❖ The service routine should include the instruction EI to enable the interrupt again.
Step 8:
❖ At the end of the subroutine, the RET instruction retrieves the memory address where
the program was interrupted and continues the execution.
116
Figure 9.1(a) Multiple Interrupt and Priorities
• The schematic in Figure 9.1(b) implements multiple interrupting devices using an 8-to-3
priority encoder that determines the priorities among interrupting devices.
• The encoder provides appropriate combinations on its output lines A0, A1, and A2, which
are connected to data lines D3, D4, and D5 through a tri-state buffer.
• The eight inputs to the encoder are connected to eight different interrupting devices.
• When an interrupting device requests service, one of the input lines goes low; this makes
line E0 high and interrupts the microprocessor.
• When the interrupt is acknowledged and the signal INTA enables the tri-state buffer, the
code corresponding to the input is placed on lines D5, D4, and D3.
117
locations on memory.
• They do not require the INTA signal or an input port; the necessary hardware is already
implemented inside the 8085. The Table 9.2(a) shows the Vectored Interrupt with address.
Table 9.2(a) Vectored Interrupt
• The TRAP has the highest priority, followed by RST 7.5, 6.5, 5.5, and INTR, in that
order.
• The TRAP has a lower priority than the hold signal used for DMA( will discuss next
chapter).
TRAP
• TRAP, a nonmaskable interrupt known as NMI, is analogous to the smoke detector
described earlier.
• It has the highest priority among the interrupt signals, it need not be enabled and it cannot
be disabled.
118
• It is level and edge sensitive, meaning that the input should go high and stay high to be
acknowledged.
• It cannot be acknowledged again until it makes a transition from high to low to high.
• TRAP is generally used for critical events as power failure and emergency shut-off.
• This is a 1-byte instruction and can be used for three different functions.
• One function is to set mask for RST 7.5, 6.5, and 5.5 interrupts.
• This instruction reads the content of the accumulator and enables or disables the
interrupts according to the content of the accumulator.
• Bit D3 is a control bit and should=1for bits D0, D1, and D2 to the effective.
• Logic 0 on D0, D1, and D2 will enable the corresponding interrupts, and logic 1 will
disable the interrupts.
119
• If D4 =1, RST 7.5 is reset.
• Bit D7 and D6 of the accumulator are used for serial I/O abd do not affect the
interrupts. Bit D6=1 enables the serial I/O and bit D7 is used to transmit(output) bits.
EXERCISE
1. Define an Interrupt.
2. Explain the 8085 interrupt service execution in detail.
3. Describe about interrupts Classification categories based on different parameters.
4. Explain about Hardware and Software interrupts in 8085.
5. What is meant by Maskable and Non-masable interrupts in 8085?
6. Explain about 8085 vector Interrupt with neat diagram.
7. What is the use of TRAP interrupt signal?
8. What is the use of RST 7.5, 6.5, 5.5 interrupts?
9. What is meant by SIM?
120
UNIT – V
****************************************************************
Chapter 10 DMA
****************************************************************
This chapter describes about Direct Memory Access (DMA) and its working
principle. This chapter discusses DMA Controller and several programmable
devices from the Intel: The 8257 DMA controller and 8255A Peripheral Interface.
The 8255A is the widely used general-purpose programmable devices, can be compatible
with any microprocessor. It includes three programmable ports, one of which can be used
for bidirectional data transfer. Later part of this chapter describes about the topics Basic
features of Advanced Microprocessors and Pentium – I3, I5, and I7.
121
• When microprocessor receipt of such request, the microprocessor
relinquishes theaddress and data buses.
• And informs the I/O devices of the situation by sending Acknowledge signal HLDA.
• The I/O device withdraws the request when the data transfer between the
I/O device andexternal memory will complete.
Figure 10.1(a) DMA Data Transfer
• This process is called switching from the slave mode to master mode.
• The DMA transfers the data in three modes which include the following.
a) Burst Mode: In this mode DMA handover the buses to CPU only after
completion of whole data transfer. Meanwhile, if the CPU requires the
bus it has to stay ideal and wait for data transfer.
b) Cycle Stealing Mode: In this mode, DMA gives control of buses to
122
CPU after transfer of every byte. It continuously issues a request for
bus control, makes the transfer of one byte and returns the bus. By this
CPU doesn’t have to wait for a long time if it needs a bus for higher
priority task.
c) Transparent Mode: Here, DMA transfers data only when CPU is
executing theinstruction which does not require the use of buses.
10.2 8257 DMA Controller
Features of 8257
8257 Architecture
123
8257 Pin Description
The following image shows the pin diagram of a 8257 DMA controller −
DRQ0−DRQ3
These are the four individual channel DMA request inputs, which are used by the peripheral devices
for using DMA services. When the fixed priority mode is selected, then DRQ0 has the highest
priority and DRQ3 has the lowest priority among them.
124
DACKo − DACK3
These are the active-low DMA acknowledge lines, which updates the requesting peripheral about
the status of their request by the CPU. These lines can also act as strobe lines for the requesting
devices.
Do − D7
These are bidirectional, data lines which are used to interface the system bus with the internal data
bus of DMA controller. In the Slave mode, it carries command words to 8257 and status word from
8257. In the master mode, these lines are used to send higher byte of the generated address to the
latch. This address is further latched using ADSTB signal.
IOR
It is an active-low bidirectional tri-state input line, which is used by the CPU to read internal
registers of 8257 in the Slave mode. In the master mode, it is used to read data from the peripheral
devices during a memory write cycle.
IOW
It is an active low bi-direction tri-state line, which is used to load the contents of the data bus to the
8-bit mode register or upper/lower byte of a 16-bit DMA address register or terminal count register.
In the master mode, it is used to load the data to the peripheral devices during DMA memory read
cycle.
CLK
It is a clock frequency signal which is required for the internal operation of 8257.
RESET
This signal is used to RESET the DMA controller by disabling all the DMA channels.
Ao - A3
These are the four least significant address lines. In the slave mode, they act as an input, which
selects one of the registers to be read or written. In the master mode, they are the four least
significant memory address output lines generated by 8257.
CS
It is an active-low chip select line. In the Slave mode, it enables the read/write operations to/from
8257. In the master mode, it disables the read/write operations to/from 8257.
A4 - A7
These are the higher nibble of the lower byte address generated by DMA in the master mode.
READY
125
It is an active-high asynchronous input signal, which makes DMA ready by inserting wait states.
HRQ
This signal is used to receive the hold request signal from the output device. In the slave mode, it is
connected with a DRQ input line 8257. In Master mode, it is connected with HOLD input of the
CPU.
HLDA
It is the hold acknowledgement signal which indicates the DMA controller that the bus has been
granted to the requesting peripheral by the CPU when it is set to 1.
MEMR
It is the low memory read signal, which is used to read the data from the addressed memory
locations during DMA read cycles.
MEMW
It is the active-low three state signal which is used to write the data to the addressed memory
location during DMA write operation.
ADST
This signal is used to convert the higher byte of the memory address generated by the DMA
controller into the latches.
AEN
TC
It stands for ‘Terminal Count’, which indicates the present DMA cycle to the present peripheral
devices.
MARK
The mark will be activated after each 128 cycles or integral multiples of it from the beginning. It
indicates the current DMA cycle is the 128th cycle since the previous MARK output to the selected
peripheral device.
Vcc
It is the power signal which is required for the operation of the circuit.
126
10.3 8255A Programmable Peripheral Interface
• The 8255A is a widely used, programmable, parallel I/O device.
• It can be programmed to transfer data under various conditions, from
simple I/O tointerrupt I/O.
• It is flexible and economical, but complex.
• As shown in the figure 10.3(a) The 8255A has 24 I/O pins that can be
grouped primarilyin two 8-bit parallel ports:
o Port A and Port B
• The remaining eight bits as port C.
• eight bits of port C can be used as individual bits or grouped in two 4-bits ports:
o CUPPER (CU)
o CLOWER(CL(b) 8255A Modes
127
Operating Modes
• Mode 0 − In this mode, Port A and B is used as two 8-bit ports and Port C as two 4-bit
ports. Each port can be programmed in either input mode or output mode where outputs
are latched and inputs are not latched. Ports do not have interrupt capability.
• Mode 1 − In this mode, Port A and B is used as 8-bit I/O ports. They can be configured
as either input or output ports. Each port uses three lines from port C as handshake
signals. Inputs and outputs are latched.
• Mode 2 − In this mode, Port A can be configured as the bidirectional port and Port B
either in Mode 0 or Mode 1. Port A uses five signals from Port C as handshake signals
for data transfer. The remaining three signals from Port C can be used either as simple
I/O or as handshake for port B.
8255 Architecture
Figure 10.3(c) shows the architecture of 8255A
128
Data Bus Buffer
It is a tri-state 8-bit buffer, which is used to interface the microprocessor to the system data bus.
Data is transmitted or received by the buffer as per the instructions by the CPU. Control words
and status information is also transferred using this bus.
It stands for Chip Select. A LOW on this input selects the chip and enables the communication
between the 8255A and the CPU. It is connected to the decoded address, and A0 & A1 are
connected to the microprocessor address lines. Table 10.3(a) shows the result depends on
conditions.
CS A1 A0 Result
0 0 0 PORT A
0 0 1 PORT B
0 1 0 PORT C
0 1 1 Control Register
1 X X No Selection
129
Write (WR)
It stands for write. This control signal enables the write operation. When this signal goes low,
the microprocessor writes into a selected I/O port or control register.
RESET
This is an active high signal. It clears the control register and sets all ports in the input mode.
Read (RD)
It stands for Read. This control signal enables the Read operation. When the signal is low, the
microprocessor reads the data from the selected I/O port of the 8255.
A0 and A1
These input signals work with RD, WR, and one of the control signal. Following is the table
10.3(b) showing their various signals with their result.
A1 A0 RD WR CS Result
Input Operation
0 0 0 1 0
PORT A → Data Bus
Output Operation
0 0 1 0 0
Data Bus → PORT A
130
Basic Features of Advanced Microprocessors
Intel 80186
• Features
• Clock Generator.
• Independent DMA Channels.
• Programmable Interrupt Controller.
• Programmable 16-bit Timers.
• Programmable Memory and Peripheral Chip-Select Logic.
• Available in 10 MHz and 8 MHz Versions.
o Direct Addressing Capability to 1 Mbyte of Memory and
64 Kbyte I/O.
• Following figure 10.4(a) shows the Architecture Diagram of 80186.
• Intel 80286
131
• Various versions of 80286 are available that runs on 12.5 MHz , 10 MHz
and8 MHz clock frequencies.
• Like the 80186, the 80286 doesn’t incorporate internal peripherals; instead
it contains a memory management unit (MMU).
• The 80286 operates in both the real and protected modes
• In the real mode, the 80286 addresses a 1MByte memory address space and is
virtually identical to 8086.
• In the protected mode, the 80286 addresses a 16MByte memory space.
• Address Unit: The address unit is responsible for calculating the physical
address of instructions and data that the CPU wants to access.
• Bus Unit: Major function of the bus unit is to fetch instruction bytes
from the memory. Instructions are fetched in advance and stored in
a queue to enable faster execution of the instructions.
• Instruction Unit: The instruction unit (IU) accepts instructions from
the prefetch queue and an instruction decoder decodes them one by
one.
• Execution Unit: The execution unit (EU) is responsible for
executing the instructions received from decoded instruction
queue. The decoded instruction queue sends the data part of the
instruction over the data bus.
• Intel 80386
• Features
• 32-bit general and offset registers.
• 16-byte prefetch queue.
• Memory Management Unit with a Segmentation Unit and a Paging Unit.
• 32-bit Address and Data Bus.
• 4-Gbyte Physical address space.
• 64-Tbyte virtual address space.
• Implementation of real, protected and virtual 8086 modes.
• Intel 80486
• Features
132
• Improved 80386 CPU (6 extra instructions)
• Hard-wired implementation of frequently used instructions (as in RISCs)
• A 5 stage instruction pipeline
• An 8K Cache Memory + cache controller (previously a separate device)
• An on-chip Floating Point coprocessor Longer Prefetch Queue (32-bytes as opposed to
16 on the 80386)
• Higher frequency operation
• About a million transistors
• Like the 80386 it uses real, protected and virtual 8086
modes and its Memory Management Unit include a
Segmentation Unit and a PagingUnit.
• The Pentium Processors
• Pentium II
• Pentium II is also a 32-bit processor with 64-bit data bus and 36-bit address
bus to address up to 64GB of physical memory space. It is actually a Pentium
pro processor with on-chip MMX (Multi Media Extension).
• The features of Pentium II processor are;
133
• Integrated 256kb second level (L2) cache.
• Fully compatible with previous microprocessors.
134
16
80286 1982 16 Bit 6 MHZ 16 bits 24 Bit
MB
16
80386 1985 32 Bit 32 bits 32 Bit 4 GB
MHZ
25
80486 1989 32 Bit 32 bits 32 Bit 4 GB
MHZ
60 32 bits, 64
Pentium 1993 32 Bit 32 Bit 4 GB
MHZ bit bus
32 bits,
233 64
PentiumII 1997 32 Bit 32 Bit
MHZ GB
64 bit bus
450 32 bits , 64 64
PeniumIII 1999 32 Bit 32 Bit
MHZ bit bus GB
1.5 32 bits, 64
PentiumIV 2000 32 Bit 32 Bit 64
GHZ bit bus GB
10.5 Pentium – I3, I5, and I7
• Intel launched its Pentium processor in 1993. It was a combination of two processors on a
single chip with 3.1 million transistors. Pentium does not support HD video technology and
gaming technologies. It also lacks multitasking support. Pentium processor is a low- end
version of core processors.
• Intel developed and manufactured dual-core i3 processors. It is the first processor in the i-
series.
• Pentium and Core processors both do the work according to their capacity. Both are designed
for modern computer systems.
• Intel's current core processors are divided into three ranges; Intel Core i3, Intel Core i5and
Intel Core i7. Their relative levels of processing power are based on a collection of criteria
involving their Number of cores, clock speed (in GHz), size of cache, Turbo Boost and
Hyper-Threading.
• Number of cores:
• A core is usually the basic computation unit of the CPU which is describe in thetable
10.5(a). It receives instructions and performs calculations, or actions, basedon those
instructions.
• A processor with two cores is called a dual-core processor and four cores iscalled a quad-
core processor.
• For example, an i5 4690k has 4 cores.
135
Clock speed:
The clock speed is the most common way to measure a CPU's speed. The CPU requiresa fixed
number of clock cycles, to execute each instruction. In the table 10.5(b) shows the clock speed of the
core i3, i5, and i7. The CPU speed determines how many calculations it can perform in one second of
time.
The components like RAM, hard drive, motherboard, and the number of processor cores (e.g., dual
core or quad core) are also have to upgrade for improve the computer speed.
Table 10.5 (b) Clock Speed of Cores in i3, i5, and i7
Hyper-Threading:
The table 10.5(c) shows the Hyper Threading technology in i3, i5, and i7.Intel's implementation of
Simultaneous Multi-Threading is known as Hyper-Threading Technology. It's available on Core i7
and Core i3 but not on the mid-range core i5.
Hyper-Threading Technology uses processor resources more efficiently, enabling multiple threads to
run on each core.
Table 10.5(c) Hyper-Threading Technology
Turbo Boost
Table 10.5(d) describes about Turbo boost, which monitors the present processor usage to
determine how close the processor is to the maximum thermal design power.
When the total number of cores is being used, the processor can turn off the unused cores and
increase the clock speed on the rest of the cores. This is like dynamic over clocking, when the
system demands.
For example, by default the processor runs at 2.3 GHz, and when under heavy load, it will
automatically speed up the cores up to 3.3 GHz. Turbo boost is present in most modern Intel
processors (not in i3). Turbo boost is used to save battery and enhance usage based performance.
136
Cache memory
A cache is a smaller, faster memory, closer to a processor core, which stores copies of the data
from frequently used main memory locations.
They were built in to decrease the time taken to access data by the processor. This time taken
is called latency.
EXERCISES:
REFERENCE BOOKS:
137
PRACTICAL - II COMPUTER ORGANIZATION LAB
I YEAR / II SEM
OBJECTIVES:
• To understand the programming features and operations of assembly language programs using
8085 microprocessor kit or Simulator
OUTCOMES:
LIST OF EXERCISES:
1. 8 - bit addition
2. 16 - bit addition
3. 8 - bit subtraction
4. BCD subtraction
l . 8 - bit multiplication
2. BCD multiplication
3. 8 - bit division
V: Applications
138
I: ADDITION AND SUBTRACTION
1. 8-BIT ADDITION
AIM:
TEST DATA:
INPUT:
4051:09 H (Augend)
4052:04 H (Addend)
OUTPUT:
4053:0D H
RESULT:
Thus, the assembly language program to add two 8-bit numbers has been executed
successfully.
139
16-BIT ADDITION
AIM:
To write an Assembly Language Program to add two 16 bit hexadecimal numbers and
store the sum in 16 bits.
ALGORITHM:
STEP 1: Start.
STEP 2: Load the first 16-bit number from memory to H-L register pair.
STEP 3: Exchange the contents of H-L register pair with D-E register pair.
STEP 4: Load the second 16-bit number from memory to H-L register pair.
STEP 5: Add the two 16-bit numbers using DAD D instruction.
STEP 6: Store the 16-bit result in two consecutive memory locations.
STEP 7 : End.
PROGRAM:
Load the H-L register pair with the first 16-bit number
4000 2A LHLD 4050 H
from memory
4001 50
4002 40
Exchange the contents of H-L register pair with D-E
4003 EB XCHG
register pair
Load the H-L register with the second 16-bit number from
4004 2A LHLD 4051 H
memory
4005 51
4006 40
4007 19 DAD D Add the contents of H-L and D-E register pairs
4008 22 SHLD 4052 H Store the 16-bit result in H-L register pair in the memory
4009 52
400A 40
400B 76 HLT End of program
140
TEST DATA:
INPUT:
4050:34
4051:12
4052: CD
4053: AB
OUTPUT:
4054:01
4055: BE
RESULT:
Thus, the assembly language program to perform 16-bit addition has been executed
successfully.
141
3. 8-BIT SUBTRACTION
AIM:
To write an Assembly Language Program to subtract two 8-bit hexadecimal numbers and
store the result in memory.
ALGORITHM:
STEP 1: Start.
STEP 2: Load the accumulator with first number in memory address 4051.
STEP 3: Move the content of accumulator to B register.
STEP 4: Load the accumulator with second number in memory address 4052.
STEP 5: Subtract the first number from the second number.
STEP 6: Store the difference in the memory.
STEP 7: End.
PROGRAM:
Thus, the assembly language program to subtract two 8-bit numbers has been executed
successfully.
142
4. BCD SUBTRACTION
AIM:
ALGORITHM:
STEP 1 : Start.
STEP 2 : Load the minuend value in memory address 4050 to accumulator.
STEP 3 : Move the value of A to B.
STEP 4 : Load the subtrahend value in memory address 4051 to accumulator.
STEP 5 : Move the value of A to C.
STEP 6 : Move immediately the value 99 to A.
STEP 7 : Subtract the value of C from A.
STEP 8 : Increment the A register by one.
STEP 9 : Add B with A value.
STEP 10: Using DAA, convert the number in accumulator to decimal (BCD).
STEP 11: Store the result in memory address 4052.
STEP 12: End.
PROGRAM
143
TEST DATA:
INPUT:
4050:85
4051:39
OUTPUT:
4052:46
RESULT:
Thus, the assembly language program to perform the BCD subtraction has been
executed successfully.
144
II: MULTIPLICATION AND DIVISION
1. 8-BIT MULTIPLICATION
AIM:
ALGORITHM:
STEP 1 : Start.
STEP 2 : Load the accumulator with value in memory address 4050.
STEP 3 : Move the value of A to B register.
STEP 4 : Load the accumulator with value in memory address 4051.
STEP 5 : Move the value of A to C register.
STEP 6 : Initialize accumulator to zero.
STEP 7 : Clear the D register for storing the carry.
STEP 8 : Add the content of C with A.
STEP 9 : If the value in accumulator exceeds FFH, increment D register by one.
STEP 10 : Decrement the B register by one.
STEP 11 : If the value in B register is not equal to zero, then go to STEP 8.
STEP 12 : If the value in B register becomes zero, store the lower byte of the product in
memory address 4052.
STEP 13 : Store the higher byte of the product in memory address 4053.
STEP 14 : End.
PROGRAM:
145
4110 C2 JNZ L1 If the value in B register is not equal to zero, then
jump to the location named L1
4111 0A
4112 41
4113 32 STA 4052 Store the product in memory
4114 52
4115 40
4116 7A MOV A,D Transfer the higher byte to accumulator
4117 32 STA 4053
4118 53
4119 40
4120 76 HLT End of program
TEST DATA:
INPUT:
4050:3 (Multiplier)
4051:10 (Multiplicand)
OUTPUT:
4052:30
RESULT:
Thus, the assembly language program to multiply two 8-bit numbers has been executed
successfully.
146
2. BCD MULTIPLICATION
AIM:
ALGORITHM:
STEP 1 : Start.
STEP 2 : Take the multiplicand in accumulator from memory.
STEP 3 : Transfer the multiplicand to B register.
STEP 4 : Take the multiplier in accumulator from memory.
STEP 5 : Transfer it to C register.
STEP 6 : Clear the accumulator
STEP 7 : Add the content of B register with that of the accumulator.
STEP 8 : Use DAA to convert the number in accumulator to decimal and save it in D.
STEP 9 : Decrement the decimal count in C register by one.
STEP 10 : If C is not zero, go to STEP 7.
STEP 11 : Store the BCD product in memory.
STEP 12 : End.
PROGRAM:
4102 50
4103 40
4103 47 MOV B,A Transfer the multiplicand to B register
4105 51
4106 40
4107 4F MOV C,A Transfer the multiplier to C register
147
410F 27 DAA Convert it into decimal
4117 40
4118 76 HLT End of program
TEST DATA:
INPUT:
4050: 08
4051: 12
OUTPUT:
4052: 96
RESULT:
Thus, the assembly language program to perform BCD multiplication has been executed
successfully.
148
3. 8-BIT DIVISION
AIM:
To write an Assembly Language Program to divide one 8 bit number by another 8 bit
number.
ALGORITHM:
STEP 1 : Start.
STEP 2 : Load the accumulator with value in memory address 4050.
STEP 3 : Move the value of A to B register.
STEP 4 : Load the accumulator with value in memory address 4051.
STEP 5 : Move FFH to C register.
STEP 6 : Increment the C register by one.
STEP 7 : Subtract the B value from A.
STEP 8 : Check for carry. If there is no carry, then go to step 6.
STEP 9 : Add the content of B with the accumulator.
STEP 10 : Store the remainder in memory location 4053.
STEP 11 : Move the value of C to A.
STEP 12 : Store the quotient in memory address 4052.
STEP 13 : End.
PROGRAM:
4101 50
4102 40
4103 47 MOV B, A Transfer the divisor to B register
4105 51
4106 40
4107 0E MVI C, FF Initialize C register to -1
4108 FF
4109 0C L1 INR C Increment C register content by one
149
410C 09
410D 41
Add the contents of A and B to get the
410E 80 ADD B remainder
4110 53
4111 40
Transfer the quotient in C register to
4112 79 MOV A,C accumulator
4114 52
4115 40
4116 76 HLT End of program
TEST DATA:
INPUT:
4050: 03 (Divisor)
4051: 0F (Dividend)
OUTPUT:
4052: 05 (Quotient)
4053: 00 (Remainder)
RESULT:
Thus, the assembly language program to perform 8-bit division has been executed
successfully.
150
III: SORTING AND SEARCHING
AIM:
To write an Assembly Language Program to search the given element from an array..
ALGORITHM:
STEP 1 : Start.
STEP 2 : Move 00 to D register.
STEP 3 : Load the accumulator with value in memory address 8000.
STEP 4 : Move the content of M to A.
STEP 5 : Increment the H register by one.
STEP 6 : Move the content of M to C.
STEP 7 : Load the accumulator with value in memory address 9000.
STEP 8 : Compare M with A.
STEP 9 : If the element is found, go for storing the element and the address of the
Memory where it is stored
STEP 10: Increment the H register by one.
STEP 11: Decrement the C register by one.
STEP 12: If the count is not zero, then go to STEP 8.
STEP 13: Load 01 in D register.
STEP 14: Move the content of D to A.
STEP 15: Store the element in memory.
STEP 16: End.
PROGRAM:
151
400F 40
Store FF in memory to indicate the search is
4100 3E MVI A, FF not a success
4101 FF
4102 32 STA 4060
4103 60
4104 40
4105 C3 JMP EXIT
4106 14
4107 41
4108 32 L1 STA 4060 Store the element in memory
4109 60
4110 40
Store the address of the memory where the
4111 22 SHLD 4061
element is present
4112 61
4113 40
4114 76 EXIT HLT End of program
TEST DATA:
INPUT:
4050: 09
4051: 05
4052: EE
4053: 32
OUTPUT:
4060: EE (DATA FOUND)
4060: FF (DATA NOT FOUND)
RESULT:
Thus, the assembly language program to search the given element from an array has
been executed successfully.
152
2. SORTING IN ASCENDING ORDER
AIM:
ALGORITHM:
STEP 1 : Start.
STEP 2 : Load size of list in C register and set D register.
STEP 3 : Copy the count in D register.
STEP 4 : Initialize H-L register pair with the memory address 4050.
STEP 5 : Move first data from M to A.
STEP 6 : Increment memory address in H-L.
STEP 7 : Move the second data from M to B register.
STEP 8 : Compare the data in A register with the data in B register
STEP 9 : If carry flag is set, Jump to L1 loop
STEP 10: Else, ‘swap’ the data stored in memory
STEP 11: Decrement C in register D by 1
STEP 12: If count in D register is not zero, jump L2.
STEP 13: Decrement the count in C register by one.
STEP 14: If count in C register is not zero, jump L3.
STEP 13: End.
PROGRAM:
153
TEST DATA:
INPUT:
4050: 05
4051: 03
4052: 07
4053: 09
4054: 04
4055: 01
4056:06
4057:08
4058:0A
4059:02
OUTPUT:
4050: 01
4051: 02
4052: 03
4053: 04
4054: 05
4055: 06
4056:07
4057:08
4058:09
4059:0A
RESULT:
Thus, the assembly language program to sort the array elements in ascending order
has been executed successfully.
154
3. FINDING LARGEST ELEMENTS FROM AN ARRAY
AIM:
To write an Assembly Language Program to find the largest element of an array.
ALGORITHM:
STEP 1 : Start
STEP 2 : Initialize H-L register pair with memory address 4050
STEP 3 : Load C register with required count
STEP 4 : Move the size of the array from M to A register
STEP 5 : Increment the memory address in H-L register pair
STEP 6 : Move the data from memory to B register
STEP 7 : Compare the data
STEP 8 : If data in A is smaller then leave the smaller number in its position and jump to L1
STEP 9 : Move the content from memory to accumulator
STEP 10 : Decrement the content of H-L
STEP 11 : Move the data from B register to memory
STEP 12 : Decrement the C register by 1
STEP 13 : Jump to L2
STEP 14 : End.
PROGRAM:
155
TEST DATA:
INPUT:
4050: 2A
4051: FF
4052:23
4053:21
4054:03
4055: 18
4056:01
4057:08
4058:04
4059:02
OUTPUT:
4050: 2A
4051: 01
4052:02
4053:03
4054:04
4055: 18
4056:21
4057:23
4058:80
4059: FF
RESULT:
Thus, the assembly language program to find the largest element of an array
has been executed successfully.
156
4. REVERSING ARRAY ELEMENTS
AIM:
ALGORIT
STEP 1 : Start
STEP 2 : Initialize the H-L register pair with memory address 4050.
STEP 3 : Initialize the D-E register pair with memory address 4054.
STEP 4 : Load C register with the number of exchanges required which is equal to N/2.
STEP 5 : Get the first element form the memory by H-L register pair to B register.
STEP 6 : Get the last element from the memory by D-E register pair to A register.
STEP 7 : Store the content of A to memory pointed by H-L register pair.
STEP 8 : Transfer the content B to A and then to memory pointed by D-E register pair.
STEP 9 : Increment the memory address in H-L register pair.
STEP 10: Decrement the memory address in D-E register pair.
STEP 11: Decrement the count in C register by 1
STEP 12: If the count is not zero, then continue exchanging.
STEP 13: End.
PROGRAM:
157
TEST DATA:
INPUT:
4050: 08
4051: 04
4052: 0A
4053: 25
4054: 98
OUTPUT:
4050: 98
4051: 25
4052: 0A
4053: 04
4054: 08
RESULT:
Thus, the assembly language program to reverse the given array an elements has
been executed successfully.
158
5. BLOCK MOVE
AIM:
ALGORITHM:
STEP 1 : Start.
STEP 2 : Initialize H-L register pair with the starting address of the memory which
contain an array of N numbers.
STEP 3 : Initialize D-E register pair with the memory to which the element are going
to be transferred.
STEP 4 : Load C register with the number of elements in the given array.
STEP 5 : Get the element from the memory pointed by H-L register pair.
STEP 6 : Store the element in the memory pointed by D-E register pair.
STEP 7 : Increment the memory address in H-L register pair to get the next element
from the source block.
STEP 8 : Increment the memory address in D-E register pair to store the next element
in the destination block.
STEP 9 : Decrement the count in C register by 1.
STEP 10: If count is not zero, then loop move to step 5.
STEP 11: End.
PROGRAM
159
TEST DATA:
INPUT:
4050: 10
4051: 20
4052:30
4053:40
4054:50
OUTPUT:
4100: 10
4101: 20
4102:30
4103:40
4104:50
RESULT:
Thus, the assembly language program to Block Move has been executed successfully.
160
6. SORTING IN DESCENDING ORDER
AIM:
ALGORITHM:
STEP 1 : Start.
STEP 2 : Load size of list in C register and set D register.
STEP 3 : Copy the count in D register.
STEP 4 : Initialize H-L register pair with the memory address 4050.
STEP 5 : Move first data from M to A.
STEP 6 : Increment memory address in H-L.
STEP 7 : Move the second data from M to B register.
STEP 8 : Compare the data in A register with the data in B register
STEP 9 : If carry flag is not set, Jump to L1 loop
STEP 10 : Else, ‘swap’ the data stored in memory
STEP 11 : Decrement C in register D by 1
STEP 12 : If count in D register is not zero, jump L2.
STEP 13 : Decrement the count in C register by one.
STEP 14 : If count in C register is not zero, jump L3.
STEP 13 : End.
PROGRAM:
161
TEST DATA:
INPUT:
4050: 05
4051: 03
4052: 07
4053: 09
4054: 04
4055: 01
4056:06
4057:08
4058:0A
4059:02
OUTPUT:
4050: 0A
4051: 09
4052: 08
4053: 07
4054: 06
4055: 05
4056:04
4057:03
4058:02
4059:01
RESULT:
Thus, the assembly language program to sort the array elements in descending order
has been executed successfully.
162
IV: CODE CONVERSION
ALGORITHM:
STEP 1 : Start
STEP 2 : Load the BCD number in B register
STEP 3 : Copy it in accumulator
STEP 4 : Mask the upper nibble and store the lower nibble in C register
STEP 5 : Get the number in B register into the accumulator
STEP 6 : Mask the lower nibble and rotate the byte four times to the right to get
higher digit.
STEP 7 : Move it to C register
STEP 8 : Multiply the Tens digit in D by 10 or 0A
STEP 9 : Add the units digit to the result
STEP 10: Store the HEX result in memory
STEP 11: End
PROGRAM:
163
TEST DATA:
INPUT:
4050: 98
OUTPUT:
4051: 62
RESULT:
Thus, the assembly language program to convert BCD to HEX has been
executed successfully.
164
1. (B) HEX TO BCD
AIM:
ALGORITHM:
STEP 1: Start
STEP 2: Initialize memory to store the BCD result.
STEP 3: Load the Hex number in accumulator
STEP 4: Load B register
STEP 5: Call division subroutine to divide the remainder b 10 or 0A
STEP 6: Get the final remainder
STEP 7: End
PROGRAM:
165
TEST DATA:
INPUT:
4050: FEH
OUTPUT:
4051: 02
4052: 05
4053: 04
RESULT:
Thus, the assembly language program to convert HEX to BCD has been
executed successfully.
166
2. (A) BINARY TO ASCII CONVERSION
AIM:
ALGORITHM
STEP 1 : Start
STEP 2 : Load the binary number in accumulator.
STEP 3: If the given number is from 0 to 9 add 30H to accumulator and go to
step 5.
STEP 4: If the given number is from 0AH to 0FH add 07H in addition to 30H
STEP 5: Store the ASCII result in memory.
STEP 6: End
PROGRAM:
TEST DATA:
INPUT:
4050:0BH
OUTPUT:
4051: 42H
RESULT:
Thus, the assembly language program to convert from Binary to ASCII has been
executed successfully.
ALGORITHM:
STEP 1 : Start.
STEP 2: Take the ASCII number in accumulator.
STEP 3: Subtract NUMBER from the accumulator.
STEP 4: If the result is from 0 to 9 go to step 6.
STEP 5: if the result is greater than 9, subtract 7 from accumulator.
STEP 6: Store the BINARY result in memory
STEP 7: End.
PROGRAM:
TEST DATA:
INPUT:
4050: 42H
OUTPUT:
4051: 0BH
RESULT:
Thus, the assembly language program to convert from ASCII to Binary has
168
3. (A) ASCII TO BCD CONVERSION
AIM:
ALGORITHM:
STEP 1 : Start.
STEP 2: Take the ASCII number in accumulator.
STEP 3: Subtract NUMBER from the accumulator.
STEP 4: Store the BCD result in memory
STEP 5: End.
PROGRAM:
ADDRESS OPCODE MNEMONICS COMMENTS
4000 3A,50,40 LDA 4050H Take the ASCII number in accumulator
Subtract the number from the
4003 D6,30 SUI 30H
accumulator.
4005 32, 51, 40 STA 4051H Store the Binary result in memory
4008 76 HLT End of program
TEST DATA:
INPUT:
4050: 39
OUTPUT:
4051: 09
RESULT:
Thus, the assembly language program to convert from ASCII to BCD has
been executed successfully.
169
3. (B) BCD TO ASCII CONVERSION
AIM:
ALGORITHM:
STEP 1: Start.
STEP 2: Take the BCD number
STEP 3: Add 30 with accumulator
STEP 4: Store content of accumulator to memory
STEP 5: End.
PROGRAM:
TEST DATA:
INPUT:
4050: 08
OUTPUT:
4051:38
RESULT:
Thus, the assembly language program to convert from BCD to ASCII has
170
V APPLICATIONS
1. SQUARE OF A SINGLE BYTE HEX NUMBER
AIM:
To write an Assembly Language Program to find the square of a number.
ALGORITHM:
STEP 1: Start the 8085 assembly language program.
STEP 2: Initialize the registers H and L with 40, 50
STEP 3: Moves the content of memory location M to register B
STEP 4: Add the content of memory location which is directly specifies by M in
accumulator A
STEP 5: Decrement value of register B by 1
STEP 6: If ZF=0, the L1 jump to memory
STEP 7: Store value of A in 4050
STEP 5: End
PROGRAM:
INPUT:
4050: D4
OUTPUT:
4051: 10
RESULT:
Thus, the assembly language program to find the square of a number has been
executed successfully.
171
2. SQUARE OF A TWO DIGIT BCD NUMBER
AIM:
ALGORITHM:
STEP 1 : Start.
STEP 2 : Take the multiplicand in accumulator from memory.
STEP 3 : Transfer the multiplicand to B register.
STEP 4 : Take the multiplier in accumulator from memory.
STEP 5 : Transfer it to C register.
STEP 6 : Clear the accumulator
STEP 7 : Add the content of B register with that of the accumulator.
STEP 8 : Use DAA to convert the number in accumulator to decimal
STEP 9 : Decrement the decimal count in C register by one.
STEP 10 : If C is not zero, go to STEP 7.
STEP 11 : Store the BCD product in memory.
STEP 12 : End.
PROGRAM:
4000 21, 50, 40 LXI H, 4050 Load the number from 4050
TEST DATA:
INPUT:
4050: 08
OUTPUT:
4051: 10
RESULT:
Thus, the assembly language program to square of a two digit BCD numbers has
been executed successfully.
172
3. SQUARE ROOT OF A SINGLE BYTE HEX NUMBER
AIM:
To write 8085 Assembly Language Program to find square root of a single byte hex
number.
ALGORITHM:
PROGRAM:
TEST DATA
INPUT:
4050: 09
OUTPUT:
4051: 03
RESULT:
Thus, the assembly language program to find square root of a single byte hex
number has been executed successfully.
173
4. SQUARE ROOT OF A TWO DIGIT BCD NUMBER
AIM:
To write an Assembly Language Program to find the square root of a two digit
BCD number.
ALGORITHM:
PROGRAM:
TEST DATA:
INPUT:
4050: 19
OUTPUT:
4051: 05
RESULT:
Thus, the assembly language program to find the square root of a two digit BCD
has been executed successfully.
174
APPENDIX – I
179