Cit 344 PDF
Cit 344 PDF
Cit 344 PDF
COURSE TITLE:
INTRODUCTION TO COMPUTER DESIGN
CIT344 COURSE GUIDE
COURSE
GUIDE
CIT344
INTRODUCTION TO COMPUTER DESIGN
Abuja Office
5, Dar es Salaam Street
Off Aminu Kano Crescent
Wuse II, Abuja
Nigeria
e-mail: centralinfo@nou.edu.ng
URL: www.nou.edu.ng
Published By:
National Open University of Nigeria
ISBN: 978-058-047-6
iii
CIT344 COURSE GUIDE
CONTENTS PAGE
Introduction…………………………………………………………. 1
What You Will Learn in This Course………………….………....... 1
Course Aim…………………………………………………………. 1
Course Objectives…………………………………………………... 2
Working through This Course……………………………...………. 2
Course Materials……………………………………….…………… 2
Study Units……………………………………………….…………. 3
Textbooks and References………………………….……………….. 4
Assignment File………………………………………….…………. 4
Presentation Schedule………………………………….…………… 4
Assessment…………………………………………………………. 4
Tutor-Marked Assignments (TMAs)……………....…………..……. 4
Final Examination and Grading……………………………….……. 4
Course Marking Scheme………………………………………….… 7
Course Overview………………………………………………….… 7
How to Get the Most from This Course………………...………….. 8
Facilitators/Tutors and Tutorials……………………………………10
iv
Introduction
This course guide therefore gives you an overview of what the course is
all about, the textbooks and other course materials to be used, what you
are expected to know in each unit, and how to work through the course
material.
Course Aim
Course Objectives
It is relevant to note that each unit has its precise objectives. You should
learn them carefully before proceeding to subsequent units. Therefore, it
is useful to refer to these objectives in the course of your study of the
unit to assess your progress. You should always look at the unit
objectives after completing a unit. In this way, you can be sure that you
have done what is required of you by the end of the unit. However,
below are overall objectives of this course. On successful completion of
this course, you should be able to:
To complete this course, you are required to study all the units, the
recommended text books, and other relevant materials. Each unit
contains tutor-marked assignments, and at some point in this course, you
are required to submit the tutor-marked assignments. There is also a
final examination at the end of this course. Stated below are the
components of this course and what you have to do.
Course Materials
1. Course Guide
2. Study Units
3. Text Books
4. Assignment File
5. Presentation Schedule
ii
CIT344 INTRODUCTION TO COMPUTER DESIGN
Study Units
There are 6 modules and 21 study units in this course. They are:
Unit 1 Microprocessors
Unit 2 Central Processing Unit and Arithmetic and Logical Unit
Unit 3 Addressing Mode
iii
CIT344 INTRODUCTION TO COMPUTER DESIGN
Comer, J. David (1994). Digital Logic & State Machine Design. Oxford:
Oxford University Press.
Emerson, W. Pugh et al (1991). IBM's 360 and Early 370 Systems. MIT
Press.
iv
CIT344 INTRODUCTION TO COMPUTER DESIGN
www.cs.siu.edu
www.educypedia.be/electronics
www.books.google.com
v
CIT344 INTRODUCTION TO COMPUTER DESIGN
Assignment File
The assignment file will be given to you in due course. In this file, you
will find all the details of the work you must submit to your tutor for
marking. The marks you obtain for these assignments will count towards
the final mark for the course. Altogether, there are 21 tutor-marked
assignments for this course.
Presentation Schedule
Assessment
There are two aspects to the assessment of this course. First, there are
tutor-marked assignments; and second, the written examination.
You are expected to take note of the facts, information and problem
solving gathered during the course. The tutor-marked assignments must
be submitted to your tutor for formal assessment, in accordance to the
deadline given. The work submitted will count for 40% of your total
course mark. At the end of the course, you will need to sit for a final
written examination. This examination will account for 60% of your
total score.
There are 21 TMAs in this course. You need to submit all the TMAs.
When you have completed each assignment, send them to your tutor as
soon as possible and make certain that it gets to your tutor on or before
the stipulated deadline. If for any reason you cannot complete your
assignment on time, contact your tutor before the assignment is due to
discuss the possibility of extension. Extension will not be granted after
the deadline, unless in extraordinary cases.
The final examination for CIT344 will be of last for a period of 3 hours
and have a value of 60% of the total course grade. The examination will
consist of questions which reflect the self-assessment exercise and tutor-
marked assignments that you have previously encountered. Furthermore,
all areas of the course will be examined. It would be better to use the
time between finishing the last unit and sitting for the examination, to
revise the entire course. You might find it useful to review your TMAs
vi
CIT344 INTRODUCTION TO COMPUTER DESIGN
Assessment Marks
Assignments 1-21 21 assignments, 40% for the best 4
Total = 10% X 4 = 40%
Final Examination 60% of overall course marks
Total 100% of Course Marks
Course Overview
This indicates the units, the number of weeks required to complete them
and the assignments.
vii
CIT344 INTRODUCTION TO COMPUTER DESIGN
In distance learning, the study units replace the university lecturer. This
is one of the huge advantages of distance learning mode; you can read
and work through specially designed study materials at your own pace
and at a time and place that is most convenient. Think of it as reading
from the teacher, the study guide indicates what you ought to study, how
to study it and the relevant texts to consult. You are provided with
exercises at appropriate points, just as a lecturer might give you an in-
class exercise.
Each of the study units follows a common format. The first item is an
introduction to the subject matter of the unit and how a particular unit is
integrated with the other units and the course as a whole. Next to this is
a set of learning objectives. These learning objectives are meant to guide
your studies. The moment a unit is finished, you must go back and
check whether you have achieved the objectives. If this is made a habit,
then you will increase your chances of passing the course.
The main body of the units also guides you through the required
readings from other sources. This will usually be either from a set book
or from other sources. Self assessment exercises are provided
throughout the unit, to aid personal studies and answers are provided at
the end of the unit. Working through these self tests will help you to
achieve the objectives of the unit and also prepare you for tutor marked
assignments and examinations. You should attempt each self test as you
encounter them in the units.
viii
CIT344 INTRODUCTION TO COMPUTER DESIGN
Read the course guide thoroughly and organise a study schedule. Refer
to the course overview for more details. Note the time you are expected
to spend on each unit and how the assignment relates to the units.
Important details, e.g. details of your tutorials and the date of the first
day of the semester are available. You need to gather together all these
information in one place such as a diary, a wall chart calendar or an
organiser. Whatever method you choose, you should decide on and write
in your own dates for working on each unit.
Once you have created your own study schedule, do everything you can
to stick to it. The major reason that students fail is that they get behind
with their course works. If you get into difficulties with your schedule,
please let your tutor know before it is too late for help.
Turn to unit 1 and read the introduction and the objectives for the unit.
Assemble the study materials. Information about what you need for a
unit is given in the table of content at the beginning of each unit. You
will almost always need both the study unit you are working on and one
of the materials recommended for further readings, on your desk at the
same time.
Work through the unit, the content of the unit itself has been arranged to
provide a sequence for you to follow. As you work through the unit, you
will be encouraged to read from your set books.
Keep in mind that you will learn a lot by doing all your assignments
carefully. They have been designed to help you meet the objectives of
the course and will help you pass the examination.
Review the objectives of each study unit to confirm that you have
achieved them. If you are not certain about any of the objectives, review
the study material and consult your tutor.
When you are confident that you have achieved a unit’s objectives, you
can start on the next unit. Proceed unit by unit through the course and try
to pace your study so that you can keep yourself on schedule.
ix
CIT344 INTRODUCTION TO COMPUTER DESIGN
After completing the last unit, review the course and prepare yourself
for the final examination. Check that you have achieved the unit
objectives (listed at the beginning of each unit) and the course objectives
(listed in this course guide).
There are 8 hours of tutorial provided in support of this course. You will
be notified of the dates, time and location together with the name and
phone number of your tutor as soon as you are allocated a tutorial group.
Your tutor will mark and comment on your assignments, keep a close
watch on your progress and on any difficulties you might encounter and
provide assistance to you during the course. You must mail your tutor
marked assignment to your tutor well before the due date. At least two
working days are required for this purpose. They will be marked by your
tutor and returned to you as soon as possible. Do not hesitate to contact
your tutor by telephone, e-mail or discussion board if you need help.
The following might be circumstances in which you would find help
necessary:
you do not understand any part of the study units or the assigned
readings
you have difficulty with the self test or exercise
you have questions or problems with an assignment, with your
tutor’s comments on an assignment or with the grading of an
assignment.
You should try your best to attend the tutorials. This is the only chance
to have face-to-face contact with your tutor and ask questions which are
answered instantly. You can raise any problem encountered in the
course of your study. To gain the maximum benefit from the course
tutorials, prepare a question list before attending them. You will learn a
lot from participating actively in tutorial discussions.
x
CIT344 INTRODUCTION TO COMPUTER DESIGN
xi
CIT344 INTRODUCTION TO COMPUTER DESIGN
Abuja Office
5, Dar es Salaam Street
Off Aminu Kano Crescent
Wuse II, Abuja
Nigeria
e-mail: centralinfo@nou.edu.ng
URL: www.nou.edu.ng
Published By:
National Open University of Nigeria
ISBN: 978-058-047-6
xii
CIT344 INTRODUCTION TO COMPUTER DESIGN
CONTENTS PAGE
xiii
CIT344 INTRODUCTION TO COMPUTER DESIGN
CONTENTS
1.0 Introduction
2.0 Objectives
3.0 Main Content
3.1 Decimal Number System
3.2 Binary Number System
3.2.1 Fractions in Binary Number System
3.2.2 Binary Arithmetic
3.2.3 Binary to Decimal Conversion
3.2.4 Decimal to Binary Conversion
4.0 Conclusion
5.0 Summary
6.0 Tutor-Marked Assignment
7.0 References/Further Reading
1.0 INTRODUCTION
2.0 OBJECTIVES
1
CIT344 INTRODUCTION TO COMPUTER DESIGN
2
CIT344 INTRODUCTION TO COMPUTER DESIGN
Binary as the name indicates is a base-2 number system having only two
numbers 0 and 1. The binary digit 0 or 1 is known as a ‘Bit’. Below is
the decimal equivalent of the binary number system.
The number 100112 (the subscript 2 indicates that the number is a binary
number and not a decimal number ten thousand and eleven) can be
rewritten in terms of the expression:
3
CIT344 INTRODUCTION TO COMPUTER DESIGN
In a decimal number system the integer part and the fraction part of a
number are separated by a decimal point. In a binary number system the
integer part and the Fraction part of a binary number can be similarly
represented separated by a decimal point. The binary number 1011.1012
has an integer part represented by 1011 and a fraction part 101 separated
by a decimal point. The subscript 2 indicates that the number is a binary
number and not a decimal number. The binary number 1011.1012 can be
written in terms of an expression using the base value 2 and weights 23,
22, 21, 20, 2-1, 2-2 and 2-3.
Binary Addition
4
CIT344 INTRODUCTION TO COMPUTER DESIGN
The first three additions give a result 0, 1 and 1 respectively which can
be represented by a single binary digit (bit). The fourth addition results
in the number 2, which can be represented in binary as 102. Thus, two
digits (bits) are required. This is similar to the addition of 9 + 3 in
decimal. The answer is 12 which cannot be represented by a single digit;
thus, two digits are required. The number 2 is the sum part and 1 is the
carry part.
Binary Subtraction
Binary Multiplication
5
CIT344 INTRODUCTION TO COMPUTER DESIGN
Binary Division
10
101 | 1101
101
011
000
11
Sum-of-Weights Method
Binary bits having the value 0 do not contribute any value towards the
final sum expression. The binary number 101102 is therefore written in
the form of an expression having weights 20, 21, 22, 23 and 24
6
CIT344 INTRODUCTION TO COMPUTER DESIGN
101102 = 1 x 24 + 0 x 23 + 1 x 22 + 1 x 21 + 0 x 20
= 16 + 0 + 4 + 2 + 0
= 22
Sum-of-Non-Zero Terms
The weights of binary bits starting from the right most least significant
bit is 1, The next significant bit on the left has the weight 2, followed by
4, 8, 16, 32, etc. corresponding to higher significant bits. In binary
number system the weights of successive bits increase by an order of 2
towards the left side and decrease by an order of 2 towards the right
side. Thus, a binary number can be quickly converted into its decimal
equivalent by adding weights of non-zero terms which increase by a
factor of 2. Binary numbers having an integer and a fraction part can
similarly be converted into their decimal equivalents by applying the
same method.
A quicker method is to add the weights of non-zero terms. Thus, for the
numbers:
100112 = 16 + 2 + 1 = 19
1011.1012 = 8 + 2 + 1 + ½ + 1/8 = 11 + 5/8 = 11.625
7
CIT344 INTRODUCTION TO COMPUTER DESIGN
Sum-of-Weights
Repeated Division-by-2
8
CIT344 INTRODUCTION TO COMPUTER DESIGN
SELF-ASSESSMENT EXERCISE
4.0 CONCLUSION
5.0 SUMMARY
decimal to binary and vice versa. Hoping that you understood the topics
discussed, you may now attempt the questions below.
Comer, J. David (1994). Digital Logic & State Machine Design. Oxford
University Press.
www.books.google.com
10
CIT344 INTRODUCTION TO COMPUTER DESIGN
CONTENTS
1.0 Introduction
2.0 Objectives
3.0 Main Content
3.1 Hexadecimal Number System
3.1.1 Counting in Hexadecimal Number System
3.1.2 Binary to Hexadecimal Conversion
3.1.3 Hexadecimal to Binary Conversion
3.1.4 Decimal to Hexadecimal Conversion
3.1.5 Hexadecimal to Decimal Conversion
3.1.6 Hexadecimal Addition and Subtraction
3.2 Octal Number System
3.2.1 Counting in Octal Number System
3.2.2 Binary to Octal Conversion
3.2.3 Octal to Binary Conversion
3.2.4 Decimal to Octal Conversion
3.2.5 Octal to Decimal Conversion
3.2.6 Octal Addition and Subtraction
4.0 Conclusion
5.0 Summary
6.0 Tutor-Marked Assignment
7.0 References/Further Reading
1.0 INTRODUCTION
2.0 OBJECTIVES
11
CIT344 INTRODUCTION TO COMPUTER DESIGN
12
CIT344 INTRODUCTION TO COMPUTER DESIGN
13
CIT344 INTRODUCTION TO COMPUTER DESIGN
F D 1 3 hexadecimal number
1111 1101 0001 0011 Replacing each hexadecimal digit by its 4-bit
binary equivalent.
Indirect Method
The repeated division method has been discussed earlier and used to
convert decimal numbers to binary by repeatedly dividing the decimal
number by 2. A decimal number can be directly converted into
hexadecimal by using repeated division. The decimal number is
continuously divided by 16 (base value of the hexadecimal number
system).
14
CIT344 INTRODUCTION TO COMPUTER DESIGN
Indirect Method
Sum-of-Weights Method
Hexadecimal Addition
Carry 1
Number 1 2 AC 6
Number 2 9 2 B 5
Sum BD7B
Hexadecimal Subtraction
Borrow 1 1 1
Number 1 9 2 B 5
Number 2 2 A C 6
Difference 6 7 E F
15
CIT344 INTRODUCTION TO COMPUTER DESIGN
16
CIT344 INTRODUCTION TO COMPUTER DESIGN
Converting from octal back to binary is also very simple. Each digit of
the octal number is replaced by an equivalent binary string of 3-bits.
1 7 2 6 Octal number
001 111 010 110 Replacing each octal digit by its 3-bit binary
equivalent.
There are two methods to convert from decimal to octal. The first
method is the
Indirect Method and the second method is the repeated division method.
Indirect Method
17
CIT344 INTRODUCTION TO COMPUTER DESIGN
The repeated division method has been discussed earlier and used to
convert decimal numbers to binary and hexadecimal by repeatedly
dividing the decimal number by 2 and 16 respectively. A decimal
number can be directly converted into octal by using repeated division.
The decimal number is continuously divided by 8 (base value of the
Octal number system).
Indirect Method
Sum-of-Weights Method
18
CIT344 INTRODUCTION TO COMPUTER DESIGN
1. Octal Addition
Carry 1
Number 1 7 6 0 2
Number 2 5 7 7 1
Sum 15573
2. Octal Subtraction
Borrow 1 1
Number 1 7 6 0 2
Number 2 5 7 7 1
Difference 1 6 1 1
SELF-ASSESSMENT EXERCISE
Explain how you can convert hexadecimal and octal numbers to binary
and decimal numbers and vice versa.
4.0 CONCLUSION
5.0 SUMMARY
19
CIT344 INTRODUCTION TO COMPUTER DESIGN
Comer, J. David (1994). Digital Logic & State Machine Design. Oxford
University Press.
www.cs.siu.edu
www.educypedia.be/electronics
www.books.google.com
20
CIT344 INTRODUCTION TO COMPUTER DESIGN
UNIT 3 CODES
CONTENTS
1.0 Introduction
2.0 Objectives
3.0 Main Content
3.1 Codes
3.1.1 The Excess Code
3.1.2 BCD Code
3.1.3 Gray Code
3.1.4 Alphanumeric Code
3.1.5 ASCII Code
3.1.6 Extended ASCII Code
4.0 Conclusion
5.0 Summary
6.0 Tutor-Marked Assignment
7.0 References/Further Reading
1.0 INTRODUCTION
We have different types of code a few are briefly discussed below they
include: Excess code, BCD code, Gray code, alphanumeric code, ASCII
code, Extended ASCII code.
2.0 OBJECTIVES
define code
explain the various types of codes.
3.1 Codes
21
CIT344 INTRODUCTION TO COMPUTER DESIGN
22
CIT344 INTRODUCTION TO COMPUTER DESIGN
To write 17, two BCD code for 1 and 7 are used 0001 and 0111. The
two digits are considered to be separate. The conventional method of
representing decimal 17 using unsigned binary is 10001. A telephone
keypad having the digits 0 to 9 generates BCD codes for the keys
pressed.
BCD Addition
23 0010 0011
45 0100 0101
68 0110 1000
The two 2-digit BCD numbers are added and generate a result in BCD.
In the example, the least significant digits 3 and 5 add up to 8 which is a
valid BCD representation. Similarly, the most significant digits 2 and 4
add up to 6 which also is a valid BCD representation.
Consider the next example where the least significant numbers add up to
a number greater than 9 for which there is no valid BCD code
23 0010 0011
48 0100 1000
71 0110 1011
23
CIT344 INTRODUCTION TO COMPUTER DESIGN
0011
1000
1011 11 is generated which is an invalid BCD number
0110 6 is added
1 0001
The Gray code does not have any weights assigned to its bit positions.
The Gray code is not a positional code. The Gray code is different from
the unsigned binary code as successive values of Gray code differ by
only one bit. Table 3 shows the Gray code representation of decimal
numbers 0 to 9.
June 2003. The ASCII code is a universally accepted code that allows
128 characters and symbols to be represented.
ASCII codes 011 0000 (30h) to 011 1001 (39h) represents numbers 0 to
9
ASCII codes 100 0001 (41h) to 101 1010 (5Ah) represent upper case
alphabets A to Z
ASCII codes 000 0000 (0h) to 001 1111 (1Fh) represent the 32 Control
characters.
The 7-bit ASCII code only has 128 unique codes which are not enough
to represent some graphical characters displayed on computer screens.
An 8-bit code extended ASCII code gives 256 unique codes. The
extended 128 unique codes represent graphic symbols which have
become an unofficial standard as vendors use their own interpretation of
these graphic codes.
4.0 CONCLUSION
The Gray code does not have any weights assigned to its bit positions, is
not a positional code and is different from the unsigned binary code as
successive values of Gray code differ by only one bit.
25
CIT344 INTRODUCTION TO COMPUTER DESIGN
5.0 SUMMARY
In this unit, we talked about various codes, their characteristics and how
they can be used.
Comer, J. David (1994). Digital Logic & State Machine Design. Oxford
University Press.
26
CIT344 INTRODUCTION TO COMPUTER DESIGN
www.cs.siu.edu
www.educypedia.be/electronics
www.books.google.com
27
CIT344 INTRODUCTION TO COMPUTER DESIGN
CONTENTS
1.0 Introduction
2.0 Objectives
3.0 Main Content
3.1 Analysis of a Combinational Logic Circuit
3.2 Design of a Combinational Logic Circuit
4.0 Conclusion
5.0 Summary
6.0 Tutor-Marked Assignment
7.0 References/Further Reading
1.0 INTRODUCTION
Digital logic circuits can be classified into two types: Combinational and
Sequential logic circuits.
2.0 OBJECTIVES
28
CIT344 INTRODUCTION TO COMPUTER DESIGN
determine the inputs and the outputs from the problem definition
and then derive the truth table
use k-maps to minimise the number of inputs in order to express
the outputs - this reduces the number of gates and thus the
implementation cost
draw the logic diagrams.
4.0 CONCLUSION
5.0 SUMMARY
Comer, J. David (1994). Digital Logic & State Machine Design. Oxford
University Press.
29
CIT344 INTRODUCTION TO COMPUTER DESIGN
30
CIT344 INTRODUCTION TO COMPUTER DESIGN
CONTENTS
1.0 Introduction
2.0 Objectives
3.0 Main Content
3.1 Typical Combinational Logic Circuit I
3.1.1 Adders
3.1.1.1 Half-adder
3.1.1.2 Half-adder Function Table
3.1.1.3 Half-adder Sum & Carry out Boolean Expression
3.1.1.4 Full-adder
3.1.1.5 Full-adder Function Table
3.1.1.6 Full-adder Sum & Carry out Boolean Expression
3.1.1.7 Forming a Full-adder Using Half-adders
3.1.1.8 Parallel Binary Adders
4.0 Conclusion
5.0 Summary
6.0 Tutor-Marked Assignment
7.0 References/Further Reading
1.0 INTRODUCTION
2.0 OBJECTIVES
31
CIT344 INTRODUCTION TO COMPUTER DESIGN
3.1.1 Adders
3.1.1.1 Half-adder
A single bit binary adder circuit basically adds two bits. The output of
the single bit adder circuit generates a sum bit. An adder circuit that only
has two bit input representing the two single bit numbers A and B and
does not have the carry bit input from the least significant digit is
regarded as a half-adder. The block diagram below represents a half-
adder.
A half-adder can be fully described in terms of its function table and the
circuit implementation.
The half-adder has a 2-bit input and a 2-bit output. The function table of
the half-adder has two input columns representing the two single bit
numbers A and B. The function table also has two output columns
representing the sum bit and carry out bit.
32
CIT344 INTRODUCTION TO COMPUTER DESIGN
The sum and carry out expressions of the half-adder can be determined
from the function table. The half-adder sum and carry out outputs are
defined by the expressions:
Sum = AB + AB = A B
Carry out = AB
3.1.1.4 Full-Adder
An adder circuit which has three inputs, one representing single bit
number A, the other representing the single bit number B and the third
bit represents the single bit carry is referred to as a full-adder. The single
bit binary adder has two bit output. One bit represents the Sum between
numbers A and B. The other bit represents the carry bit generated due to
addition. The diagram below represents the block diagram of a full-
adder.
33
CIT344 INTRODUCTION TO COMPUTER DESIGN
The full-adder has a 3-bit input and a 2-bit output. The function table of
the full-adder has three input columns representing the two single bit
numbers A, B and the carry in bit. The function table also has two
output columns representing the sum bit and carry out bit.
The sum and carry out expressions of the full-adder can be determined
from the function table. The full-adder sum and carry out outputs are
defined by the expressions:
34
CIT344 INTRODUCTION TO COMPUTER DESIGN
Single bit full or half-adders do not perform any useful function. To add
two 4-bit numbers a 4-bit adder is required. Four single bit full-adders
are connected together to form a 4-bit parallel adder capable of adding
two 4-bit binary numbers. A 4-bit binary adder can be formed with four
full-adders as follows:
35
CIT344 INTRODUCTION TO COMPUTER DESIGN
SELF-ASSESSMENT EXERCISE
Explain with the aid of diagrams how you can form a full-adder from
half-adders.
4.0 CONCLUSION
An adder circuit that only has two bit input representing the two single
bit numbers A and B and does not have the carry bit input from the least
significant digit is regarded as a half-adder. An adder circuit which has
three inputs, one representing single bit number A, the other
representing the single bit number B and the third bit represents the
single bit carry is referred to as a full-adder.
5.0 SUMMARY
36
CIT344 INTRODUCTION TO COMPUTER DESIGN
1. half-adder, its function table and sum & carry out Boolean
expression.
2. full-adder, its function table and sum & carry out Boolean
expression.
Comer, J. David (1994). Digital Logic & State Machine Design. Oxford
University Press.
Nelson, P. Victor et al. (1995). Digital Logic Circuit Analysis & Design.
Prentice Hall.
37
CIT344 INTRODUCTION TO COMPUTER DESIGN
38
CIT344 INTRODUCTION TO COMPUTER DESIGN
CONTENTS
1.0 Introduction
2.0 Objectives
3.0 Main Content
3.1 Typical Combinational Logic Circuit II
3.1.1 Multiplexers
3.1.1.1 Using Pass Gate
3.1.1.2 Design with Multiplexers
3.1.1.3 Applications of Multiplexers
3.1.2 Demultiplexers
3.1.2.1 Applications of Demultiplexers
4.0 Conclusion
5.0 Summary
6.0 Tutor-Marked Assignment
7.0 References/Further Reading
1.0 INTRODUCTION
2.0 OBJECTIVES
3.1.1 Multiplexers
39
CIT344 INTRODUCTION TO COMPUTER DESIGN
The inputs of the two multiplexers are connected to the output of each of
the multiple registers.
The outputs of the two multiplexers are connected to the two inputs of
the ALUs. The multiplexers are used to route the contents of any two
registers to the ALU inputs.
40
CIT344 INTRODUCTION TO COMPUTER DESIGN
41
CIT344 INTRODUCTION TO COMPUTER DESIGN
42
CIT344 INTRODUCTION TO COMPUTER DESIGN
Data Routing
An 8-bit parallel data can be converted into serial data by using an 8-to-
1 multiplexer such as 74X151 which has 8 inputs and a single output.
The 8-bit data which is to be transmitted serially is applied at the 8
inputs I0-7 of the multiplexer. A three bit counter which counts from 0
to 7 is connected to the three select inputs S0, S1 and S2. The counter is
connected to a clock which sends a clock pulse to the counter every 1
millisecond. Initially, the counter is reset to 000, the I0 input is selected
and the data at input I0 is routed to the output of the multiplexer. On
receiving the clock signal after 1 millisecond the counter increments its
count from 000 to 001 which selects I1 input of the multiplexer and
routes the data present at the input to the output. Similarly, at the next
clock pulse the counter increments to 010, selecting I2 input and routing
the data to the output. Thus, after 8 milliseconds the parallel data is
routed to the output 1-bit at a time. The output of the multiplexer is
connected to the wire through which the serial data is transmitted.
43
CIT344 INTRODUCTION TO COMPUTER DESIGN
44
CIT344 INTRODUCTION TO COMPUTER DESIGN
Operation Sequencing
45
CIT344 INTRODUCTION TO COMPUTER DESIGN
3.1.2 Demultiplexer
A multiplexer has several inputs. It selects one of the inputs and routes
the data at the selected input to the single output. Demultiplexer has an
opposite function to that of the multiplexer. It has a single input and
several outputs. The demultiplexer selects one of the several outputs and
routes the data at the single input to the selected output. A demultiplexer
is also known as a data distributor.
46
CIT344 INTRODUCTION TO COMPUTER DESIGN
Fig. 8: A 1 x 4 Demultiplexer
The circuit if compared to that of the 2-to-4 decoder. The decoder enable
input is used as the demultiplexer data input. A demultiplexer is not
available commercially. A demultiplexer is available as a
decoder/demultiplexer chip which can be configured to operate as a
demultiplexer or a decoder.
It is used at the output of the ALU circuit. The output of the ALU has to
be stored in one of the multiple registers or storage units. The Data input
of the demultiplexer is connected to the output of the ALU. Each output
of the demultiplexer is connected to each of the multiple registers. By
selecting the appropriate output data from the ALU is routed to the
appropriate register for storage.
4.0 CONCLUSION
48
CIT344 INTRODUCTION TO COMPUTER DESIGN
5.0 SUMMARY
i. MUX
ii. DeMUX
iii. 4 Differences b/w MUX and DeMUX
iv. Designing with multiplexers and demultiplexers
v. Applications of MUX and DeMUX.
Comer, J. David (1994). Digital Logic & State Machine Design. Oxford
University Press.
Nelson, P. Victor et al. (1995). Digital Logic Circuit Analysis & Design.
Prentice Hall.
49
CIT344 INTRODUCTION TO COMPUTER DESIGN
50
CIT344 INTRODUCTION TO COMPUTER DESIGN
CONTENTS
1.0 Introduction
2.0 Objectives
3.0 Main Content
3.1 Typical Combinational Logic Circuit III
3.1.1 Decoders
3.1.1.1 Decoders with Enable Line
3.1.1.2 Designing with Decoders
3.1.1.3 Decoder Networks
3.1.1.4 Applications of Decoders
3.1.2 Encoders
3.1.2.1 Designing with Encoders
3.1.2.2 Priority Encoders
3.1.2.3 Designing with P-Encoders
3.1.2.4 Designing with P-Encoders
4.0 Conclusion
5.0 Summary
5.0 Tutor-Marked Assignment
6.0 References/Further Reading
1.0 INTRODUCTION
2.0 OBJECTIVES
define a decoder
design with decoders
discuss the decoder networks and applications of decoders
define an encoder
define a priority encoder.
51
CIT344 INTRODUCTION TO COMPUTER DESIGN
3.1.1 Decoders
A decoder has multiple inputs and multiple outputs. The decoder device
accepts as an input a multi-bit code and activates one or more of its
outputs to indicate the presence of the multi-bit code. A standard
decoder is an m-to-n line where m≤2n.
Often, decoders have an enable line that turns on outputs or leaves them
off. The figure below shows a 3-to-8 decoder with enable and its truth
table.
52
CIT344 INTRODUCTION TO COMPUTER DESIGN
53
CIT344 INTRODUCTION TO COMPUTER DESIGN
Computers have different internal and external devices like the Hard
Disk, CD Drive, Modem, Printer, etc. Each of these different devices is
selected by specifying different codes. A decoder is used to uniquely
select or deselect the appropriate devices.
Instruction Decoder
3.1.2 Encoders
54
CIT344 INTRODUCTION TO COMPUTER DESIGN
55
CIT344 INTRODUCTION TO COMPUTER DESIGN
Encoders are useful when the occurance of one of several disjoint events
needs to be represented by an integer identifying the event.
A priority encoder takes the input of 1 with the highest index and
translates that index to the output.
56
CIT344 INTRODUCTION TO COMPUTER DESIGN
SELF-ASSESSMENT EXERCISE
4.0 CONCLUSION
A decoder has multiple inputs and multiple outputs. The decoder device
accepts as an input a multi-bit code and activates one or more of its
outputs to indicate the presence of the multi-bit code. Decoders have
two major uses in computer systems: selection of peripheral devices and
instruction decoder.
5.0 SUMMARY
In this unit, we examined decoders and encoders and also how to design
with them.
57
CIT344 INTRODUCTION TO COMPUTER DESIGN
i. decoders
ii. encoders
iii. differences between decoders and encoders
iv designing with decoders and encoders
v. applications of decoders and encoders.
Comer, J. David (1994). Digital Logic & State Machine Design. Oxford
University Press.
58
CIT344 INTRODUCTION TO COMPUTER DESIGN
59
CIT344 INTRODUCTION TO COMPUTER DESIGN
CONTENTS
1.0 Introduction
2.0 Objectives
3.0 Main Content
3.1 Sequential Logic Circuits
3.1.1 Overview
4.0 Conclusion
5.0 Summary
6.0 Tutor-Marked Assignment
7.0 References/Further Reading
1.0 INTRODUCTION
Digital logic circuits can be classified into two types: Combinational and
Sequential logic circuits. We shall in this module explain the sequential
logic circuit and its numerous applications.
2.0 OBJECTIVES
60
CIT344 INTRODUCTION TO COMPUTER DESIGN
3.1.1 Overview
Digital circuits that use memory elements for their operation are known
as Sequential circuits. Thus, sequential circuits are implemented by
combining combinational circuits with memory elements as shown
below:
61
CIT344 INTRODUCTION TO COMPUTER DESIGN
SELF-ASSESSMENT EXCERCISE
4.0 CONCLUSION
Digital circuits that use memory elements for their operation are known
as sequential circuits. Thus, sequential circuits are implemented by
combining combinational circuits with memory elements.
5.0 SUMMARY
Extensively discuss sequential logic circuit and its types using diagrams
and good examples.
62
CIT344 INTRODUCTION TO COMPUTER DESIGN
Comer, J. David (1994). Digital Logic & State Machine Design. Oxford
University Press.
63
CIT344 INTRODUCTION TO COMPUTER DESIGN
64
CIT344 INTRODUCTION TO COMPUTER DESIGN
CONTENTS
1.0 Introduction
2.0 Objectives
3.0 Main Content
3.1 Latches and Flip-Flops
3.1.1 Latches
3.1.1.1The NAND Gate Based S-R Latch
3.1.1.2The NOR Gate Based S-R (Set-Reset) Latch
3.1.1.3Applications of S-R Latch
3.1.1.4 The Gated S-R Latch
3.1.1.5 The Gated D Latch
3.1.2 Flip-Flops
3.1.2.1 S-R Edge-Triggered Flip-Flops
3.1.2.2 Edge-Triggered D Flip-Flops
3.1.2.3 Edge-Triggered J-K Flip-Flops
3.1.2.4 Asynchronous Preset and Clear Inputs
3.1.2.5 Master-Slave Flip-Flops
3.1.2.6 Flip-Flops Operating Characteristics
3.1.2.7 Applications of Edge-Triggered D Flip-
Flops
3.1.2.8 Applications of Edge-Triggered J-K Flip-
Flops
4.0 Conclusion
5.0 Summary
6.0 Tutor-Marked Assignment
7.0 References/Further Reading
1.0 INTRODUCTION
2.0 OBJECTIVES
65
CIT344 INTRODUCTION TO COMPUTER DESIGN
3.1.1 Latches
A latch is a temporary storage device that has two stable states. A latch
output can change from one state to the other by applying appropriate
inputs. A latch normally has two inputs, the binary input combinations
at the latch input allows the latch to change its state. A latch has two
outputs Q and its complement Q. The latch is said to be in logic high
state when Q=1 and Q=0 and it is in the logic low state when Q=0 and
Q=1. When the latch is set to a certain state it retains its state unless the
inputs are changed to set the latch to a new state.
66
CIT344 INTRODUCTION TO COMPUTER DESIGN
A truth-table shows the operation of the S-R NAND based latch. The
Output Qt+1 represents the Q output of NAND gate 1 at time interval
t+1.When inputs are S = 1 and R = 1 the next state output Qt+1 remains
the same as the previous state output Qt. When inputs are S = 0 and R =
1 the output Q is set to 1. When inputs are S = 1 and R = 0 the output Q
is set to 0. Inputs S = 0 and R = 0 are not applied as they place the latch
in an invalid state.
Input Output
S R Qt+1
0 0 invalid
0 1 1
1 0 0
1 1 Qt
Connections are identical to that of the NAND based latch. The S and R
inputs have been switched.
The truth table of the NOR gate based latch is shown. When inputs are S
=0 and R = 0 the next state output Qt+1 remains the same as the
previous state output Qt. When inputs are S = 0 and R = 1 the output Q
is set to 0. When inputs are S = 1 and R = 0 the output Q is set to 1.
Inputs S = 1 and R = 1 are not applied as they place the latch in an
invalid state. The NOR gate based S-R latch has active-high inputs.
67
CIT344 INTRODUCTION TO COMPUTER DESIGN
Input Output
S R Qt+1
0 0 Qt
0 1 0
1 0 1
1 1 invalid
Comparing the operation of the NOR based and NAND based S-R
latches.
The NAND based latch has active-low inputs, whereas NOR based latch
has active-high inputs. Both the S-R latches are set to logic 1 when the
set input is activated and the reset input is inactive.
Both the latches are set to logic 0 when the reset input is activated and
the set input is inactive. The latches maintain the output state when both
the set and reset inputs are inactive.
For both the latches both the set and reset inputs cannot be activated
simultaneously as this leads to invalid output states. The logic symbols
of the two latches are shown below.
Digital systems use switches to input values and to control the output.
For example, a keypad uses 10 switches to enter decimal numbers 0 to 9.
When a switch is closed the switch contacts physically vibrate or
‘bounce’ before making a solid contact. The switch bounce causes the
voltage at the output of the switch to vary between logic low and high
68
CIT344 INTRODUCTION TO COMPUTER DESIGN
for a very short duration before it settles to a steady state. The variation
in the voltage causes the digital circuit to operate in an erratic manner.
An S-R latch connected between the switch and the digital circuit
prevents the varying switch output from reaching the digital circuit.
The S-R NAND gate based latch is available in the form of an Integrated
Circuit. The 74LS279 IC has four S-R latches which can be used
independently.
The gated S-R latch has an enable input which has to be activated to
operate the latch. The circuit diagram of the gated S-R latch is shown in
figure 6. In the gated S-R circuit, the S and R inputs are applied at the
inputs of the NAND gates 1 and 2 when the enable input is set to active-
high. If the enable input is disabled by setting it to logic low the output
of NAND gates 3 and 4 remains logic 1, whatever the state of S and R
inputs. Thus, logic 1 applied at the inputs of NAND gates 1 and 2 keeps
the Q and Q outputs to the previous state. The logic symbol of a gated S-
R latch is shown in figure 6.
70
CIT344 INTRODUCTION TO COMPUTER DESIGN
Input Output
EN S R Qt+1
0 x x Qt
1 0 0 Qt
1 0 1 0
1 1 0 1
1 1 1 invalid
71
CIT344 INTRODUCTION TO COMPUTER DESIGN
3.1.2 Flip-Flops
When latches are used for the memory elements in sequential circuits, a
serious difficulty arises. Recall that latches have the property of
immediate output responses (i.e., transparency).Because of this the
output of a latch cannot be applied directly (or through logic) to the
input of the same or another latch when all the latches are triggered by a
common clock source. Flip-flops are used to overcome this difficulty.
72
CIT344 INTRODUCTION TO COMPUTER DESIGN
Each flip-flop has two variations, that is, it is either positive edge-
triggered or negative edge triggered. A positive edge-triggered flip-flop
changes its state on a low-to-high transition of the clock and a negative
edge-triggered flip-flop changes its state on a high-to-low transition of
the clock. The edge-detection circuit which allows a flip-flop to change
its state on either the positive or the negative transition of the clock is
implemented using a simple combinational circuit. The edge detection
circuit that detects the positive and the negative clock transition are
shown in figure 11.
The logic symbols of a positive edge and a negative edge triggered S-R
flip-flops are shown in figure 12 below.
73
CIT344 INTRODUCTION TO COMPUTER DESIGN
The truth tables of the two S-R flip-flops are also shown below in table
5.
74
CIT344 INTRODUCTION TO COMPUTER DESIGN
75
CIT344 INTRODUCTION TO COMPUTER DESIGN
J = 0 and K =0
With Q=1 and Q=0, on a clock transition the outputs of NAND gates 3
and 4 are set to logic 1. With logic 1 value at the inputs of NAND gates
1 and 2 the output Q and Q remains unchanged. With Q=0 and Q=1, on
a clock transition the outputs of the NAND gates 3 and 4 are set to logic
1. With logic 1 value at the inputs of NAND gates 1 and 2 the output Q
and Q remains unchanged.
Thus, when J=0 and K=0 the previous state is maintained and there is no
change in the output.
J = 0 and K =1
With Q=1 and Q=0, on a clock transition the output of NAND gate 3 is
set to logic 1.
The output of the NAND gate 4 is set to 0 as all three of its inputs are at
logic 1. The logic 1 and 0 at the inputs of the NAND gates 3 and 4
respectively resets the Q output to 0 and Q to 1. With Q=0 and Q=1, on
a clock transition the output of NAND gate 3 is set to logic 1. The
76
CIT344 INTRODUCTION TO COMPUTER DESIGN
output of the NAND gate 4 is also set to 1 as the input of the NAND
gate 4 is connected to Q=0. The logic 1 and 1 at the inputs of the NAND
gates 3 and 4 respectively retains the Q and Q to 0 and 1 respectively.
Thus, when J=0 and K=1 the J-K flip-flop irrespective of its earlier state
is rest to state Q=0 and Q=1.
J = 1 and K =0
With Q=1 and Q=0, on a clock transition the output of NAND gate 4 is
set to logic 1.
The output of the NAND gate 3 is also set to 1 as its input connected to
Q is at logic 0. Thus, inputs 1 and 1 at inputs of NAND gates 1 and 2
retain the Q and Q output to 1 and 0 respectively. With Q=0 and Q=1,
on a clock transition the output of NAND gate 4 is set to logic 1. The
output of the NAND gate 3 is set to 0 as all its input are at logic 1. Thus,
inputs 0 and 1 at inputs of NAND gates 1 and 2 sets the flip-flop to Q=1
and Q=0.
Thus, when J=1 and K=0 the J-K flip-flop irrespective of its output state
is set to state Q=1 and Q=0.
J = 1 and K =1
With Q=1 and Q=0, on a clock transition the output of the NAND gates
3 and 4 depend on the outputs Q and Q. The output of NAND gate 3 is
set to 1 as Q is connected to its input. The output of NAND gate 4 is set
to 0 as all its inputs including Q is at logic 1. A logic 1 and 0 at the input
of gates 1 and 2 toggles the outputs Q and Q from logic 1 and 0 to 0 and
1 respectively. With Q=0 and Q=1, on a clock transition the output of
NAND gate 3 is set to 0 as Q and the output of NAND gate 4 is set to 1.
A logic 0 and 1 at the input toggles the outputs Q and Q from logic 0
and 1 to 1 and 0 respectively.
In summary, when J-K inputs are both set to logic 0, the output remains
unchanged. At J=0 and K=1 the J-K flip-flop is reset to Q=0 and Q=1.
At J=1 and K=0 the flip-flop is set to Q=1 and Q=0. With J=1 and K=1
the output toggles from the previous state.
The truth tables of the positive and negative edge triggered J-K flip-
flops are shown in Table 7.
77
CIT344 INTRODUCTION TO COMPUTER DESIGN
The logic symbols of the J-K flip-flops are shown in figure 15.
The S-R, J-K and D inputs are known as synchronous inputs because the
outputs change when appropriate input values are applied at the inputs
and a clock signal is applied at the clock input. If there is no clock
transition then the inputs have no effect on the output.
Digital circuits require that the flip-flops be set or reset to some initial
state before a new set of inputs is applied for changing the output. The
flip-flops are set-reset to some initial state by using asynchronous inputs
known as Preset and Clear inputs. Since these inputs change the output
78
CIT344 INTRODUCTION TO COMPUTER DESIGN
79
CIT344 INTRODUCTION TO COMPUTER DESIGN
80
CIT344 INTRODUCTION TO COMPUTER DESIGN
81
CIT344 INTRODUCTION TO COMPUTER DESIGN
• Propagation Delay
• Set-up Time
• Hold Time
• Maximum Clock frequency
• Pulse width
• Power Dissipation
Propagation Delay
The propagation delay time is the interval of time when the input is
applied and the output changes. Four different types of Propagation
Delays are measured.
82
CIT344 INTRODUCTION TO COMPUTER DESIGN
Set-Up Time
When a clock transition occurs at the clock input of a flip-flop the output
of the flip-flop is set to a new state based on the inputs. For the flip-flop
to change its output to a new state at the clock transition, the input
should be stable. The minimum time required for the input logic levels
to remain stable before the clock transition occurs is known as the set-up
time
Hold Time
Pulse Width
A flip-flop uses the clock, preset and clear inputs for its operation. Each
signal has to be of a specified duration for correct operation of the flip-
flop. The manufacturer specifies the minimum pulse width tw for each of
the three signals. The clock signal is specified by minimum high time
and minimum low time.
Power Dissipation
83
CIT344 INTRODUCTION TO COMPUTER DESIGN
84
CIT344 INTRODUCTION TO COMPUTER DESIGN
In synchronised digital systems all the circuits change their state with
respect to a common clock and all the input and output signals are
synchronised. However, external inputs that are applied to digital
circuits through switches and keypads are not synchronised with the
clock. The asynchronous inputs can occur at any instant of time
85
CIT344 INTRODUCTION TO COMPUTER DESIGN
MHZ and 1 MHZ signal using two J-K flip-flops connected together.
86
CIT344 INTRODUCTION TO COMPUTER DESIGN
numbers can be easily shifted in the left or right direction by using J-K
flip-flop based shift registers.
4.0 CONCLUSION
A latch is a temporary storage device that has two stable states. A latch
output can change from one state to the other by applying appropriate
inputs. A latch normally has two inputs, the binary input combinations
at the latch input allows the latch to change its state.
87
CIT344 INTRODUCTION TO COMPUTER DESIGN
5.0 SUMMARY
Extensively discuss latches and flip-flops and their types using diagrams
and good examples.
Comer, J. David (1994). Digital Logic & State Machine Design. Oxford
University Press.
88
CIT344 INTRODUCTION TO COMPUTER DESIGN
89
CIT344 INTRODUCTION TO COMPUTER DESIGN
UNIT 3 REGISTERS
CONTENTS
1.0 Introduction
2.0 Objectives
3.0 Main Content
3.1 Registers
3.1.1 Shift Registers
3.1.2 Shift Register Counters
3.1.3 Applications of Shift Registers
4.0 Conclusion
5.0 Summary
6.0 Tutor-Marked Assignment
7.0 References/Further Reading
1.0 INTRODUCTION
In this unit we shall discuss registers. We shall look at the shift register,
shift register counters and the applications of shift registers.
2.0 OBJECTIVES
3.1 Registers
90
CIT344 INTRODUCTION TO COMPUTER DESIGN
Data is shifted in the right-hand direction one bit at a time with each
transition of the clock signal. The data enters the shift register serially
from the left hand side and after four clock transitions the 4-bit register
has 4-bits of data. The data is shifted out serially one bit at a time from
the right hand side of the register if clock signals are continuously
applied. Thus, after 8 clock signals the 4-bit data is completely shifted
out of the shift register.
Data is shifted in the left-hand direction one bit at a time with each
transition of the clock signal. The data enters the shift register serially
from the right hand side and after four clock transitions the 4-bit register
has 4-bits of data. The data is shifted out serially one bit at a time from
91
CIT344 INTRODUCTION TO COMPUTER DESIGN
the left hand side of the register if clock signals are continuously
applied. Thus, after 8 clock signals the 4-bit data is completely shifted
out of the shift register.
The shift left and shift right shift registers are identical in their working.
They are connected differently for shift left and shift right operations.
Bidirectional Shift Registers are available which allow data to be shifted
92
CIT344 INTRODUCTION TO COMPUTER DESIGN
Data is shifted in the left-hand direction one bit at a time with each
transition of the clock signal. The data enters the shift register serially
from the right hand side and after four clock transitions the 4-bit register
has 4-bits of data. The data is shifted out in parallel by the application of
a single clock signal. The shift register has 4 parallel outputs. The circuit
diagram of the Serial In/Parallel Out register is shown.
93
CIT344 INTRODUCTION TO COMPUTER DESIGN
The register has parallel inputs, data bits are loaded into the register in
parallel by activating a load signal. The data is shifted out serially by
application of clock signals. Thus, in a 4-bit shift register, after 4 clock
signals the 4-bit data is completely shifted out of the shift register.
respective flip-flops. To shift the data, the SHIFT /LOAD is set to logic
high which enables AND gates marked 1 connecting the Q outputs of
the each flip-flop connected to the D input of the next flip-flop.
The register has parallel inputs and parallel outputs. Data is entered in
parallel by applying a single clock pulse. Data is latched by the flip-
flops on the clock transition and is available in parallel form at the flip-
flop outputs.
95
CIT344 INTRODUCTION TO COMPUTER DESIGN
The serial output of the register is connected to the serial input of the
register. By applying clock pulses data is shifted right. The data shifted
out of the serial out pin at the right hand side is re-circulated back into
the shift register input at the left hand side. Thus, the data is rotated right
within the register.
The serial output of the register is connected to the serial input of the
register. By applying clock pulses data is shifted left. The data shifted
out of the serial out pin at the left hand side is re-circulated back into the
shift register input at the right hand side. Thus, the data is rotated left
within the register.
96
CIT344 INTRODUCTION TO COMPUTER DESIGN
Johnson Counter
97
CIT344 INTRODUCTION TO COMPUTER DESIGN
Ring Counter
The Ring Counter is similar to the Johnson Counter, except that the Q
output of the last flip-flop of the shift register is connected to the data
input of the first flip-flop of the shift register. All the flip-flops of the
counter are cleared to logic low except for the first flip-flop which is
preset to logic high.
After the initialisation of the counter, the logic high set at the output of
the first flip-flop is shifted right at each clock transition. With a Ring
Counter circuit no decoding gates are required. Each state of the ring
counter has a unique output.
98
CIT344 INTRODUCTION TO COMPUTER DESIGN
Serial-to-Parallel Converter
99
CIT344 INTRODUCTION TO COMPUTER DESIGN
100
CIT344 INTRODUCTION TO COMPUTER DESIGN
Keyboard Encoder
101
CIT344 INTRODUCTION TO COMPUTER DESIGN
4.0 CONCLUSION
102
CIT344 INTRODUCTION TO COMPUTER DESIGN
Shift register counters are shift registers connected to perform rotate left
and rotate right operations. When data is rotated through a register
counter a specific sequence of states is repeated. Two commonly used
register counters in digital logic are the Johnson Counter and the Ring
Counter.
SELF-ASSESSMENT EXERCISE
5.0 SUMMARY
State in not less than four pages what you know about registers.
Comer, J. David (1994). Digital Logic & State Machine Design. Oxford
University Press.
103
CIT344 INTRODUCTION TO COMPUTER DESIGN
Nelson, P. Victor et al. (1995). Digital Logic Circuit Analysis & Design.
Prentice Hall.
104
CIT344 INTRODUCTION TO COMPUTER DESIGN
CONTENTS
1.0 Introduction
2.0 Objectives
3.0 Main Content
3.1 Finite State Machines
3.2 Finite State Machines as a Restrictive Turing Machines
3.3 Modeling the Behaviour of Finite State Machine
3.4 Functional Program View of Finite State Machines
3.5 Imperative Program View of Finite State Machines
3.6 Feedback System View of Finite State Machines
3.7 Tabular Description of Finite State Machines
3.8 Classifiers, Acceptors, Transducers & Sequencers
3.9 Description of Finite State Machines using Graphs
4.0 Conclusion
5.0 Summary
6.0 Tutor-Marked Assignment
7.0 References/Further Reading
1.0 INTRODUCTION
2.0 OBJECTIVES
106
CIT344 INTRODUCTION TO COMPUTER DESIGN
107
CIT344 INTRODUCTION TO COMPUTER DESIGN
108
CIT344 INTRODUCTION TO COMPUTER DESIGN
Since the motion of the head over the tape is strictly one-way, we can
abstract away the idea of a tape and just refer to the input sequence read
and the output sequence produced, as suggested in the next diagram. A
machine of this form is called a transducer, since it maps input
sequences to output sequences. The term Mealy machine, after George
H. Mealy (1965), is also often used for transducer.
109
CIT344 INTRODUCTION TO COMPUTER DESIGN
For a Mealy machine, the transition will be associated with an output. For a
Moore machine, the output occurs within the next state. For this reason,
Finite State Machines are often called 'reactive' systems. Inputs are also
called events. Typical events may be: a message received from another
state machine, a simple event flag set by another state machine, or the
expiration of a time interval. Likewise, outputs may be: sending a message
to another state machine, setting an event flag for another state machine to
respond to, or starting a timed interval. Also, multiple unique transitions
are allowed from one state to other defined states. For software FSMs, each
state will have its unique source code logic to process events, perform
actions and output, and to effect state transitions. A complete system may
be comprised of one or more Finite State Machines, as determined by the
partitioning process performed during the initial design or analysis.
Although the Mealy Machine model may be more flexible than Moore
Machine, it is the need of the system being analysed or designed that
determines which of the two is most suitable. Note that a given state
machine may be comprised of both Mealy and Moore models, if such a
design meets functional requirements of the system. Also, be aware that
both Mealy and Moore Machines can be logically converted to the other.
The point here is that the correct state logic required for efficient operation
is what’s important; the resulting machine archetype (Mealy or Moore)
should be only a secondary observation.
Example: An Edge-Detector
110
CIT344 INTRODUCTION TO COMPUTER DESIGN
The initial state is identified with the overall function of the machine.
The functions are interrelated by mutual recursion: when a function
processes an input symbol, it calls another function to process the
remaining input.
Each function will return NIL if the input list is NIL, and we do not
show this explicitly.
111
CIT344 INTRODUCTION TO COMPUTER DESIGN
Notice that f is never called after its initial use. Its only purpose is to
provide the proper output (namely 0) for the first symbol in the input.
The top level call with input sequence x is k ("f", x) since "f" is the
initial state.
In this view, the input and output are viewed as streams of characters.
The program repeats the processing cycle:
112
CIT344 INTRODUCTION TO COMPUTER DESIGN
read character,
select next state,
write character,
go to next state
[Note that this is a case where all calls can be "tail recursive", i.e. could
be implemented as gotos by a smart compiler.]
113
CIT344 INTRODUCTION TO COMPUTER DESIGN
114
CIT344 INTRODUCTION TO COMPUTER DESIGN
F(q, σ) is the state to which the machine goes when currently in state q
and σ is read
115
CIT344 INTRODUCTION TO COMPUTER DESIGN
F*(q, λ) = q
F*(q, xσ) = F(F*(q, x), σ )
G*(q, λ) = λ
G*(q, xσ) = G*(q, x) G(F*(q, x), σ )
This description is similar to the one used for Turing machines, except
that the motion is left unspecified, since it is implicitly one direction. In
lieu of the two functions F and G, a finite-state machine could be
specified by a single function combining F and G of the form:
116
CIT344 INTRODUCTION TO COMPUTER DESIGN
The sequences it accepts are those given by c(F*(q0, x)) = 1 that is, the
sequences x such that, when started in state q0, after reading x, the
machine is in a state q such that c(q) = 1. The set of all such x, since it is
a set of strings, is a language. If A designates a finite-state acceptor,
then L(A) = { x in Σ* | c(F*(q0, x)) = 1} is the language accepted by A.
Any finite state machine can be shown as a graph with a finite set of
nodes. The nodes correspond to the states. There is no other memory
implied other than the state shown. The start state is designated with an
arrow directed into the corresponding node, but otherwise unconnected.
118
CIT344 INTRODUCTION TO COMPUTER DESIGN
The arcs and nodes are labeled differently, depending on whether we are
representing a transducer, a classifier, or an acceptor. In the case of a
transducer, the arcs are labeled σ/δ as shown below, where σ is the
input symbol and δ is the output symbol. The state transition is
designated by virtue of the arrow going from one node to another.
In the case of a classifier, the arrow is labeled only with the input
symbol. The categories are attached to the names of the states after /.
119
CIT344 INTRODUCTION TO COMPUTER DESIGN
Transducer Example
Classifier Example
120
CIT344 INTRODUCTION TO COMPUTER DESIGN
Acceptor Example
Let us give an acceptor that accepts those strings with exactly one edge.
We can use the state transitions from the previous classifier. We need
only designate those states that categorise there being one edge as
accepting states and the others as rejecting states.
Fig. 15: Acceptor for Strings with Exactly One Edge. Accepting
States are d and e
Sequencer Example
121
CIT344 INTRODUCTION TO COMPUTER DESIGN
122
CIT344 INTRODUCTION TO COMPUTER DESIGN
SELF-ASSESSMENT EXERCISE
Write short notes with the aid of diagrams on the following terms: (a)
classifiers (b) acceptors (c) transducers (d) sequencers.
4.0 CONCLUSION
123
CIT344 INTRODUCTION TO COMPUTER DESIGN
5.0 SUMMARY
State in not less than 800 words, all you know about finite state
machines.
Comer, J. David (1994). Digital Logic & State Machine Design. Oxford
University Press.
124
CIT344 INTRODUCTION TO COMPUTER DESIGN
125
CIT344 INTRODUCTION TO COMPUTER DESIGN
MODULE 4 MEMORY
CONTENTS
1.0 Introduction
2.0 Objectives
3.0 Main Content
3.1 Memory Organisation
3.1.1 Memory Capacity & Density
3.1.2 Memory Signals & Basic Operations on Memory
3.1.2.1 Read & Write Signals
3.1.2.2 Address Signals
3.1.2.3 Data Signals
3.1.2.4 Memory Select or Enable Signal
3.1.2.5 Memory Read Operation
3.1.2.6 Memory Write Operation
4.0 Conclusion
5.0 Summary
6.0 Tutor-Marked Assignment
7.0 References/Further Reading
1.0 INTRODUCTION
126
CIT344 INTRODUCTION TO COMPUTER DESIGN
Memories store data in units that have one, four, eight or higher number
of bits.
Smallest unit of binary data is a bit. Data is also handled in a 4-bit unit
called a Nibble. In many applications the data is handled as an 8-bit unit
called a byte, which is a combination of two 4-bit units that are called
Nibbles. A complete unit of information is sometimes called a Word and
consists of one or more bytes.
2.0 OBJECTIVES
127
CIT344 INTRODUCTION TO COMPUTER DESIGN
A memory is identified by the number of units it can store times the unit
size. Thus, the 8 x 8 memory is identified as an 8 Byte memory, the 16 x
4 memory is used as a 16 Nibble memory and the 64 x 1 is known as a
64 bit memory. Practical memory chips are organised as 16 K x 8
memory, storing 16K bytes or 16 x 1024 = 16384 bytes. A 32 K x 4
memory stores 32K nibbles or 32 x 1024 = 32768 nibbles.
128
CIT344 INTRODUCTION TO COMPUTER DESIGN
unit area more dense the memory, that is, more bits are stored in less
space. The capacity and the density of a memory are determined by the
total number of cells implemented in a unit area.
Read/Write signals are required to configure the memory for read and
write operation. Memory chips have a single Read/Write signal. When
the signal is set to high it allows data to be read from the memory. When
the signal is set to low data is written into the memory. Some memory
chips have two separate Read and Write signals. The read and write
signals are separately asserted to control the Read and Write operation.
Address signals are required to specify the location in the memory from
which information is accessed (read or written). A set of parallel address
lines known as the address bus carry the address information. The
number of bits (lines) comprising the address bus depends upon the size
of the memory. For example, a memory having four locations to store
data has four unique addresses (00, 01, 10, 11) specified by a 2-bit
address bus. The size of the address bus depends upon the total
129
CIT344 INTRODUCTION TO COMPUTER DESIGN
Data lines are required to retrieve the information from the memory
array during a read operation and to provide the data that is to be stored
in the memory during a write operation. As the memory reads or writes
one data unit at a time therefore the data lines should be equal to the
number of data bits stored at each addressable location in the memory. A
memory organised as a byte memory reads or writes byte data values,
therefore the number of data lines or the size of the data bus should be 8-
bits or 1 byte. A memory organised to store nibble data values requires a
4-bit wide data bus. Generally, the wider the data bus more data can be
accessed at each read or write operation.
In a computer system there are more than one memory chips to store
program information. At any particular instant a read or write operation
is carried out on a single addressable location. The unique location can
only be accessed in one of the several memory chips; thus, a single
memory chip has to be selected before a read or write operation can be
carried out. All memory chips have a chip enable or chip select signal
which has to be activated before the memory can be accessed.
Memory Read operation is carried out by first selecting the memory chip
by activating the Memory Select signal. The Read signal is asserted to
configure the memory circuitry for reading data from the memory. An
address (100) is applied on the Address Lines. The internal address
decoder of the memory decodes the address and selects one unique row
from which data is read.
130
CIT344 INTRODUCTION TO COMPUTER DESIGN
The address of the location in the memory from which data is to be read
is supplied by the microprocessor. The microprocessor stores the
address in its address buffer. The data read from the memory is stored in
a data buffer inside the microprocessor. In the diagram shown, a
microprocessor places an address 100 on its external address bus
connected to the address lines of the memory. The internal address
decoder of the memory decodes the address 100 and activates a row
select line which selects the row location 4. The dat (00110001) at the
location is read from the memory and placed on the data bus where it is
latched by the microprocessor and stored in its data buffer.
131
CIT344 INTRODUCTION TO COMPUTER DESIGN
4.0 CONCLUSION
5.0 SUMMARY
132
CIT344 INTRODUCTION TO COMPUTER DESIGN
Comer, J. David (1994). Digital Logic & State Machine Design. Oxford
University Press.
133
CIT344 INTRODUCTION TO COMPUTER DESIGN
134
CIT344 INTRODUCTION TO COMPUTER DESIGN
CONTENTS
1.0 Introduction
2.0 Objectives
3.0 Main Content
3.1 Memory Types
3.1.1 Random Access Memory
3.1.1.1 Static Ram
3.1.1.2 Dynamic Ram
3.1.1.3 Types of Drams
3.1.2 Read Only Memory
3.1.2.1 Rom Application
3.1.3 Flash Memory
3.1.3.1 Flash Memory Operations
4.0 Conclusion
5.0 Summary
6.0 Tutor-Marked Assignment
7.0 References/Further Reading
1.0 INTRODUCTION
2.0 OBJECTIVES
Two major categories of memory chips are the Random Access Memory
(RAM) and Read-Only Memory (ROM).
135
CIT344 INTRODUCTION TO COMPUTER DESIGN
RAM memories are also known as volatile memories as they lose data
when the power is turned off.
ROM chips retain data permanently even if the power to a ROM chip is
turned off. ROM chips are also known as non-volatile memory chips
due to their ability to retain data permanently. Since ROM chips are read
only, therefore user cannot write any information to ROM chips. ROM
chips are programmed by the manufacturer and contain important
information which is required to start (Boot Up) the computer.
RAM is divided into two types, Static RAM which uses flip-flops as
storage elements and Dynamic RAM which uses capacitors to store
binary information. In a Static RAM each cell which is capable of
storing a binary 0 or 1 is made up of a flip-flop which retains
information as long as power continues to be supplied to the flip-flop.
Dynamic RAM on the other hand uses a capacitor to store a single bit of
data. To store binary 1, the capacitor is charged and to store binary 0, the
capacitor is in the uncharged state. Capacitors over a period of time lose
their charge and unless the capacitors are refreshed the information
stored by the capacitor is lost. Dynamic memories periodically charge
their capacitors by implementing a refresh cycle. Static memories are
faster than Dynamic memories therefore data access in Static memories
is faster as compared to dynamic memories. Dynamic memories on the
other hand have a high density and can store much more data per unit
area and at a lesser cost. Dynamic memories have a high storage density,
as capacitors are simpler to implement and occupy a very small
semiconductor area as compared to flip-flops.
136
CIT344 INTRODUCTION TO COMPUTER DESIGN
The flip-flop used to store a binary bit works like a latch. When the SEL
signal is activated, the output buffer is enabled allowing data to be read
out from the memory cell. When both the SEL and W(rite) signals are
activated the latch is configured in the transparent mode and the data
applied at the Data In line flows through the latch to the output. The
Data In and Data Out lines can be connected together to form a bi-
directional line which does not cause any problems with the reading or
writing of data. This is possible as the read and write operations takes
place at different time intervals. The flip-flop based cells are combined
to form an array. Additional logic is added to select cells at appropriate
locations and to read and write data. A 3 x 8 decoder decodes a 3-bit
address to select any one of the eight locations comprising of a group of
4-cells. For example, when the address is 000, the first output line of the
3 x 8 decoder is activated which is connected to the SEL input of the
four latches in the first row.
To write data 1001 at the 6th memory location, the address A2, A1 and
A0 bits are set to 110 which select the 6th row of the memory array. The
data 1001 is placed at the four Data In lines respectively. The CS and W
137
CIT344 INTRODUCTION TO COMPUTER DESIGN
signals are activated which set the four latches in the sixth row to
transparent mode allowing data 1001 applied at the four Data In lines to
be available at the Q outputs of the four latches respectively. As soon as
the CS and W signals are deactivated, the latches store the data value. A
16K x 8 memory is shown. The memory is capable of storing byte
values in 16 x 1024 locations. To address these unique locations,
fourteen address lines are required. The memory has eight bi-directional
data lines through which data is read/written at selected memory
locations. The three CS, WE and OE are shown to be active low.
138
CIT344 INTRODUCTION TO COMPUTER DESIGN
139
CIT344 INTRODUCTION TO COMPUTER DESIGN
A static RAM uses a latch to store a single bit of information. Four gates
are used to implement a latch. In terms of transistors, 4 to 6 transistors
are required to implement a single storage cell. In order to build
memories with higher densities, a single transistor is used to store a
binary value. A single transistor cannot store a binary value however it
is used to charge and discharge a capacitor. A single memory cell is thus
implemented using a single transistor and a capacitor which occupy
lesser space as compared to the six transistors which are used to
implement a single Static RAM cell. Thus, the density of the capacitor
based memory is significantly increased. The capacitor based memory is
known as a Dynamic RAM (DRAM). The drawback of DRAM is the
discharging of the capacitor over a period of time. Unless the capacitor
is periodically recharged all the information stored in terms of binary
bits in a capacitor based memory array is lost. The extra circuitry
required to refresh the capacitor complicates the operation of the
DRAM. The circuit diagram of a single DRAM capacitor based memory
cell is shown. The capacitor is connected through a MOSFET which
connects or disconnects the column line at B to the capacitor at D. If the
row is set at logic high the MOSFET connects the column line to the
capacitor. If the row line is set to logic low the MOSFET disconnects
the column line form the capacitor.
140
CIT344 INTRODUCTION TO COMPUTER DESIGN
141
CIT344 INTRODUCTION TO COMPUTER DESIGN
142
CIT344 INTRODUCTION TO COMPUTER DESIGN
143
CIT344 INTRODUCTION TO COMPUTER DESIGN
144
CIT344 INTRODUCTION TO COMPUTER DESIGN
FLASH memories have high density, that is, they store more
information per unit area as more storage cells are implemented per unit
area. These memories have read/write capability and are non-volatile
and can store data for indefinite time period. The high density FLASH
memory cell is implemented using a single floating-gate MOS transistor.
A data bit is stored as a charge (logic 0) or the absence of a charge (logic
1) on the floating gate. The amount of charge present o the floating gate
determines if the transistor will turn and conduct current from the drain
to the source when a control voltage is applied at the Control rate during
the read operation.
145
CIT344 INTRODUCTION TO COMPUTER DESIGN
• Programming Operation
• Read Operation
• Erase Operation
Programming Operation
Initially, all cells are at the logic 1 state - that is with no charge. The
programming operation adds charge to the floating gate of those cells
that are to store a logic 0. No charge is added to those gates that are to
store logic 1. The charges are stored by applying a positive voltage at
the Control Gate with respect to the Source which attracts electrons to
the floating gate. Once the gate is charged it retains the charge for years.
Read Operation
Erase Operation
During the erase operation charge is removed from the memory cell. A
sufficiently large positive voltage is applied at the source with respect to
the control gate. The voltage applied across the control gate and source
is opposite to the voltage applied during programming. If charges are
present on the gate, the positive voltage supply at the source attracts the
electrons depleting the gate. A flash memory is erased prior to
programming.
4.0 CONCLUSION
Two major categories of memory chips are the Random Access Memory
(RAM) and Read-Only Memory (ROM). RAM allows a read or write
operation to be carried out at any address. All locations are accessible in
equal time. RAM memories do not store permanent data. As soon as the
power supply to the memory chip is turned off, the entire data stored in
the memory is lost permanently.
ROM chips retain data permanently even if the power to a ROM chip is
turned off.
RAM is divided into two types, Static RAM which uses flip-flops as
storage elements and Dynamic RAM which uses capacitors to store
binary information.
Static Memories are faster than Dynamic memories therefore data access
in Static Memories is faster as compared to Dynamic Memories.
Dynamic memories on the other hand have a high density and can store
much more data per unit area and at a lesser cost. ROMs are of different
types: Mask ROM, PROM, EPROM, UV EPROM & EEPROM.
FLASH memories have high density, that is, they store more
information per unit area as more storage cells are implemented per unit
area.
SELF-ASSESSMENT EXERCISE
147
CIT344 INTRODUCTION TO COMPUTER DESIGN
5.0 SUMMARY
Comer, J. David (1994). Digital Logic & State Machine Design. Oxford
University Press.
148
CIT344 INTRODUCTION TO COMPUTER DESIGN
149
CIT344 INTRODUCTION TO COMPUTER DESIGN
CONTENTS
1.0 Introduction
2.0 Objectives
3.0 Main Content
3.1 Memory Expansion
4.0 Conclusion
5.0 Summary
6.0 Tutor-Marked Assignment
7.0 References/Further Reading
1.0 INTRODUCTION
2.0 OBJECTIVES
Memory, both RAM and ROM are implemented in fixed data unit sizes
of 1, 4 or 8 bits. Similarly, these memory devices are implemented
having sizes in terms of total addressable locations which are restricted
to address ranges between few hundred kilobytes to megabytes.
151
CIT344 INTRODUCTION TO COMPUTER DESIGN
Another important aspect of the RAM and ROM memories that are
manufactured are the addresses of each memory location. For example,
two 32Kbyte RAM chips have 215 locations each. The first addressable
locations in both the RAM chips have an address 0. Similarly, the
second and third locations in both the memory chips have addresses 1
and 2 respectively. If the two RAM chips are connected together to form
a 64 Kbyte RAM then one of 32Kbyte memory chips should respond to
the address between 0 and 32767 and the other 32Kbyte memory chip
should respond to the address 32768 and 65535. The two memory chips
have bases address 0 and 32768 respectively.
4.0 CONCLUSION
5.0 SUMMARY
In this unit we talked about ways and reasons why we should expand
our memory.
Comer, J. David (1994). Digital Logic & State Machine Design. Oxford
University Press.
152
CIT344 INTRODUCTION TO COMPUTER DESIGN
153
CIT344 INTRODUCTION TO COMPUTER DESIGN
CONTENTS
1.0 Introduction
2.0 Objectives
3.0 Main Content
3.1 Memory Summary
4.0 Conclusion
5.0 Summary
6.0 Tutor-Marked Assignment
7.0 References/Further Reading
1.0 INTRODUCTION
This unit summarises all that we have talked about memory. It does it in
a clear and concise manner for easy understanding.
2.0 OBJECTIVES
define memory
list the different memory types.
154
CIT344 INTRODUCTION TO COMPUTER DESIGN
SELF-ASSESSMENT EXERCISE
Mention five memory types you know and give five differences among
them.
4.0 CONCLUSION
5.0 SUMMARY
This unit summarises the various memory types. The Static Ram
(SRAM) is non-volatile and is not a high density memory as a latch is
required to store a single bit of information.
Comer, J. David (1994). Digital Logic & State Machine Design. Oxford
University Press.
155
CIT344 INTRODUCTION TO COMPUTER DESIGN
156
CIT344 INTRODUCTION TO COMPUTER DESIGN
MODULE 5 INTRODUCTION TO
MICROPROCESSORS
Unit 1 Microprocessors
Unit 2 Central Processing Unit & Arithmetic and Logical Unit
Unit 3 Addressing Mode
UNIT 1 MICROPROCESSORS
CONTENTS
1.0 Introduction
2.0 Objectives
3.0 Main Content
3.1 Microprocessors
3.1.1 Microprocessor History
3.1.2 Microprocessor Design
3.1.3 Microprocessor Speed
3.1.4 Microprocessor Architecture
4.0 Conclusion
5.0 Summary
6.0 Tutor-Marked Assignment
7.0 References/Further Reading
1.0 INTRODUCTION
2.0 OBJECTIVES
define microprocessors
state the history of microprocessors
explain their architecture, speed and design.
157
CIT344 INTRODUCTION TO COMPUTER DESIGN
3.1 Microprocessors
The first microprocessor to make it into a home computer was the Intel
8080, a complete 8-bit computer on one chip, introduced in 1974. The
first microprocessor to make a real splash in the market was the Intel
8088, introduced in 1979 and incorporated into the IBM PC (which first
appeared around 1982). If you are familiar with the PC market and its
history, you know that the PC market moved from the 8088 to the 80286
to the 80386 to the 80486 to the Pentium to the Pentium II to the
Pentium III to the Pentium 4. All of these microprocessors are made by
Intel and all of them are improvements on the basic design of the 8088.
The Pentium 4 can execute any piece of code that ran on the original
8088, but it does it about 5,000 times faster!
The following table helps you to understand the differences between the
different processors that Intel has introduced over the years.
158
CIT344 INTRODUCTION TO COMPUTER DESIGN
Microprocessor Components
1. Execution unit
2. Branch predictor
The branch predictor attempts to guess where the program will jump (or
branch) next, allowing the prefetch and decode unit to retrieve
159
CIT344 INTRODUCTION TO COMPUTER DESIGN
3. Floating-point unit
4. Primary cache
5. Bus interfaces
160
CIT344 INTRODUCTION TO COMPUTER DESIGN
Clock speeds increase every year, but the laws of physics limit how fast
CPUs can run. If designers depended only on faster clock speeds for
better performance, CPU performance would have hit the wall years
ago. Instead, designers have improved internal architectures while also
increasing clock speeds. Recent CPUs run at more than 650 times the
clock speed of the PC/XT’s 8088 processor, but provide 6,500 or more
times the performance. Here are some major architectural improvements
that have allowed CPUs to continue to get faster every year:
For a given clock speed, the amount of work done depends on the
amount of data processed in one operation. Early CPUs processed data
in 4-bit (nibble) or 8-bit (byte) chunks, whereas current CPUs process 32
or 64 bits per operation.
FPUs
Pipelining
161
CIT344 INTRODUCTION TO COMPUTER DESIGN
Superscalar architecture
If one pipeline is good, more are better. Using multiple pipelines allows
multiple instructions to be processed in parallel, an architecture called
superscalar. A superscalar processor processes multiple instructions per
tick.
SELF-ASSESSMENT EXCERCISE
4.0 CONCLUSION
5.0 SUMMARY
162
CIT344 INTRODUCTION TO COMPUTER DESIGN
Comer, J David (1994). Digital Logic & State Machine Design. Oxford
University Press.
163
CIT344 INTRODUCTION TO COMPUTER DESIGN
164
CIT344 INTRODUCTION TO COMPUTER DESIGN
CONTENTS
1.0 Introduction
2.0 Objectives
3.0 Main Content
3.1 Central Processing Unit &Arithmetic and Logical Unit
3.1.1 Central Processing Unit
3.1.2 CPU Registers
3.1.3 Polling Loops and Interrupts
3.1.4 Arithmetic & Logical Unit
4.0 Conclusion
5.0 Summary
6.0 Tutor-Marked Assignment
7.0 References/Further Reading
1.0 INTRODUCTION
This unit exposes us to the Central Processing Unit and the Arithmetic
& Logical Unit.
2.0 OBJECTIVES
165
CIT344 INTRODUCTION TO COMPUTER DESIGN
166
CIT344 INTRODUCTION TO COMPUTER DESIGN
CPU registers are very special memory locations constructed from flip-
flops. They are not part of main memory; the CPU implements them on-
chip. Various members of the 80 x 86 family have different register
sizes. The 886, 8286, 8486, and 8686 (x86 from now on) CPUs have
exactly four registers, all 16 bits wide. All arithmetic and location
operations occur in the CPU registers.
Because the x86 processor has so few registers, we'll give each register
its own name and refer to it by that name rather than its address. The
names for the x86 registers are:
Besides the above registers, which are visible to the programmer, the
x86 processors also have an instruction pointer register which contains
the address of the next instruction to execute. There is also a flags
register that holds the result of a comparison. The flags register
remembers if one value was less than, equal to, or greater than another
value.
167
CIT344 INTRODUCTION TO COMPUTER DESIGN
Because registers are on-chip and handled specially by the CPU, they
are much faster than memory. Accessing a memory location requires
one or more clock cycles. Accessing data in a register usually takes zero
clock cycles. Therefore, you should try to keep variables in the registers.
Register sets are very small and most registers have special purposes
which limit their use as variables, but they are still an excellent place to
store temporary data.
SELF-ASSESSMENT EXCERCISE
The CPU spends almost all its time fetching instructions from memory
and executing them. However, the CPU and main memory are only two
out of many components in a real computer system. A complete system
contains other devices such as:
A hard disk for storing programs and data files. (Note that main
memory holds only a comparatively small amount of information,
and holds it only as long as the power is turned on. A hard disk is
necessary for permanent storage of larger amounts of
information, but programs have to be loaded from disk into main
memory before they can actually be executed.)
A keyboard and mouse for user input.
A monitor and printer which can be used to display the
computer's output.
A network interface that allows the computer to communicate
with other computers that are connected to it on a network.
A scanner that converts images into coded binary numbers that
can be stored and manipulated on the computer.
The list of devices is entirely open ended, and computer systems are
built so that they can easily be expanded by adding new devices.
Somehow the CPU has to communicate with and control all these
devices. The CPU can only do this by executing machine language
instructions (which is all it can do, period). So, for each device in a
system, there is a device driver, which consists of software that the CPU
executes when it has to deal with the device. Installing a new device on
a system generally has two steps: plugging the device physically into the
168
CIT344 INTRODUCTION TO COMPUTER DESIGN
computer, and installing the device driver software. Without the device
driver, the actual physical device would be useless, since the CPU would
not be able to communicate with it.
169
CIT344 INTRODUCTION TO COMPUTER DESIGN
170
CIT344 INTRODUCTION TO COMPUTER DESIGN
Not all computers can "forcibly" suspend a thread in this way; those that
can are said to use preemptive multitasking. To do preemptive
multitasking, a computer needs a special timer device that generates an
interrupt at regular intervals, such as 100 times per second. When a
timer interrupt occurs, the CPU has a chance to switch from one thread
to another, whether the thread that is currently running likes it or not.
By the way, the software that does all the interrupt handling and the
communication with the user and with hardware devices is called the
operating system. The operating system is the basic, essential software
without which a computer would not be able to function. Other
programs, such as word processors and World Wide Web browsers, are
dependent upon the operating system. Common operating systems
include UNIX, DOS, Windows, and the Macintosh OS.
The Arithmetic and Logical Unit (ALU) is where most of the action
takes place inside the CPU. Microprocessors have Arithmetic and Logic
Units, a combinational circuit that can perform any of the arithmetic
operations and logic operations on two input values. The operation to be
performed is selected by set of inputs known as function select inputs.
There are different MSI ALUs available that have two 4-bit inputs a 4-
bit output and three to five function select inputs that allows up to 32
different functions to be performed.
171
CIT344 INTRODUCTION TO COMPUTER DESIGN
• 74XX181: The 4-bit ALU has five function select inputs allowing
it to perform 32 different Arithmetic and Logic operations.
• 74XX381: The 4-bit ALU only has three function select inputs
allowing only 8 different arithmetic and logic functions.
• 74XX382: The 4-bit ALU is similar to the 74XX381, the only
difference is that 74XX 381 provides group-carry look-ahead
outputs and 74XX382 provides ripple carry and overflow outputs
4.0 CONCLUSION
The Arithmetic and Logical Unit (ALU) is where most of the action
takes place inside the CPU. Microprocessors have Arithmetic and Logic
Units, a combinational circuit that can perform any of the arithmetic
operations and logic operations on two input values.
5.0 SUMMARY
This unit talks extensively on Central Processing Unit and Arithmetic &
Logical Unit of a computer system.
172
CIT344 INTRODUCTION TO COMPUTER DESIGN
Comer, J David (1994). Digital Logic & State Machine Design. Oxford
University Press.
173
CIT344 INTRODUCTION TO COMPUTER DESIGN
174
CIT344 INTRODUCTION TO COMPUTER DESIGN
CONTENTS
1.0 Introduction
2.0 Objectives
3.0 Main Content
3.1 Addressing Modes
3.1.1 Register Addressing Mode
3.1.2 Memory Addressing Mode
3.1.3 The Displacement Only Addressing Mode
3.1.4 Register Indirect Addressing Mode
3.1.5 Indexed Addressing Mode
3.1.6 Based Index Addressing Mode
3.1.7 80386 Scaled Indexed Addressing Mode
4.0 Conclusion
5.0 Summary
6.0 Tutor-Marked Assignment
7.0 References/Further Reading
1.0 INTRODUCTION
2.0 OBJECTIVES
Most 80386 instructions can operate on the general purpose register set.
By specifying the name of the register as an operand to the instruction,
175
CIT344 INTRODUCTION TO COMPUTER DESIGN
you may access the contents of that register. Consider the mov (move)
instruction:
mov eax, ebx; Copies the value from EBX into EAX
mov edl, eal ; Copies the value from EAL into EDL
mov esi,edx ; Copies the value from EDX into ESI
mov esp, ebp; Copies the value from EBP into ESP
mov edh, ecx; Copies the value from ECX into EDH
mov eax, eax ;Yes, this is legal!
Remember, the registers are the best place to keep often used variables.
Instructions using the registers are shorter and faster than those that
access memory.
You should never use the segment registers as data registers to hold
arbitrary values. They should only contain segment addresses.
176
CIT344 INTRODUCTION TO COMPUTER DESIGN
The most common addressing mode, and the one that's easiest to
understand, is the displacement-only (or direct) addressing mode. The
displacement-only addressing mode consists of a 16 bit constant that
specifies the address of the target location. The instruction mov
al,ds:[8088h] loads the al register with a copy of the byte at memory
location 8088h. Likewise, the instruction mov ds:[1234h],dl stores the
value in the dl register to memory location 1234h:
177
CIT344 INTRODUCTION TO COMPUTER DESIGN
The 80x86 CPUs let you access memory indirectly through a register
using the register indirect addressing modes. There are four forms of this
addressing mode on the 8086, best demonstrated by the following
instructions:
As with the x86 [bx] addressing mode, these four addressing modes
reference the byte at the offset found in the bx, bp, si, or di register,
respectively. The [bx], [si], and [di] modes use the ds segment by
default. The [bp] addressing mode uses the stack segment (ss) by
default.
178
CIT344 INTRODUCTION TO COMPUTER DESIGN
You can use the segment override prefix symbols if you wish to access
data in different segments. The following instructions demonstrate the
use of these overrides:
Intel refers to [bx] and [bp] as base addressing modes and bx and bp as
base registers (in fact, bp stands for base pointer). Intel refers to the [si]
and [di] addressing modes as indexed addressing modes (si stands for
source index, di stands for destination index). However, these
addressing modes are functionally equivalent. This text will call these
forms register indirect modes to be consistent.
Note: the [si] and [di] addressing modes work exactly the same way, just
substitute si and di for bx above.
On the 80386 you may specify any general purpose 32 bit register when
using the register indirect addressing mode. [eax], [ebx], [ecx], [edx],
179
CIT344 INTRODUCTION TO COMPUTER DESIGN
[esi], and [edi] all provide offsets, by default, into the data segment. The
[ebp] and [esp] addressing modes use the stack segment by default.
Note that while running in 16 bit real mode on the 80386, offsets in
these 32 bit registers must still be in the range 0...0FFFFh. You cannot
use values larger than this to access more than 64K in a segment. Also
note that you must use the 32 bit names of the registers. You cannot use
the 16 bit names. The following instructions demonstrate all the legal
forms:
The offsets generated by these addressing modes are the sum of the
constant and the specified register. The addressing modes involving bx,
si, and di all use the data segment, the disp[bp] addressing mode uses the
stack segment by default. As with the register indirect addressing
modes, you can use the segment override prefixes to specify a different
segment:
180
CIT344 INTRODUCTION TO COMPUTER DESIGN
Note that Intel still refers to these addressing modes as based addressing
and indexed addressing. Intel's literature does not differentiate between
these modes with or without the constant. If you look at how the
hardware works, this is a reasonable definition. From the programmer's
point of view, however, these addressing modes are useful for entirely
different things.
181
CIT344 INTRODUCTION TO COMPUTER DESIGN
The addressing modes that do not involve bp use the data segment by
default. Those that have bp as an operand use the stack segment by
default.
You substitute di in the figure above for the [bp+di] addressing mode.
182
CIT344 INTRODUCTION TO COMPUTER DESIGN
183
CIT344 INTRODUCTION TO COMPUTER DESIGN
bits long when operating in real mode. On the 80386 the terms base
register and index register actually take on some meaning. When
combining two 32 bit registers in an addressing mode, the first register
is the base register and the second register is the index register. This is
true regardless of the register names. Note that the 80386 allows you to
use the same register as both a base and index register, which is actually
useful on occasion. The following instructions provide representative
samples of the various base and indexed address modes along with
syntactical variations:
184
CIT344 INTRODUCTION TO COMPUTER DESIGN
There is one restriction the 80386 places on the index register. You
cannot use the esp register as an index register. It's okay to use esp as the
base register, but not as the index register.
disp[index*n]
[base][index*n]
or
disp[base][index*n]
where "base" and "index" represent any 80386 32 bit general purpose
registers and "n" is the value one, two, four, or eight.
The 80386 computes the effective address by adding disp, base, and
index*n together. For example, if ebx contains 1000h and esi contains 4,
then
185
CIT344 INTRODUCTION TO COMPUTER DESIGN
4.0 CONCLUSION
Not all addressing modes are created equal! Different addressing modes
may take differing amounts of time to compute the effective address.
The exact difference varies from processor to processor. Generally,
though, the more complex an addressing mode is, the longer it takes to
compute the effective address. Complexity of an addressing mode is
directly related to the number of terms in the addressing mode.
5.0 SUMMARY
In this unit, we discussed addressing modes, their various types and how
they are used.
Comer, J. David (1994). Digital Logic & State Machine Design. Oxford
University Press.
186
CIT344 INTRODUCTION TO COMPUTER DESIGN
187
CIT344 INTRODUCTION TO COMPUTER DESIGN
CONTENTS
1.0 Introduction
2.0 Objectives
3.0 Main Content
3.1 Learning to Program with Assembly Language
3.1.1 Availability
3.1.2 Why Learn Assembly Language
3.1.3 Assembly Language Statements
3.1.4 Assembly Language Structure
3.1.5 Using Debug Program
3.1.6 Creating Basic Assembly Programs
3.1.7 Building Assembly Language Programs
3.1.8 Assembly Language Programming
3.1.9 Assembly Process
4.0 Conclusion
5.0 Summary
6.0 Tutor-Marked Assignment
7.0 References/Further Reading
1.0 INTRODUCTION
188
CIT344 INTRODUCTION TO COMPUTER DESIGN
Each type of CPU has its own machine language and assembly
language, so an assembly language program written for one type of CPU
won’t run on another. In the early days of programming, all programs
were written in assembly language. Now, most programs are written in
high-level language. Programmers still use assembly language when
speed is essential or when they need to perform an operation that isn't
possible in a high-level language.
2.0 OBJECTIVES
3.1.1 Availability
Assemblers are available for just about every processor ever made.
Native assemblers produce object code on the same hardware that the
object code will run on. Cross assemblers produce object code on
different hardware that the object code will run on.
The second reason is the total control of the PC which you can have
with the use of the assembler.
189
CIT344 INTRODUCTION TO COMPUTER DESIGN
Another reason is that the assembly programs are quicker, smaller, and
have larger capacities than ones created with other languages.
Each entity above is a field. The four fields above are the label field, the
mnemonic field, the operand field, and the comment field.
190
CIT344 INTRODUCTION TO COMPUTER DESIGN
The comment field allows you to annotate each line of source code in
your program. Note that the comment field always begins with a
semicolon. When the assembler is processing a line of text, it completely
ignores everything on the source line following a semicolon.
Each assembly language statement appears on its own line in the source
file. You cannot have multiple assembly language statements on a single
line. On the other hand, since all the fields in an assembly language
statement are optional, blank lines are fine. You can use blank lines
anywhere in your source file. Blank lines are useful for spacing out
certain sections of code, making them easier to read.
mov ax, 0
mov bx, ax
add ax, dx
mov cx, ax
mov ax, 0
mov bx, ax
add ax, dx
mov cx, ax
The first code sequence is much easier to read than the second. With
respect to readability, the judicial use of spacing within your program
can make all the difference in the world.
You may have a comment on the line by itself. In such a case, place the
semicolon in column one and use the entire line for the comment,
examples:
191
CIT344 INTRODUCTION TO COMPUTER DESIGN
mov X, 0
mov Y, 0
; Now clear from the current cursor position to the end of the
; screen to clear the video display:
; etc.
In assembly language code lines have two parts, the first one is the name
of the instruction which is to be executed, and the second one are the
parameters of the command. For example: add ah bh
In the above example, we are using the instruction mov, it means move
the value 25 to al register.
192
CIT344 INTRODUCTION TO COMPUTER DESIGN
other words, the written program as a sequence of zeros and ones that
can be interpreted by the processor. Test the program, after the
translation the program into machine language, execute the program in
the computer machine. The last stage is the elimination of detected
faults on the program on the test stage. The correction of a fault
normally requires the repetition of all the steps from the first or second.
Debug Program
Debug can only create files with a .COM extension, and because of the
characteristics of these kinds of programs they cannot be larger than 64
kb, and they also must start with displacement, offset, or 0100H memory
direction inside the specific segment.
C:/>Debug [Enter]
On the next line a dash will appear, this is the indicator of Debug, at this
moment the instructions of Debug can be introduced using the following
command:
-r[Enter]
193
CIT344 INTRODUCTION TO COMPUTER DESIGN
All the contents of the internal registers of the CPU are displayed; an
alternative of viewing them is to use the "r" command using as a
parameter the name of the register whose value wants to be seen. For
example:
-rbx
BX 0000
:
This instruction will only display the content of the BX register and the
Debug indicator changes from "-" to ":"
When the prompt is like this, it is possible to change the value of the
register which was seen by typing the new value and [Enter], or the old
value can be left by pressing [Enter] without typing any other value.
The first step is to initiate the Debug, this step only consists of typing
debug [Enter] on the operative system prompt.
Even though at this moment it is not necessary to give the "a" command
a parameter, it is recommendable to do so to avoid problems once the
CS:IP registers are used, therefore we type:
a 100[enter]
mov ax,0002[enter]
mov bx,0004[enter]
add ax,bx[enter]
nop[enter][enter]
194
CIT344 INTRODUCTION TO COMPUTER DESIGN
What does the program do?, move the value 0002 to the ax register,
move the value 0004 to the bx register, add the contents of the ax and bx
registers, the instruction, no operation, to finish the program.
After to do this, appear on the screen some like the follow lines:
C:\>debug
-a 100
0D62:0100 mov ax,0002
0D62:0103 mov bx,0004
0D62:0106 add ax,bx
0D62:0108 nop
0D62:0109
-t
AX=0002 BX=0000 CX=0000 DX=0000 SP=FFEE BP=0000 SI=0000
DI=0000
You see that the value 2 move to AX register. Type the command "t"
(trace), again, and you see the second instruction is executed.
-t
AX=0002 BX=0004 CX=0000 DX=0000 SP=FFEE BP=0000 SI=0000
DI=0000
Type the command "t" (trace) to see if the instruction add is executed,
you will see the follow lines:
-t
AX=0006 BX=0004 CX=0000 DX=0000 SP=FFEE BP=0000 SI=0000
DI=0000
195
CIT344 INTRODUCTION TO COMPUTER DESIGN
0D62:0108 90 NOP
The possibility that the registers contain different values exists, but AX
and BX must be the same, since they are the ones we just modified.
Obtain the length of the program subtracting the final address from the
initial address, naturally in hexadecimal system. Give the program a
name and extension. Put the length of the program on the CX register.
Order Debug to write the program on the disk.
To obtain the length of a program the "h" command is used, since it will
show us the addition and subtraction of two numbers in hexadecimal. To
obtain the length of ours, we give it as parameters the value of our
program's final address (10A), and the program's initial address (100).
The first result the command shows us is the addition of the parameters
and the second is the subtraction.
-h 10a 100
020a 000a
196
CIT344 INTRODUCTION TO COMPUTER DESIGN
-n test.com
-rcx
CX 0000
:000a
Lastly, the "w" command writes our program on the disk, indicating
how many bytes it wrote.
-w
Writing 000A bytes
To obtain the correct result of the following steps, it is necessary that the
above program be already created.
The last "u" command is used to verify that the program was loaded on
memory. What it does is that it disassembles the code and shows it
disassembled. The parameters indicate to Debug from where and to
where to disassemble.
197
CIT344 INTRODUCTION TO COMPUTER DESIGN
The editor can be any text editor at hand, and as a compiler we will use
the TASM macro assembler from Borland, and as a linker we will use
the Tlink program.
.MODEL SMALL
Assembler directive that defines the memory model to use in the
program
.CODE
Assembler directive that defines the program instructions
.STACK
Assembler directive that reserves a memory space for program
instructions
in the stack
END
Assembler directive that finishes the assembler program
Let's program
198
CIT344 INTRODUCTION TO COMPUTER DESIGN
First Step
use any editor program to create the source file. Type the following
lines:
first example
; use ; to put comments in the assembler program
.MODEL SMALL; memory model
.STACK; memory space for program instructions in the stack
.CODE; the following lines are program instructions
mov ah,1h; moves the value 1h to register ah
mov cx,07h;moves the value 07h to register cx
int 10h;10h interruption
mov ah,4ch;moves the value 4 ch to register ah
int 21h;21h interruption
END; finishes the program code
Second Step
Save the file with the following name: examp1.asm Don't forget to save
this in ASCII format.
Third Step
The TASM can only create programs in .OBJ format, which are not
executable by themselves, but rather it is necessary to have a linker
which generates the executable code.
199
CIT344 INTRODUCTION TO COMPUTER DESIGN
Fourth Step
Turbo Link Version 3.0 Copyright (c) 1987, 1990 Borland International
C:\>
Fifth Step
Another example
First Step
use any editor program to create the source file. Type the following
lines:
;example11
.model small
.stack
.code
mov ah,2h ;moves the value 2h to register ah
mov dl,2ah ;moves de value 2ah to register dl
;(Its the asterisk value in ASCII format)
int 21h ;21h interruption
mov ah,4ch ;4ch function, goes to operating system
int 21h ;21h interruption
end ;finishes the program code
Second Step
200
CIT344 INTRODUCTION TO COMPUTER DESIGN
Third Step
Fourth Step
Fifth Step
Segments
201
CIT344 INTRODUCTION TO COMPUTER DESIGN
of memory, which is, in the present day, more memory than what we
will see installed in a PC.
The assembler adjusts the size of the segments taking as a base the
number of bytes each assembled instruction needs, since it would be a
waste of memory to use the whole segments. For example, if a program
only needs 10kb to store data, the data segment will only be of 10kb and
not the 64kb it can handle.
Symbols Chart
Each one of the parts on code line in assembler is known as token, for
example on the code line:
MOV AX,Var
We have three tokens, the MOV instruction, the AX operator, and the
VAR operator. What the assembler does to generate the OBJ code is to
read each one of the tokens and look for it on an internal "equivalence"
chart known as the reserved words chart, which is where all the
mnemonic meanings we use as instructions are found. Following this
process, the assembler reads MOV, looks for it on its chart and identifies
it as a processor instruction. Likewise it reads AX and recognises it as a
register of the processor, but when it looks for the Var token on the
reserved words chart, it does not find it, so then it looks for it on the
symbols chart which is a table where the names of the variables,
constants and labels used in the program where their addresses on
memory are included and the sort of data it contains, are found.
Sometimes the assembler comes on a token which is not defined on the
202
CIT344 INTRODUCTION TO COMPUTER DESIGN
SELF-ASSESSMENT EXERCISE
4.0 CONCLUSION
Assemblers are available for just about every processor ever made.
Native assemblers produce object code on the same hardware that the
object code will run on. Cross assemblers produce object code on
different hardware that the object code will run on.
The second reason is the total control of the PC which you can have
with the use of the assembler. Another reason is that the assembly
programs are quicker, smaller, and have larger capacities than ones
created with other languages. Lastly, the assembler allows an ideal
optimisation in programs, be it on their size or on their execution.
Each assembly language statement appears on its own line in the source
file. You cannot have multiple assembly language statements on a single
line.
In assembly language, code lines have two parts, the first one is the
name of the instruction which is to be executed, and the second one are
the parameters of the command.
203
CIT344 INTRODUCTION TO COMPUTER DESIGN
program. And third, a linker that generates the executable program from
the object program.
5.0 SUMMARY
In this unit we introduced assembly languages, what they are and how to
write programs using assembly language.
www.cs.siu.edu
www.educypedia.be/electronics
www.books.google.com
204
CIT344 INTRODUCTION TO COMPUTER DESIGN
CONTENTS
1.0 Introduction
2.0 Objectives
3.0 Main Content
3.1 Branching Loops & Subroutines
3.1.1 Types of Instruction
3.1.2 Jumps, Loops and Procedure
3.1.3 Program Flow Control Instructions
4.0 Conclusion
5.0 Summary
6.0 Tutor-Marked Assignment
7.0 References/Further Reading
1.0 INTRODUCTION
2.0 OBJECTIVES
Data Movement
In any program it is necessary to move the data in the memory and in the
CPU registers; there are several ways to do this: it can copy data in the
memory to some register, from register to register, from a register to a
stack, from a stack to a register, to transmit data to external devices as
well as vice versa.
205
CIT344 INTRODUCTION TO COMPUTER DESIGN
To move data there are also structures called batteries, where the data is
introduced with the push instruction and are extracted with the pop
instruction.
In a stack the first data to be introduced is the last one we can take, this
is, if in our program we use these instructions:
PUSH AX
PUSH BX
PUSH CX
POP CX
POP BX
POP AX
For the communication with external devices the out command is used
to send information to a port and the in command to read the
information received from a port.
OUT DX,AX
Where DX contains the value of the port which will be used for the
communication and AX contains the information which will be sent.
IN AX,DX
206
CIT344 INTRODUCTION TO COMPUTER DESIGN
The instructions discussed thus far execute sequentially; that is, the CPU
executes each instruction in the sequence it appears in your program. To
write real programs requires several control structures, not just the
sequence. Examples include the if statement, loops, and subroutine
invocation (a call). Since compilers reduce all other languages to
assembly language, it should come as no surprise that assembly
language supports the instructions necessary to implement these control
structures. 80x86 program control instructions belong to three groups:
unconditional transfers, conditional transfers, and subroutine call and
return instructions. The following sections describe these instructions:
1. Unconditional Jumps
For example, the following short little loop continuously reads the
parallel printer data port and inverts the L.O. bit. This produces a square
wave electrical signal on one of the printer port output lines:
207
CIT344 INTRODUCTION TO COMPUTER DESIGN
The call and ret instructions handle subroutine calls and returns. There
are five different call instructions and six different forms of the return
instruction:
The call instructions take the same forms as the jmp instructions except
there is no short (two byte) intrasegment call.
208
CIT344 INTRODUCTION TO COMPUTER DESIGN
retn: pop ip
retf: popd cs:ip
Clearly, you must match a near subroutine call with a near return and a
far subroutine call with a corresponding far return. If you mix near calls
with far returns or vice versa, you will leave the stack in an inconsistent
state and you probably will not return to the proper instruction after the
call. Of course, another important issue when using the call and ret
instructions is that you must make sure your subroutine doesn't push
something onto the stack and then fail to pop it off before trying to
return to the caller. Stack problems are a major cause of errors in
assembly language subroutines. Consider the following code:
Subroutine: push ax
push bx
.
.
.
pop bx
ret
.
.
.
call Subroutine
209
CIT344 INTRODUCTION TO COMPUTER DESIGN
The call instruction pushes the return address onto the stack and then
transfers control to the first instruction of subroutine. The first two push
instructions push the ax and bx registers onto the stack, presumably in
order to preserve their value because subroutine modifies them.
Unfortunately, a programming error exists in the code above, subroutine
only pops bx from the stack, it fails to pop ax as well. This means that
when subroutine tries to return to the caller, the value of ax rather than
the return address is sitting on the top of the stack. Therefore, this
subroutine returns control to the address specified by the initial value of
the ax register rather than to the true return address. Like the call
instruction, it is very easy to simulate the ret instruction using two
80x86 instructions. All you need to do is pop the return address off the
stack and then copy it into the ip register. For near returns, this is a very
simple operation, just pop the near return address off the stack and then
jump indirectly through that register:
pop ax
jmp ax
Simulating a far return is a little more difficult because you must load
cs:ip in a single operation. The only instruction that does this (other than
a far return) is the jmp mem32 instruction.
Although the jmp, call, and ret instructions provide transfer of control,
they do not allow you to make any serious decisions. The 80x86's
conditional jump instructions handle this task. The conditional jump
instructions are the basic tool for creating loops and other conditionally
executable statements like the “if … then” statement.
The conditional jumps test one or more flags in the flags register to see
if they match some particular pattern (just like the setcc instructions). If
the pattern matches, control transfers to the target location. If the match
fails, the CPU ignores the conditional jump and execution continues
with the next instruction. Some instructions, for example, test the
conditions of the sign, carry, overflow, and zero flags.
One thing nice about conditional jumps is that you do not flush the
pipeline or the prefetch queue if you do not take the branch. If one
condition is true far more often than the other, you might want to use the
conditional jump to transfer control to a jmp nearby, so you can continue
to fall through as before. For example, if you have a je target instruction
and target is out of range, you could convert it to the following code:
je GotoTarget
210
CIT344 INTRODUCTION TO COMPUTER DESIGN
.
.
.
GotoTarget: jmp Target
cmp bx, cx
jne SkipStmts
inc ax
SkipStmts:
The trick is to use the opposite branch to skip over the instructions you
want to execute if the condition is true. Always use the "opposite branch
(N/no N)" rule given earlier to select the opposite branch. You can make
the same mistake choosing an opposite branch here as you could when
extending out of range jumps.
You can also use the conditional jump instructions to synthesise loops.
For example, the following code sequence reads a sequence of
characters from the user and stores each character in successive
elements of an array until the user presses the Enter key (carriage
return):
mov di, 0
ReadLnLoop: mov ah, 0 ;INT 16h read key opcode.
int 16h
mov Input[di], al
inc di
cmp al, 0dh ;Carriage return ASCII code.
jne ReadLnLoop
mov Input[di-1],0 ;Replace carriage return with zero.
211
CIT344 INTRODUCTION TO COMPUTER DESIGN
dec cx
jne lbl
Although the loop instruction's name suggests that you would normally
create loops with it, keep in mind that all it is really doing is
decrementing cx and branching to the target address if cx does not
contain zero after the decrement. You can use this instruction anywhere
you want to decrement cx and then check for a zero result, not just when
creating loops. Nonetheless, it is a very convenient instruction to use if
you simply want to repeat a sequence of instructions some number of
times. For example, the following loop initialises a 256 element array of
bytes to the values 1, 2, 3, ...
212
CIT344 INTRODUCTION TO COMPUTER DESIGN
The last instruction is necessary because the loop does not repeat when
cx is zero. Therefore, the last element of the array that this loop
processes is Array[1], hence the last instruction.
Loope/loopz (loop while equal/zero, they are synonyms for one another)
will branch to the target address if cx is not zero and the zero flag is set.
This instruction is quite useful after cmp or cmps instruction, and is
marginally faster than the comparable 80386/486 instructions if you use
all the features of this instruction. However, this instruction plays havoc
with the pipeline and superscalar operation of the Pentium so you're
probably better off sticking with discrete instructions rather than using
this instruction. This instruction does the following:
cx := cx - 1
if ZeroFlag = 1 and cx 0, goto target
The loope instruction falls through on one of two conditions. Either the
zero flag is clear or the instruction decremented cx to zero. By testing
the zero flag after the loop instruction (with a je or jne instruction, for
example), you can determine the cause of termination.
This instruction is useful if you need to repeat a loop while some value
is equal to another, but there is a maximum number of iterations you
want to allow. For example, the following loop scans through an array
looking for the first non-zero byte, but it does not scan beyond the end
of the array:
jne quit
dec cx
213
CIT344 INTRODUCTION TO COMPUTER DESIGN
je Quit2
jmp Target
quit: dec cx ;loope decrements cx, even if ZF=0.
quit2:
cx := cx - 1
if ZeroFlag = 0 and cx 0, goto target
je quit
dec cx
je Quit2
jmp Target
quit: dec cx ;loopne decrements cx, even if ZF=1.
quit2:
You can use the loopne instruction to repeat some maximum number of
times while waiting for some other condition to be true. For example,
you could scan through an array until you exhaust the number of array
elements or until you find a certain byte using a loop like the following:
214
CIT344 INTRODUCTION TO COMPUTER DESIGN
one main use for these instruction forms where speed is rarely
important; indeed, being faster would make them less useful - timeout
loops during I/O operations. Suppose bit #7 of input port 379h contains
a one if the device is busy and contains a zero if the device is not busy.
If you want to output data to the port, you could use code like the
following:
The only problem with this loop is that it is conceivable that it would
loop forever. In a real system, a cable could come unplugged, someone
could shut off the peripheral device, and any number of other things
could go wrong that would hang up the system. Robust programs
usually apply a timeout to a loop like this. If the device fails to become
busy within some specified amount of time, then the loop exits and
raises an error condition. The following code will accomplish this:
You could use the loope/loopz instruction if the bit were zero rather than
one.
4. While Loops
The most general loop is the while loop. It takes the following form:
WHILE boolean expression DO statement;
215
CIT344 INTRODUCTION TO COMPUTER DESIGN
There are two important points to note about the while loop. First, the
test for termination appears at the beginning of the loop. Second as a
direct consequence of the position of the termination test, the body of
the loop may never execute. If the termination condition always exists,
the loop body will always be skipped over.
I := 0;
WHILE (I<100) do I := I + 1;
mov I, 0
WhileLp: cmp I, 100
jge WhileDone
inc I
jmp WhileLp
WhileDone:
Note that a Pascal while loop can be easily synthesised using an if and a
goto statement. For example, the Pascal while loop presented above can
be replaced by:
I := 0;
1: IF (I<100) THEN BEGIN
I := I + 1;
GOTO 1;
END;
More generally, any while loop can be built up from the following:
optional initialisation code
1: IF not termination condition THEN BEGIN
loop body
GOTO 1;
END;
216
CIT344 INTRODUCTION TO COMPUTER DESIGN
5. Repeat..Until Loops
This sequence executes the initialisation code, the loop body, then tests
some condition to see if the loop should be repeated. If the boolean
expression evaluates to false, the loop repeats; otherwise the loop
terminates. The two things to note about the repeat..until loop is
that the termination test appears at the end of the loop and, as a direct
consequence of this, the loop body executes at least once.
6. LOOP..ENDLOOP Loops
If while loops test for termination at the beginning of the loop and
repeat..until loops check for termination at the end of the loop,
the only place left to test for termination is in the middle of the loop.
Although Pascal and C/C++ don't directly support such a loop, the
loop..endloop structure can be found in HLL languages like Ada.
The loop..endloop loop takes the following form:
LOOP
loop body
ENDLOOP;
217
CIT344 INTRODUCTION TO COMPUTER DESIGN
LOOP
READ(ch)
IF ch = '.' THEN BREAK;
WRITE(ch);
ENDLOOP;
1:
READ(ch);
IF ch = '.' THEN GOTO 2; (* Turbo Pascal supports BREAK! *)
WRITE(ch);
GOTO 1
2:
In assembly language you'd end up with something like:
LOOP1: getc
cmp al, '.'
je EndLoop
putc
jmp LOOP1
EndLoop:
7. FOR Loops
The for loop is a special form of the while loop which repeats the
loop body a specific number of times. In Pascal, the for loop looks
something like the following:
218
CIT344 INTRODUCTION TO COMPUTER DESIGN
inc var
jmp FL
EndFor:
FOR I := 0 to 7 do write(ch);
In situations like this, it's better to use the 80x86 loop instruction (or
corresponding dec cx/jne sequence) rather than simulate a for loop:
mov cx, 7
LP: mov al, ch
call putc
loop LP
Keep in mind that the loop instruction normally appears at the end of a
loop whereas the for loop tests for termination at the beginning of the
loop. Therefore, you should take precautions to prevent a runaway loop
in the event cx is zero (which would cause the loop instruction to repeat
the loop 65,536 times) or the stop value is less than the start value. In
the case of
assuming you don't use the value of var within the loop, you'd probably
want to use the assembly code:
Remember, the sub and cmp instructions set the flags in an identical
fashion. Therefore, this loop will be skipped if stop is less than start. It
will be repeated (stop-start)+1 times otherwise. If you need to reference
the value of var within the loop, you could use the following code:
219
CIT344 INTRODUCTION TO COMPUTER DESIGN
SELF-ASSESSMENT EXCERCISE
Mention all the program flow instructions you know and write short
notes on each.
4.0 CONCLUSION
5.0 SUMMARY
220
CIT344 INTRODUCTION TO COMPUTER DESIGN
locality to a register and then from the register to the destiny locality. It
is not possible to move a constant directly to a segment register; it first
must be moved to a register in the CPU. It is possible to move data
blocks by means of the movs instructions, which copies a chain of bytes
or words; movsb which copies n bytes from a locality to another; and
movsw copies n words from a locality to another.
www.cs.siu.edu
www.educypedia.be/electronics
www.books.google.com
221
CIT344 INTRODUCTION TO COMPUTER DESIGN
CONTENTS
1.0 Introduction
2.0 Objectives
3.0 Main Content
3.1 Sample Programs in Assembly Language
3.1.1 Simple Arithmetic I
3.1.2 Simple Arithmetic II
3.1.3 Logical Operations
3.2 Comparison of Assembly & High Level Languages
4.0 Conclusion
5.0 Summary
6.0 Tutor-Marked Assignment
7.0 References/Further Reading
1.0 INTRODUCTION
This unit gives some simple programs used to demonstrate the use of
various instructions in assembly language. It also compares assembly
language with high level languages.
2.0 OBJECTIVES
222
CIT344 INTRODUCTION TO COMPUTER DESIGN
; Simple Arithmetic
; This program demonstrates some simple arithmetic instructions.
j integer ?
k integer ?
l integer ?
u1 uint ?
u2 uint ?
u3 uint ?
dseg ends
Main proc
mov ax, dseg
mov ds, ax
mov es, ax
mov j, 3
mov k, -2
mov ax, J
add ax, K
mov L, ax
223
CIT344 INTRODUCTION TO COMPUTER DESIGN
mov ax, J
sub ax, K
mov L, ax
; Compute L := -L
neg L
; Compute L := -J
inc K
inc u2
dec J
dec u2
cseg ends
224
CIT344 INTRODUCTION TO COMPUTER DESIGN
; Simple Arithmetic
; This program demonstrates some simple arithmetic instructions.
j integer ?
k integer ?
l integer ?
u1 uint ?
u2 uint ?
u3 uint ?
dseg ends
Main proc
mov ax, dseg
mov ds, ax
mov es, ax
225
CIT344 INTRODUCTION TO COMPUTER DESIGN
mov j, 3
mov k, -2
mov u1, 254
mov u2, 22
mov ax, J
imul K ;Computes DX:AX := AX * K
mov L, ax ;Ignore overflow into DX.
; u3 := u1 * u2
mov ax, u1
mul u2 ;Computes DX:AX := AX * U2
mov u3, ax ;Ignore overflow in DX.
mov ax, J
cwd ;*MUST* sign extend AX to DX:AX!
idiv K ;AX := DX:AX/K, DX := DX:AX mod K
mov L, ax
; u3 := u1/u2
mov ax, u1
mov dx, 0 ;Must zero extend AX to DX:AX!
div u2 ;AX := DX:AX/u2, DX := DX:AX
226
CIT344 INTRODUCTION TO COMPUTER DESIGN
mod u2
mov u3, ax
mov ax, J
imul ax, K
mov L, ax
; Logical Operations
; This program demonstrates the AND, OR, XOR, and NOT instructions
227
CIT344 INTRODUCTION TO COMPUTER DESIGN
j word 0FF00h
k word 0FFF0h
l word ?
c1 byte 'A'
c2 byte 'a'
dseg ends
cseg segment para public 'code'
assume cs:cseg, ds:dseg
Main proc
mov ax, dseg
mov ds, ax
mov es, ax
mov ax, J
and ax, K
mov L, ax
mov ax, J
or ax, K
mov L, ax
mov ax, J
xor ax, K
mov L, ax
not L
228
CIT344 INTRODUCTION TO COMPUTER DESIGN
mov ax, J
not ax
mov L, ax
and J, 0FFF0h
or K, 0Fh
xor L, 0FF0h
mov al, c2
and al, 5Fh ;Clears bit 5.
mov c2, al
cseg ends
229
CIT344 INTRODUCTION TO COMPUTER DESIGN
SELF-ASSESSMENT EXERCISE
Perhaps the most glaring difference among the three types of languages
[high level, assembly, and machine] is that as we move from high-level
languages to lower levels, the code gets harder to read (with
understanding). The major advantages of high-level languages are that
they are easy to read and are machine independent. The instructions are
written in a combination of English and ordinary mathematical notation,
and programs can be run with minor, if any, changes on different
computers.
230
CIT344 INTRODUCTION TO COMPUTER DESIGN
High level programming languages are much easier for less skilled
programmers to work in and for semi-technical managers to supervise.
And high level languages allow faster development times than work in
assembly language, even with highly skilled programmers. Development
time increases of 10 to 100 times faster are fairly common. Programs
written in high level languages (especially object oriented programming
languages) are much easier and less expensive to maintain than similar
programs written in assembly language (and for a successful software
project, the vast majority of the work and expense is in maintenance, not
initial development).
231
CIT344 INTRODUCTION TO COMPUTER DESIGN
4.0 CONCLUSION
The most glaring difference among the three types of languages [high
level, assembly, and machine] is that as we move from high-level
languages to lower levels, the code gets harder to read (with
understanding). The major advantages of high-level languages are that
they are easy to read and are machine independent.
5.0 SUMMARY
232
CIT344 INTRODUCTION TO COMPUTER DESIGN
www.cs.siu.edu
www.educypedia.be/electronics
www.books.google.com
233