B.Sc. COMPUTER SCIENCE MICROPROCESSOR

40

Transcript of B.Sc. COMPUTER SCIENCE MICROPROCESSOR

Page 1: B.Sc. COMPUTER SCIENCE MICROPROCESSOR
Page 2: B.Sc. COMPUTER SCIENCE MICROPROCESSOR

B.Sc. COMPUTER SCIENCE

SEMESTER I

CORE I - DIGITAL COMPUTER FUNDAMENTALS AND

MICROPROCESSOR

UNIT - I

Introduction: Application of Computer-Different types of

Computer systems-Basic components of

Digital Computer System-Programming Languages -

Number Systems.

UNIT - II

Boolean Algebra and Gate Networks: Fundamentals

concepts of Boolean Algebra - Logical

Multiplication AND Gates, OR Gates, and Inverters -

Evaluation of logical Expressions - Basic Law of

Boolean Algebra - Simplification of expressions - De

Morgan's theorems - Basic Duality of Boolean

Algebra - Derivation of a Boolean Expression.

UNIT – III

Interconnecting Gates: Sum of Products (SOP) and

Products of Sums (POS) - Derivation of products of

sums expressions - Derivation of three Input variable

expression - NAND gates and NOR gates - The

Map method for simplifying expressions - Sub cube and

covering - product of sums expressions - Don't

cares.

Page 3: B.Sc. COMPUTER SCIENCE MICROPROCESSOR

UNIT - IV

Microprocessors, Microcomputers and Assembly Language:

Microprocessors - Microprocessor

instruction set and Computer Languages-From large

computers to single chip Microcontrollers;

Microprocessor Architecture and Microcomputer systems -

Microprocessor Architecture and its

operations - Memory - I/O devices - 8085 Microprocessor

Architecture and Interfacing: The 8085 MPU -

Examples of a 8085 based Microcomputer - Memory

interfacing.

UNIT -V

Programming the 8085: Introduction to 8085 Instructions -

Code conversion: BCD to Binary conversion

- Binary to BCD conversion - BCD to seven segment LED code

conversion - Binary to ASCII and ASCII

to binary code conversion - BCD addition - BCD subtraction.

TEXT BOOKS:

1. Thomas C Bartee, "Digital Computer Fundamentals", 6th

Edition, T.M.H Publisher, New Delhi, 1991.

2. Ramesh S Gaonkar, "Microprocessor Architecture

Programming and Application with the 8085",5th

Edition, 2002.

REFERENCE BOOKS:

1. Deborah Morley, Charles S. Parker, "Understanding

Computers- Today and Tomorrow", 1stEdition,

Thomson Course Technology, 2007

2. N.K. Srinath, "8085 Microprocessor Programming and

Interfacing", PHI Publishing, 2005.

Page 4: B.Sc. COMPUTER SCIENCE MICROPROCESSOR

Advantagesof Computers

Following are certain advantages of computers.

High Speed

Computer is a very fast device.

It is capable of performing calculation of very large amount ofdata.

The computer has units of speed in microsecond, nanosecond, and even the picosecond.It can

perform millions of calculations in a few seconds as compared to man who will spend many

months to perform the same task.

Accuracy

In addition to being very fast, computers are very accurate.

The calculations are 100% error free.

Computers perform all jobs with 100% accuracy provided that the input is correct.

Storage Capability

Memory is a very important characteristic of computers. A computer has much more storage capacity than human beings.

INTRODUCTION TO COMPUTER

UNIT-1

Page 5: B.Sc. COMPUTER SCIENCE MICROPROCESSOR

It can store large amount of data.

It can store any type of data such as images, videos, text, audio,etc.

Diligence

Unlike human beings, a computer is free from monotony, tiredness, and lack of concentration.

It can work continuously without any error and boredom.

It can perform repeated tasks with the same speed and accuracy.

Versatility

A computer is a very versatile machine.

A computer is very flexible in performing the jobs to be done.

This machine can be used to solve the problems related to variousfields.

At one instance, it may be solving a complex scientific problem and the very next moment it

may be playing a card game.

Reliability

A computer is a reliable machine.

Modern electronic components have long lives.

Computers are designed to make maintenanceeasy.

Automation

Computer is an automaticmachine.

Automation is the ability to perform a given task automatically. Once the computer receives a

program i.e., the program is stored in the computer memory, then the program and instruction

can control the program executionwithouthuman interaction.

Reduction in Paper Work and Cost

The use of computers for data processing in an organization leads to reduction in paper work and

results in speeding up the process.

As data in electronic files can be retrieved as and when required, the problem of maintenance of

large number of paper files getsreduced.

Though the initial investment for installing a computer is high, it substantially reduces the cost of

Page 6: B.Sc. COMPUTER SCIENCE MICROPROCESSOR

each of its transaction.

Disadvantages of Computers

No I.Q.

A computer is a machine that has no intelligence to perform any task.

Each instruction has to be given to the computer.

A computer cannot take any decision on its own.

Dependency

It functions as per the user’s instruction, thus it is fully dependent onhumans.

Environment

The operating environment of the computer should be dust free and suitable.

No Feeling

Computers have no feelings or emotions.

It cannot make judgment based on feeling, taste, experience, and knowledge unlikehumans.

COMPUTER APPLICATIONS

Business

A computer has high speed of calculation, diligence,

accuracy, reliability, or versatility which has made it an

integrated part in all business organizations.

Computer is used in business organizationsfor:

Payroll calculations Budgeting Sales analysis Financial forecasting Managing employee database Maintenance of stocks, etc.

Banking

Today, banking is almost totally dependent on

Page 7: B.Sc. COMPUTER SCIENCE MICROPROCESSOR

computers.

Banks provide the following facilities:

Online accounting facility, which includes checking current balance, making deposits and overdrafts, checking interest charges, shares, and trustee records.

ATM machines which are completelyautomated are making it even easier forcustomers to deal with banks.

Insurance

Insurance companies are keeping all records up- to-date

with the help of computers. Insurance companies,

finance houses, and stock broking firms are widely using

computers for their concerns.

Insurance companies are maintaining a database of all

clients with information showing:

Procedure to continue with policies

Starting date of the policies

Next due installment of a policy

Maturity date

Interests due

Survival benefits

Bonus

Education

The computer helps in providing a lot of facilities in the educationsystem.

The computerprovides a tool in the education system known as CBE (ComputerBased Education).

CBE involves control, delivery, and evaluationof learning.

Computer education is rapidly increasing thegraph of number of computer students.

There are a number of methods in whicheducational institutions can use a computerto

Page 8: B.Sc. COMPUTER SCIENCE MICROPROCESSOR

educate the students.

It is used to prepare a database aboutperformance of a student and analysis is carried out on thisbasis.

Marketing

In marketing, uses of the computer are following:

Advertising - With computers, advertising

professionals create art and graphics, write and

revise copy, and print and disseminate ads with

the goal of selling moreproducts.

Home Shopping - Home shopping has been

made possible through the use of computerized

catalogues that provide access to product

information and permit direct entry of orders to

be filled by the customers.

Healthcare

Computers have become an important part in hospitals, labs, and dispensaries. They are being used in

hospitals to keep the record of patients and medicines. It is also used in scanning and diagnosing different

diseases.ECG, EEG, ultrasounds and CT scans, etc. are also done by computerized machines.

Following are some major fields of health care in which computers are used.Diagnostic System - Computers are used to collect data and identify the cause of illness.

Lab-diagnostic System - All tests can be doneand the reports are prepared by computer.

Patient Monitoring System - These are used tocheck the patient's signs for abnormality such asinCardiacArrest, ECG, etc.

Pharma Information System- Computer is used to check drug labels, expiry dates, harmful side effects, etc.

Surgery - Nowadays, computers are also used in performing surgery.

Engineering Design

Computers are widely used for Engineering purpose.

One of the major areas is CAD (Computer Aided Design) that provides creation and modification of

images. Some of the fields are:

Page 9: B.Sc. COMPUTER SCIENCE MICROPROCESSOR

Structural Engineering - Requires stress andstrain analysis for design of ships, buildings,budgets, airplanes, etc.

Industrial Engineering - Computers dealwith design, implementation, andimprovement of integrated systems ofpeople, materials, and equipment.

Architectural Engineering - Computers help in planning towns, designing buildings, determining a range of buildings on a site using both 2D and 3D drawings.

Military

Computers are largely used in defence. Modern tanks,

missiles, weapons, etc. Military also employs

computerized control systems. Some military areas

where a computer has been used are:

Missile Control

Military Communication

Military Operation and Planning

Smart Weapons

Communication

Communication is a way to convey a message, an idea, a picture, or speech that is received and

understood clearly and correctly by the person

for whom it is meant. Some main areas in this categoryare:

E-mail

Chatting

Usenet

FTP

Telnet

Video-conferencing

Government

Computers play an important role in government services. Some major fields in this category are:

Budgets

Page 10: B.Sc. COMPUTER SCIENCE MICROPROCESSOR

Sales tax department

Income tax department

Computation of male/female ratio

Computerization of voters lists

Computerization of PAN card

Weather forecasting

GENERATION OF A COMPUTER

Generation in computer terminology is a change in technology a computer is/was being used. Initially, the

generation term was used to distinguish between varying hardware technologies. Nowadays, generation

includes both hardware and software, which together make up an entire computersystem.

There are five computer generations known till date. Each generation has been discussed in detail along

with their time period and characteristics. In the following table, approximate dates against each

generation has been mentioned, which are normallyaccepted.

Following are the main five generations of computers.

Sr.No.

Generation & Description

1First Generation

The period of first generation: 1946-1959. Vacuum tube based.

2Second Generation

The period of second generation: 1959-1965. Transistor based.

3Third Generation

The period of third generation: 1965-1971. Integrated Circuit based.

4Fourth Generation

The period of fourth generation: 1971-1980. VLSI microprocessor based.

5Fifth Generation

The period of fifth generation: 1980-onwards. ULSI microprocessorbased.

Page 11: B.Sc. COMPUTER SCIENCE MICROPROCESSOR

First Generation Computers

The period of first generation was from 1946-1959. The computers of first generation used vacuum

tubes as the basic components for memory and circuitry for CPU (Central Processing Unit). These tubes,

like electricbulbs,produced a lot of heat and the installations used to fuse

frequently. Therefore, they were very expensive and only large organizations were able to afford it.

In this generation, mainly batch processing operating system was used. Punch cards, paper tape, and

magnetic tape was used as input and output devices. The computers in this generation used machine

code as the programming language.

The main features of the first generation are:

Vacuum tube technology

Unreliable

Supported machine language only

Very costly

Generated a lot of heat

Slow input and output devices

Huge size

Need of AC

Non-portable

Consumed a lot of electricity

Some computers of this generation were:

Page 12: B.Sc. COMPUTER SCIENCE MICROPROCESSOR

ENIAC

EDVAC

UNIVAC

IBM-701

IBM-650

Second GenerationComputers

The period of second generation was from 1959-1965. In this generation, transistors were used that

were cheaper, consumed less power, more compact in size, more reliable and faster than the first

generation machines made of vacuum tubes. In this generation, magnetic cores were used as the primary

memory and magnetic tape and magnetic disks as secondary storagedevices.

In this generation, assembly language and high-level programming languages like FORTRAN, COBOL were

used. The computers used batch processing and multiprogramming operating system.

The main features of second generation are:

Use of transistors

Reliable in comparison to first generationcomputers

Smaller size as compared to first generationcomputers

Generated less heat as compared to first generationcomputers

Consumed less electricity as compared to first generationcomputers

Faster than first generation computers

Still very costly

AC required

Supported machine and assembly languages

Page 13: B.Sc. COMPUTER SCIENCE MICROPROCESSOR

Some computers of this generation were:

IBM1620

IBM7094

CDC 1604

CDC 3600

UNIVAC 1108

ThirdGenerationComputers

The period of third generation was from 1965-1971. The computers of third generation used Integrated

Circuits (ICs) in place of transistors. A single IC has many transistors, resistors, and capacitors along with

the associated circuitry.

The IC was invented by Jack Kilby. This developmentmade computers smaller in size, reliable, and efficient.

In this generation remote processing, time-sharing, multi-programming operating system were used.

High-level languages (FORTRAN-II TO IV, COBOL, PASCAL PL/1, BASIC, ALGOL-68 etc.) were used during

this generation.

Page 14: B.Sc. COMPUTER SCIENCE MICROPROCESSOR

The main features of third generation are:

IC used

More reliable in comparison to previous two generations

Smaller size

Generated less heat

Faster

Lesser maintenance

Costly

AC required

Consumed lesser electricity

Supported high-level language

Some computers of this generation were:

IBM-360 series

Honeywell-6000 series

PDP (Personal Data Processor)

IBM-370/168

TDC-316

Fourth GenerationComputers

The period of fourth generation was from 1971-1980. Computers of fourth generation used

Very Large Scale Integrated (VLSI) circuits. VLSI circuits having about 5000 transistors and

other circuit elements with their associated circuits on a single chip made it possible to have

microcomputers of fourth generation.

Fourth generation computers became more powerful, compact, reliable, and affordable. As

a result, it gave rise to Personal Computer (PC) revolution. In this generation, time sharing,

real time networks, distributed operating system were used. All the high-level languages

Page 15: B.Sc. COMPUTER SCIENCE MICROPROCESSOR

like C, C++, DBASE etc., were used in thisgeneration.

The main features of fourth generation are:

VLSI technology used

Very cheap

Portable and reliable

Use of PCs

Very small size

Pipeline processing

No AC required

Concept of internet was introduced

Great developments in the fields of networks

Computers became easily available

Some computers of this generation were:

DEC 10

STAR 1000

PDP 11

CRAY-1(Super Computer)

CRAY-X-MP(Super Computer)

FifthGenerationComputers

The period of fifth generation is 1980-till date. In the fifth generation, VLSI technology became

ULSI (Ultra Large Scale Integration) technology, resulting in the production of microprocessor

chips having ten million electroniccomponents.

This generation is based on parallel processing hardware and AI (Artificial Intelligence)

software. AI is an emerging branch in computer science, which interprets the meansand

Page 16: B.Sc. COMPUTER SCIENCE MICROPROCESSOR

method of making computers think like human beings. All the high-level languages like C and

C++, Java, .Net etc., are used in thisgeneration.

AI includes:

Robotics

Neural Networks

Game Playing

Development of expert systems to make decisions in real-lifesituations

Natural language understanding and generation

The main features of fifth generation are:

ULSI technology

Development of true artificial intelligence

Development of Natural language processing

Advancement in ParallelProcessing

Advancement in Superconductor technology

More user-friendly interfaces with multimediafeatures

Availability of very powerful and compact computers at cheaper rates

Some computer types of this generation are:

Desktop

Laptop

NoteBook

UltraBook

ChromeBook

TYPES OF COMPUTERS

Page 17: B.Sc. COMPUTER SCIENCE MICROPROCESSOR

Computers can be broadly classified by their speed and computing power.

Sr.No.

Type Specifications

1PC (Personal Computer)

It is a single user computer system having moderately powerful microprocessor

2 WorkstationIt is also a single user computer system, similar to personal computer however has a more powerful microprocessor

3 Mini ComputerIt is a multi-user computer system, capable of supporting hundreds of users simultaneously.

4 Main Frame

It is a multi-user computer system, capable of supporting hundredsof users simultaneously. Software technology is different fromminicomputer.

5 SupercomputerIt is an extremely fast computer, which can execute hundreds of millions of instructions per second.

PC (Personal Computer)

A PC can be defined as a small, relatively inexpensive computer designed for an individual

user. PCs are based on the microprocessor technology that enables manufacturers to put an

entire CPU on one chip. Businesses use personal

computers for word processing,

accounting, desktop publishing, and for

running spreadsheet and database

management applications. At home, the

most popular use for personal computers

is playing games and surfing the Internet.

Although personal computers are designed

as single-user systems, these systems are

normally linked together to form a

network. In terms of power, now-a-days

high-end models of the Macintosh and PC

offer the same computing power and

graphics capability as low-end workstations

by Sun Microsystems, Hewlett-Packard,

and Dell.

Workstation

Workstation is a computer used for engineering applications (CAD/CAM), desktop

publishing, software development, and other such types of applications which require a

moderate amount of computing power and relatively high quality graphicscapabilities.

Workstations generally come with a large, high-resolution graphics screen, large amount of

RAM, inbuilt network support, and a graphicaluser

interface. Most workstations also have

mass storage device such as a disk drive,

but a special type of workstation, called

diskless workstation, comes without a disk

Page 18: B.Sc. COMPUTER SCIENCE MICROPROCESSOR

drive.

Common operating systems for

workstations are UNIX and Windows NT.

Like PC, workstations are also single-user

computers like PC but are typically linked

together to form a local-area network,

although they can also be used as stand-

alone systems.

Minicomputer

It is a midsize multi-processing system capable of supporting up to 250 users simultaneously.

Mainframe

Mainframe is very large in size and is an expensive computer capable of supporting

hundreds or even thousands of users simultaneously. Mainframe executes many programs

concurrently

and supports many simultaneous execution of programs.

Supercomputer

Supercomputers are one of the fastest computers currently available. Supercomputers are

very expensive and are employed for specialized applications that require immense

Page 19: B.Sc. COMPUTER SCIENCE MICROPROCESSOR

amount of mathematical calculations (number crunching).

For example, weather forecasting, scientific simulations, (animated) graphics, fluid dynamic

calculations, nuclear energy research, electronic design, and analysis of geological data(e.g.

in petrochemical prospecting)

COMPONENTS OF A DIGITAL COMPUTER

All types of computers follow the same basic logical structure and perform the following five basic

operations for converting raw input data into information useful to their users.

Input Unit

This unit contains devices with the help of which we enter data into the computer. This unit creates a link

between the user and the computer. The input devices translate the information into a form understandable by

the computer.

Operation Description

Take InputThe process of entering data and instructions into the computer

system.

StoreDataSaving data and instructions so that they are available for

processing as and when required.

Processing Data

Performing arithmetic, and logical operations on data in order to convert them into useful information.

Output Information

The process of producing useful information or results for the user, such as a printed report or visual display.

Control the workf

low

Directs the manner and sequence in which all of the above operations are performed.

Page 20: B.Sc. COMPUTER SCIENCE MICROPROCESSOR

CPU (Central Processing Unit)

CPU is considered as the brain of the computer. CPU performs all types of data processing operations. It

stores data, intermediate results, and instructions (program). It controls the operation of all parts of the

computer.

CPU itself has the following three components:

ALU (Arithmetic LogicUnit)

Memory Unit

Control Unit

Output Unit

The output unit consists of devices with the help of which we get the information from the computer. This

unit is a link between the computer and the users. Output devices translate the computer's output into a

form understandable by the users.

Types of Programming Languages

There are two types of programming languages, which can be categorized into the following ways:

1. Low level language

a) Machine language (1GL)

b) Assembly language (2GL)

2. High level language

a) Procedural-Oriented language (3GL)

b) Problem-Oriented language (4GL)

c) Natural language (5GL)

1. Low level language

This language is the most understandable language used by computer to perform its operations. It can be

further categorized into:

a) Machine Language (1GL)

Machine language consists of strings of binary numbers (i.e. 0s and 1s) and it is the only one language, the

processor directly understands. Machine language has an Merits of very fast execution speed and efficient

use of primary memory.

Merits:

¨ It is directly understood by the processor so has faster execution time since the programs written in

this language need not to be translated.

¨ It doesn’t need larger memory.

Demerits:

¨ It is very difficult to program using 1GL since all the instructions are to be represented by 0s and 1s.

¨ Use of this language makes programming time consuming.

¨ It is difficult to find error and to debug.

¨ It can be used by experts only.

b) Assembly Language

Assembly language is also known as low-level language because to design a program programmer requires

detailed knowledge of hardware specification. This language uses mnemonics code (symbolic operation

code like ‘ADD’ for addition) in place of 0s and 1s. The program is converted into machine code by

assembler. The resulting program is referred to as an object code.

Page 21: B.Sc. COMPUTER SCIENCE MICROPROCESSOR

Merits:

¨ It is makes programming easier than 1GL since it uses mnemonics code for

programming. Eg: ADD for addition, SUB for subtraction, DIV for division,etc.

¨ It makes programming process faster.

¨ Error can be identified much easily compared to 1GL.

¨ It is easier to debug than machine language.

Demerits:

¨ Programs written in this language is not directly understandable by computer so translaters should be

used.

¨ It is hardware dependent language so programmers are forced to think in terms of computer’s

architecture rather than to the problem being solved.

¨ Being machine dependent language, programs written in this language are very less or notprotable.

¨ Programmers must know its mnemonics codes to perform any task.

2. High level language

Instructions of this language closely reassembles to human language or English like words. It uses

mathematical notations to perform the task. The high level language is easier to learn. It requires less

time to write and is easier to maintain the errors. The high level language is converted into machine

language by one of the two different languages translator programs; interpreter or compiler.

High level language can be further categorized as:

a) Procedural-Oriented language (3GL)

Procedural Programming is a methodology for modeling the problem being solved, by determining the steps

and the order of those steps that must be followed in order to reach a desired outcome or specific

program state. These languages are designed to express the logic and the procedure of a problem to be

solved. It includes languages such as Pascal, COBOL, C, FORTAN,etc.

Merits:

¨ Because of their flexibility, procedural languages are able to solve a variety of problems.

¨ Programmer does not need to think in term of computer architecture which makes them focused on the

problem.

¨ Programs written in this language are portable.

Demerits:

¨ It is easier but needs higher processor and larger memory.

¨ It needs to be translated therefore its execution time is more.

b) Problem-Oriented language (4GL)

It allows the users to specify what the output should be, without describing all the details of how the data

should be manipulated to produce the result. This is one step ahead from 3GL. These are result oriented

and include database query language.

Eg: Visual Basic, C#, PHP, etc.

The objectives of 4GL are to:

Page 22: B.Sc. COMPUTER SCIENCE MICROPROCESSOR

Ø Increase the speed of developing programs.

Ø Minimize user’s effort to obtain information from computer.

Ø Reduce errors while writing programs.

Merits:

¨ Programmer need not to think about the procedure of the program. So, programming is mucheasier.

Demerits:

¨ It is easier but needs higher processor and larger memory.

¨ It needs to be translated therefore its execution time is more.

c) Natural language (5GL)

Natural language are still in developing stage where we could write statements that would look like normal

sentences.

Merits:

¨ Easy to program.

¨ The programs designed using 5GL will have artificial intelligence (AI).

¨ The programs would be much more interactive and interesting.

Demerits:

¨ It is slower than previous generation language as it should be completely translated into binary code

which is a tedious task.

¨ Highly advanced and expensive electronic devices are required to run programs developed in 5GL. Therefore,

it is an expensive approach.

These are the different types of programming languages with their merits and demerits.

NUMBER SYSTEM

Number system is simply the ways to count things. Aim of any number system is to deal with certainquantities which can be measured, monitored, recorded, manipulated arithmetically, observed andutilised. Each quantity has to be represented by its value as efficiently and accurately as is necessary forany application. The numerical value of a quantity can be basically expressed in either analog(continuous) or digital (step by step) method of representation. In analog method, a quantity is expressedby another quantity which is proportional to the first. For example, the voltage output of an amplifier ismeasured by a voltmeter. The angular position of the needle of the voltmeter is proportional to thevoltage output of the amplifier.

Digital technology is different from analog technology. Many number systems are being used in

digital technology. Most common amongst them are decimal, binary, octal, and hexadecimal

systems. We are most familiar with the decimal number system, because we use it every day.

It is the base-10 or radix-10 system. Note that there is no symbol for “10” or for the base of any

system. We count 1 2 3 4 5 6 7 8 9, and then insert a 0 in the first column and add a new left

column, starting at 1 again. Then we count 1-9 in the first column again. (People use the base-10

system because we have 10 fingers!). Each column in our system stands for a power of 10 starting at

100.

1.2 Binary System

All computers use the binary system. The following points provides an overview of the binary system:

• In the binary number system (base of 2), there are only two digits: 0 and 1 and the place values are

20, 21, 22, 23 etc. Binary digits are abbreviated as bits. For example, 1101 is a binary number of 4 bits

(i.e.it is a binary number containing four binary digits.)

Page 23: B.Sc. COMPUTER SCIENCE MICROPROCESSOR

• A binary number may have any number of bits. Consider the number 11001.01 1. Note the binary

point (counterpart of decimal point in decimal number system) in thisnumber.

• Each digit is known as a bit and can take only two values 0 and 1. The left most bit is the highest-order

bit and represents the most significant bit (MSB) while the lowest-order bit is the least significant bit

(LSB). Some useful definitions are:

Word is a binary number consisting of an arbitrary number of bits.

Nibble is a 4-bit word (one hexadecimal digit) 16 values.

Byte is an 8-bit word 256 values.

Counting binary numbers

1’s complement

The 1’s complement of changing each 0 to 1

a binary number is obtained just by and each 1 to 0.

1’s complement

2’s complement

The 2’s complement of a binary number is obtained adding 1 to the 1’s complement of this number:

2’s complement = 1’s complement+1 Binary number 1 0 1 1 1 01

0

1’s complement 0 1 0 0 0 1 0 1

+ 1

2’s complement 0 1 0 0 0 1 1 0

There is a simple method to obtain the 2’s complement:

• Beginning with the LSB, just write down bits as they are moving to left till the first 1, includingit.

• Substitute the rest of bits by their 1’s complement.

Signed numbers

Binary Number

Decimal Number

0000 0

0001 1

0010 2

0100 3

0101 4

0110 5

0111 6

1000 7

1001 8

1010 9

1011 10

1100 11

1101 12

1101 13

1110 14

1111 15

Binary 1 0 1 1 1 1 0

1- 0 1 0 0 0 0 1

Page 24: B.Sc. COMPUTER SCIENCE MICROPROCESSOR

In a signed number, the left most bit is the so called sign bit: 0=positive number 1=negativenumber.

Sign-value notation

In this notation, the left-most bit is the sign bit and the others are used to represent the absolute value notation.

1’s complementIn this notation, the positive numbers have the same representation as the sign-value notation, and

the negative numbers are obtained by taking the 1’s complement of the positive correspondents.

2’s complement

The positivenumbershavethesamerepresentationasthe sign-valuenotation,and the negative

numbersareobtained by taking the 1’s complement of the positive correspondents.

1.2.1 Binary to Decimal Conversion

• Binary number can be converted into its decimal equivalent, by simply adding the weights of various

positions in the binary number which have bit 1.

• Example 1:

Find the decimal equivalent of the binarynumber (11111)2 The equivalent decimal number is

=1X24+1X23+1X22+1X21+1X20

=16+8+4+2+1

= (31)10

• To differentiate between numbers represented in different number systems, either the corresponding

number system may be specified along with the number or a small subscript at the end of the number

may be added signifying the number system. Example (1000)2 represents a binary

number and is not onethousand.

• Example 2:

Consider the conversion of (100011.101)2 1 0 0 0 1 1.1 0 1

= 25+0+0+0+21+20+2-1+0+2-3

=32+2+1+0.5+0.125

=(35.625)10Consider the following examples.

1111.00 = 15

11110.0 = 30

111100.0 = 60

From these examples, it is clear that if the binary point is shifted towards right side, then the value of

the number is doubled.

Now consider the following examples.

111.100 =

7.5 11.1

100 = 3.75

1.1 1100 =

1.875

From these examples it is clear that if the binary point is shifted towards the left side, then the value of

the number is halved.

1.3 Decimal to Binary Conversion

A decimal number is converted into its binary equivalent by its repeated divisions by 2. The division is continued

Page 25: B.Sc. COMPUTER SCIENCE MICROPROCESSOR

Decimal to binary conversion

Let us try another example, conversion of (58.0725)10 into binary. Split this number in two parts, i.e. 58

and .0725 and convert them into binary separately as described above.

1 0 1

till we get a quotient of 0. Then all the remainders are arranged sequentially withfirst remainder taking the position of LSB and the last one taking the position of MSB. Consider the conversion of 27 into its binary equivalent as follows.

2 27

2 13 - 1

2 6 – 1

2 3 – 0

2 1 - 1

2 0 - 1

If the number also has some figures on the right of the decimal point, then this part of the

number is to be treated separately. Multiply this part repeatedly by two. After first multiplication

by 2, either 1 or 0 will appear on the left of the decimal point. Keep this 1 or 0 separately and do

not multiply it by 2 subsequently. This should be followed for every multiplication. Continue

multiplication by 2 till you get all 0s after the decimal point or up to the level of the accuracy

desired. This will be clear from the following example. Consider the conversion of 27.62510 into

its binary equivalent. We have already converted 27 into its binary equivalentwhich is (11011)2. Now

fortheconversion of 0.625, multiply it by 2 repeatedly as follows:

Thus, 27.62510 = 11011.101

.625

X 2

.250

X 2

.500

X 2

.00

Page 26: B.Sc. COMPUTER SCIENCE MICROPROCESSOR

2 58

2 -0

214

-1

2 7 -0

2 3 -1

2 1 -1

0 -1

1 1 1 0 1Decimal to binary conversion

The conversion of 0.725

Thus, (58.0725)10 = 111010.00010

.0725

X 2.1450

X 2.2900

X 2.5800

X 2 .1600

X 2

0 0 0 1

Decimal to binary conversion

0

Representing numbers in binary is very tedious, since binary numbers often consist of a large chain of 0's and 1's.

Convenient shorthand forms for representing the binary numbers are developed such as octal system and

hexadecimal system. With these number systems long strings of 0's and 1's can be reduced to a manageable

form. The section below gives an overview of these systems.

1.4 Octal Number System

The octal number system has base-8 that is, there are 8 digits in this system. These digits are 0, 1, 2, 3, 4, 5, 6, and7.The weight of each octal digit is some power of 8 depending upon the position of the digit. Octal numbers showing

positional values (weights) of each digit are as follows:

Page 27: B.Sc. COMPUTER SCIENCE MICROPROCESSOR

Decimal to octal conversion

Octal number does not include the decimal digits 8 and 9. If any number includes decimal digits 8 and 9, then the

number can not be an octal number.

1. Octal to Decimal Conversion

As has been done in case of binary numbers, an octal number can be converted into its decimal equivalent by

multiplying the octal digit by its positional value. For example, let us convert 36.48 into decimal number.

36.48 = 3 x 81 + 6 x 80 + 4 x 8-1

= 24 + 6 + 0.5

= (30.5)10

2. Decimal to Octal Conversion

A decimal number can be converted by repeated division by 8 into equivalent octal number. This method is similar

to that adopted in decimal to binary conversion. If the decimal number has some digits on the right of the

decimal point, then this part of the number is converted into its octal equivalent by repeatedly multiplying it by

8. The process is same as has been followed in binary number system. Consider the conversion of 126.3810 into its

decimal equivalent. Split it into two parts, that is 126 and .38

2 126

2 15 -6

2 1-7

1 7 6

Page 28: B.Sc. COMPUTER SCIENCE MICROPROCESSOR

The conversion of .38 is as follows

Thus, (126.38)10 = 176.3024

Decimal to octal conversion

1.4.3 Octal to Binary Conversion

In the octal number system the highest octal digit i.e.7 can be expressed as a 3-bit binary number. Therefore, all

the octal digits have to be represented by n 3-bit binary number. The binary equivalent of each octal digit is

shown in Table 1.2. The main advantage of the octal number system is the easiness with which any octal number

can be converted into its binary equivalent.

Octal digit 3-bit binary equivalent

0 000

1 001

2 010

3 011

4 100

5 101

6 110

7 111

Binary equivalent of octal digit

Using this conversion of octal digit into 3-bit binary number, any octal number can be converted into its binary

equivalent by simply replacing each octal digit by a 3-bit binary number. For example, conversion of 567, into its

binary equivalent is:

567 = 101110111

.38

X 8

3.04 .04

X 8 .32

X 8

2.56 .56

X 8

4.48.4

3 0 2 4

Page 29: B.Sc. COMPUTER SCIENCE MICROPROCESSOR

164 163 162 161 160 16-1 1

1 2 4 A F . B

HexMSD Point

Fig. 1.7 Hexadecimal number showing positional values (weight) of digits

(Source: http://www.egyankosh.ac.in/bitstream/123456789/10991/1/Unit-10.pdf)

Relationship of hex digits with decimal and binary numbers is given in Table 1.3. Note that to represent the

largest hex digit we require four binary bits. Therefore, the binary equivalent of all the hex digits has to be

written infour bit numbers.

Hex digit Decimal equivalent 4-bit Binary equivalent

0 0 0000

1 1 0001

2 2 0010

3 3 0100

4 4 0101

5 5 0110

6 6 0111

7 7 1000

8 8 1001

9 9 1010

A 10 1011

B 11 1100

C 12 1101

D 13 1101

E 14 1110

F 15 1111

Binary and decimal equivalent of each hex digit

1.4.4 Binary to Octal Conversion

A binary number can be converted into its octal equivalent by first making groups of 3-bits starting from the LSB

side. If the MSB side does not have 3 bits, then add 0s to make the last group of 3 bits. Then by replacing each

group of 3 bits by its octal equivalent, a binary number can be converted into its binary equivalent. For example,

consider the conversion of 1100011001, into its octal equivalent as follows:

= 001 100 01 1 001 [As the MSB side does not have 3 bits, we have added two 0's to make the last group of 3

bits]

= l 4 3 1

Thus, (1100011001)2 = (1431)8

1.5 Hexadecimal Number System

The hexadecimal number system has base 16 that is it has 16 digits (Hexadecimal means'16'). These digits are 0,

1, 2, 3, 4, 5, 6, 7, 8, 9, A, B, C, D, E, and F. The digits A, B, C, D, E and F have equivalent decimal values 10, 11, 12,

13, 14, and 15 respectively. Each Hex (Hexadecimal is popularly known as hex) digit in a hex number has a

positional value that is some power of 16 depending upon its position in the number.

Page 30: B.Sc. COMPUTER SCIENCE MICROPROCESSOR

1. Hex to Decimal Conversion

Hex to decimal conversion is done in the same way as in the cases of binary and octal to decimal conversions. A

hex number is converted into its equivalent decimal number by summing the products of the weights of each

digit and their values. This is clear from the example of conversion of 514.AF16 into its decimal equivalent.

514. AF16 = 5 X 162 + 1 X 161 + 4 X 160 + 10 X 16-1 + 15 X 16-2

= 1280+16+4+0.625+0.0586

= (1300.6836)10

2. Decimal to Hex Conversion

Adecimal number is converted into hex number in the same way as a decimal number is converted into its

equivalent binary and octal numbers. The part of the number on the left of the decimal point is to be divided

repeatedly by 16 and the part an the right of the decimal point is to be repeatedly multiplied by 16. This will be

clear from the examples of conversion of (579.26)10 into hex equivalent. Split the number into two parts, 579

and .26.Thus, (579)10 = (2443)16

2 4 3

16 579

16 36 -

3

16 2 -4

Page 31: B.Sc. COMPUTER SCIENCE MICROPROCESSOR

Decimal to hex conversion

0 .26 is converted into hex number as follows:

.26

X 16

4.16.16

X 16

2.56.56

X 16

8.96

.96

4 2 8

Thus 579.2610 = 243.42816

Decimal to hex conversion

1.5.3 Hex to Binary Conversion

As in octal number system, a hex number is converted into its binary equivalent by replacing each hex digit by its

equivalent 4-bit binary number. This is clear from the following example:

(BA6)16 =B= 1011

A 1010

6010

= (101110100110)2

1.5.4 Binary to Hex Conversion

By a process that is reverse of the process described in the above section, a binary number can be converted in

to its hex equivalent. Starting from the LSB side, group the binary number bits into groups of lour bits. If towards

the MSB side, the numbers of bits is less than four, then add zeros on the left of the MSB so that the group of

four is complete. Replace each group by its equivalent hex digit. This is clear from the following example:

(1001101110)2 = 0010 0110 1110= 2

= (26E)16

6 E

Page 32: B.Sc. COMPUTER SCIENCE MICROPROCESSOR

10 m 3 2 1 0

=010 110 101 111

= 2 6 5 7

5. Hex to Octal Conversion

Each digit of the hex number is first converted into its equivalent four bit binary number. Then the bits of the

equivalent binary number are grouped into groups of three bits. Then each group is replaced by its equivalent

octal digit to get the octal number.

For example:

(5AF)16 = 0101 1010 1111= 010110101111

=(2567)8

6. Octal to Hex Conversion

For octal to hex conversion, just reverse the process described in the section

above. This is clear from the following example:

(5457)8 = 101 100 101 111

= 1011 0010 1111

= B 2 F= (B2F)16

This method can also be applied to hex to decimal and decimal to hex conversions. For example, consider the

conversion of 3C16, into its decimal equivalent:

3C16 = 0011 1100

= 1111002

m 3 2 1N = N X B + .... N X B + N < B + N X B + N B o

When numbers, letters or words are represented by a specific group of symbols, it is said that the number, letter or

word is being encoded. The group of symbols is called as the

code. Few codes will be discussed in the following sections.

1.6.1 BCD Code

In BCD (BCD stands Binary coded decimal) code, each digit of a decimal number is converted in to its binary

equivalent. The largest decimal digit is 9; therefore the largest binary equivalent is 1001. This is illustrated as

follows

951 10 = 1001 0101 0001

= (100101010001)BCD

Check the conversion.

3C16 = 3 X161 + CX160

= 3 x 161+ 12 x 160

= 48 + 12

= (60)101111002 = 25+24+23+22

= 32+16+8+4

= (60)10Thus, 3C16 = (111100)2 = 6010

1.6 Codes

We had an overview of binary, octal and hexadecimal number system. For any number system with n base B and digits N0 (LSB), N1 N2 ..... N10 (MSB), the decimal equivalent N10 is given by

Page 33: B.Sc. COMPUTER SCIENCE MICROPROCESSOR

2. ASCII Code

The word ASCII is run acronym of American Standard Code for Information

Interchange. This is the alphanumeric code most widely used in computers. The

alphanumeric code is one that represents alphabets, numerical numbers,

punctuation marks and other special characters recognised by a computer. The ASCII

code is a 7-bit code representing 26 English alphabets, 0 through 9 digits,

punctuation marks, etc. A 7-bit code has 27 = 128 possible code groups which arc

quite sufficient.

3. Code Gray

Gray Code is a form of binary that uses a different method of incrementing from one

number to the next. With Gray Code, only one bit changes state from one position

to another. This feature allows a system designer to perform some error checking

(i.e., if more than one bit changes, the data must be incorrect).

Decimal Binary Gray Decimal Binary Gray

0 0000 0000 8 1000 1100

1 0001 0001 9 1001 1101

2 0010 0011 10 1010 1111

3 0011 0010 12 1100 1110

4 0100 0110 13 1101 1010

5 0101 0111 14 1110 1011

6 0110 0101 14 1110 1001

7 0111 0100 15 1111 1000

Gray code

1.6.4 Excess 3

Excess-3 binary-coded decimal (XS-3), also called biased representation or Excess-N,

is a numeral system used on some older computers that uses a pre-specified

number N as a biasing value. It is a way to represent values with a balanced

number of positive and negative numbers. In XS-3, numbers are represented as

decimal digits, and each digit is represented by four bits as the BCD value plus 3

(the "excess" amount)

The smallest binary number represents the smallest value. (i.e. 0 − Excess Value)

The greatest binary number represents the largest value. (i.e. 2N+1 − Excess Value − 1)

The primary advantage of XS-3 coding over BCD coding is that a decimal number

Page 34: B.Sc. COMPUTER SCIENCE MICROPROCESSOR

can be 9’s complemented (for subtraction) as easily as a binary number can be 1's

complemented; just invert all bits. In addition, when the sum of two XS-3 digits is

greater than 9, the carry bit of a four bit adder will be set high. This works because,

when adding two numbers that are greater or equal to zero, an "excess" value of

six results in the sum. Since a four bit integer can only hold values 0 to 15, an

excess of six means that any sum over nine willoverflow.

7. Binary Arithmetic

Majority of arithmetic performed by computers is binary arithmetic, that is, arithmetic on base two numbers.Decimal and floating-point numbers, also used in computer arithmetic, depend on binary representations, and an

understanding of binary arithmetic is necessary in order to understand either one.

Computers perform arithmetic on fixed-size numbers. The arithmetic of fixed size

numbers is called finite-precision arithmetic. The rules for finite-precision

arithmetic are different from the rules of ordinary arithmetic. The sizes of numbers

which can be arithmetic operands are determined when the architecture of the

computer is designed. Common sizes for integer arithmetic are eight, 16, 32, and

recently 64 bits. It is possible for the programmer to perform arithmetic on larger

numbers or on sizes which are not directly implemented in the architecture.

However, this is usually so painful that the programmer picks the most appropriate

size implemented by the architecture. This puts a burden on the computer architect

to select appropriate sizes for integers, and on the programmer to be aware of the

limitations of the size he has chosen and on finite-precision arithmetic in general.

We are considering binary arithmetic in the context of building digital logic circuits to

perform arithmetic. Not only do we have to deal with the fact of finite precision

arithmetic, we must consider the complexity of the digital logic. When there is more

than one way of performing an operation we choose the method which results in

the simplest circuit.

1. Addition

Addition of binary numbers can be carried out in a similar way by the column

method But before this, view four simple cases. In the decimal number system, 3 +

6 = 9 symbolizes the combination of 3 with 6 to get a total of9.

View the four simple cases.

• Case 1: When nothing is combined with nothing, we get nothing. The binary

representation of this is 0 + 0 = 0.

• Case 2: When nothing is combined with1, we get1. Using binary numbers to denote this

gives 0 + 1 =1.

• Case 3: Combining.1 with nothing gives 1. The binary equivalent of this is 1 + 0 = 1.

• Case 4: When we combine 1 with 1, the result is 2. Using binary numbers, we symbolize1+ 1 = 10.

The last result is sometimes confusing because of our long time association with

decimal numbers. But it is correct and makes sense because we are using binary

Page 35: B.Sc. COMPUTER SCIENCE MICROPROCESSOR

numbers. Binary number 10 stands for'1','0' and not for 10 (ten). To summarize our

results for binary addition,

0+0 = 0

0+1 = 1

1+0 = 1

1+1=10

• One can also express the rules of binary addition with a truth table. This is

important because there are techniques for designing electronic circuits that

compute functions expressed by truth tables. The fact that we can express the

rules of binary addition as a truth table implies that we can design a circuit

which will perform addition on binary numbers, and that turns out to be the

case.

•We only need to write the rules for one column of bits; we start at the right

and apply the rules to each column in succession until the final sum is formed.

Call the bits of the addend and augend A and B, and the carry in from the

previous column Ci. Call the sum S and the carry out Co.

• The truth table for one-bit binary addition looks like this:

A B Ci S Co

0 0 0 0 0

0 0 1 1 0

0 1 0 1 0

0 1 1 0 1

1 0 0 1 0

1 0 1 0 1

1 1 0 0 1

1 1 1 1 1

One-bit binary addition

This says if all three input bits are zero, both S and Co will be zero. If any one of the bits is one and the other two are zero, S will be one and Co will be zero. If two bits are 1's, S will be zero and Ci will be one. Only if all three bits are 1's, both S and Co

will be 1's.

1.7.2 Addition of SignedNumbers

Binary addition of 2’s complement signed numbers can be performed using the same

rules given above for unsigned addition. If there is a carry out of the sign bit, it is

ignored. It is possible for the result of an addition to be too large to fit in the

available space. The answer will be truncated, and will be incorrect. This is the

overflow condition discussed above. There are two rules for determining whether

overflow has occurred:

• If two numbers of opposite signs are added, overflow cannot occur.

• If two numbers of the same sign are added, overflow has occurred if and only if theresult is of the opposite

sign.

Page 36: B.Sc. COMPUTER SCIENCE MICROPROCESSOR

1.7.3 Subtraction

Addition has the property of being commutative, that is, a+b = b+a. This is not true

of subtraction. 5 – 3 is not the same as 3 – 5. For this reason, we must be careful of

the order of the operands when subtracting. We call the first operand, the number

which is being diminished, the minuend; the second operand, the amount to be

subtracted from the minuend, is the subtrahend. The result is called thedifference.

It is possible to perform binary subtraction using the same process we use for decimal

subtraction, namely subtracting individual digits and borrowing from the left. This

process quickly becomes cumbersome as you borrow across successive zeroes in

the minuend. Further, it doesn’t lend itself well to automation. Jacobowitz describes

the “carry” method of subtraction which some of you may have learned in

elementary school, where a one borrowed in the minuend is “paid back” by adding

to the subtrahend digit to the left. This means that one need look no more than one

column to the left when subtracting.

Subtraction can thus be performed a column at a time with a carry to the left,

analogous to addition. This is a process which can be automated, but we are left

with difficulties when the subtrahend is larger than the minuend or when either

operand is, signed. Since we can form the complement of a binary number easily and

can add signed numbers easily, the obvious answer to the problem of subtraction is

to take the 2’s complement of the subtrahend, then add it to the minuend. That is

51–22 = 51+ (–22).

Not only does this approach remove many of the complications of subtraction by the

usual method, but it also means special circuits to perform subtraction need not be

built All that is needed is a circuit which can form the bitwise complement of a

number and an adder.

1.7.4 Multiplication

A simplistic way to perform multiplication is by repeated addition. In the example

below, we could add 42 to the product register 27 times. In fact, some early

computers performed multiplication this way. However, one of our goals is speed,

and we can do much better using the familiar methods we have learned for

multiplying decimal numbers. Recall that the multiplicand is multiplied by each digit

of the multiplier to form a partial product, and then the partial products are added

to form the total product. Each partial product is shifted left to align on the right

with its multiplier digit.

51 minuend

-22 subtrahend

29 difference

Page 37: B.Sc. COMPUTER SCIENCE MICROPROCESSOR

42 multiplicand

x 27 multiplier

(42 X 7)294 first partialproduct84

second

partial

product

(42 X 2)

1134

total

product

Binary multiplication of unsigned (or positive 2’s complement) numbers works

exactly the same way, but is even easier because the digits of the multiplier are all

either zero or one. That means the partial products are either zero or a copy of the

multiplicand, shifted left appropriately. Consider the following binary multiplication:

0111 multiplicand

x 0101 multiplier

0111 first partial product (0111 X 1)

0000 second partial product (0111 X 0)

0111 third partial product (0111 X 1)

0000 fourth partial products (0111 X 0)

0100011 total productNotice that no true multiplication is necessary in forming the partial products. The

fundamental operations required are shifting and addition. This means we can

multiply unsigned or positive integers using only shifters andadders.

1.7.5 Division

As with the other arithmetic operations, division is based on the paper-and-pencil

approach we learned for decimal arithmetic. We will show an algorithm for unsigned

long division that is essentially similar to the decimal algorithm we learned in grade

school. Let us divide 0110101 (5310) by 0101 (510). Beginning at the left of the

dividend, we move to the right one digit at a time until we have identified a portion

of the dividend which is greater than or equal to the divisor. At this point, a one is

placed in the quotient; all digits of the quotient to the left are assumed to be zero.

The divisor is copied below the partial dividend and subtracted to produce a partial

remainder as shownbelow.

1 quotient

divisor 01010110101dividend

0101

1 partial remainder

Page 38: B.Sc. COMPUTER SCIENCE MICROPROCESSOR

Now digits from the dividend are “brought down” into the partial remainder until

the partial remainder is again greater than or equal to the divisor. Zeroes are placed

in the quotient until the partial remainder is greater than or equal to the divisor,

and then a one is placed in the quotient, as shown below.

101

0101 011010

0101

110

The divisor is copied below the partial remainder and subtracted from it to form a

new partial remainder. The process is repeated until all bits of the dividend have

been used. The quotient is complete and the result of the last subtraction is the

remainder.

1010

0101 0110101

0101

110

0101

11

Thiscompletesthedivision.Thequotientis (1010)2 (1010)andthe remainderis(11)2(310), whichistheexpected result. This algorithm works only for unsigned numbers, but it is possible to extend it to 2’s complement numbers.

Multiple choice questions:1. Aimofanynumbersystemistodealwithcertainquantitieswhichcanbemeasured,

monitored, ,manipulated arithmetically, observed and utilised.

a. recorded

b. stored

c. read

d. used

2. Which of the following is not a common numbersystem?

a. Decimal system

b. Tetra decimal system

c. Binary system

d. Octal systems

3. What are binary digits abbreviatedas?

a. Bytes

b. Giga bytes

c. Bits

Page 39: B.Sc. COMPUTER SCIENCE MICROPROCESSOR

d. Nibble

4. The 2’s complement of a binary number is obtained adding 1 to the of this number.

a. complement

b. end

c. beginning

d. 1’s complement

5. Binary number can be converted into its decimal equivalent by simply adding of

various positions in the binary number which has bit 1.

a. weights

b. number

c. ten

d. two

6. A decimal number is converted into its binary equivalent by its repeated by 2.

a. addition

b. division

c. multiplication

d. subtraction

7. Advantage of the octal number system is the ease with which any octal number can be

equivalent.converted into its

a. decimal

b. hex

c. binary

d. tetra

8. Which digits are excluded from the octal number system?

a. 1 and2

b. 0 and1

c. 7 and8

d. 8 and9

9. What should be added to last group of 3 bits if the MSB side does not have 3

bits while converting numbers from binary to octal?

a. Zero

b. One

c. Two

d. Nine

Page 40: B.Sc. COMPUTER SCIENCE MICROPROCESSOR

10. In subtraction number which is being diminished is called the minuend; the

amount to be subtracted from the minuend is the called the .

a. difference

b. subtrahend

c. subtraction

d. minus