UNIT-1: Introduction To Computer Organization

Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 51

UNIT-1

INTRODUCTION TO COMPUTER ORGANIZATION


UNIT-I: Computer types, Functional units, basic operational concepts, Bus structures, Data types,
Software : Languages and Translators, Loaders, Linkers, Operating systems.

Memory locations – addresses and encoding of information – main memory operations –


Instruction formats and instruction sequences – Addressing modes and instructions – Simple input
programming – pushdown stacks – subroutines.
Computer: - Computer is an electronic device designed to accept inputs, process it at a high
speed and display the result.
1. It describes the function and design of the various units of digital computer that store
and process information.
2. It also deals with the units of computer that receive information from external sources
and send computed results to external destinations.
Computer organization: Computer organization describes the function & design of various
functional units of digital computers.
 Computer organization include hard ware details such as generations of control
signals, inter face between the computer and peripherals, memory technologies used,
modular design, flow of data, control mechanisms and so on.
Computer Architecture: Computer architecture describes the specification of an instruction
set
and the hardware units that implement the instructions.
 Computer Architecture deals with the instruction sets, address fields, operation codes,
addressing modes, effective utilization of Input /Output mechanisms and such other
aspects which would interest the users of computers.
 “Computer Organization” and “Computer Architecture” are the terms used in
describe computer systems.

1. Computer types
A computer can be defined as a fast electronic calculating machine that accepts
the digitized input information, processes it as per the list of internally stored
instructions and produces the resulting output information.
List of instructions are called programs & internal storage is called computer
memory.

The different types of computers are

Computer Organization, Unit-I, VTA Page 1


1. Personal computers: - These are the most common type found in homes, schools,
Business offices etc. These are the most common type of desk top computers with
processing and storage units along with various input and output devices.
2. Note book computers: - These are compact and portable versions of PC
3. Work stations: - These have high resolution input/output (I/O) graphics
capability, but with same dimensions as that of desktop computer. These are used
in engineering applications of interactive design work.
4. Enterprise systems or Mainframe computers: - These are used for business data
processing in medium to large corporations that require much more computing
power and storage capacity than work stations. Internet associated with servers has
become a dominant worldwide source of all types of information.
5. Super computers: - These are used for large scale numerical calculations
required in the applications like weather forecasting, aircraft design and
simulation.

2 Functional Units
A computer consists of five functionally independent main parts input, memory,
arithmetic logic unit (ALU), output and control unit.

Input device accepts the coded information as source program i.e. high level
language. This is either stored in the memory or immediately used by the processor to
perform the desired operations. The program stored in the memory determines the
processing steps. Basically the computer converts the source program to an object

Computer Organization, Unit-I, VTA Page 2


program. i.e. into machine language (using compiler).

Finally the results are sent to the outside world through output device. All of
these actions are coordinated by the control unit.

Input unit: -
The high level language program, coded data is fed to a computer through input
devices. K eyboard is a most common type. Whenever a key is pressed, one corresponding
word or number is translated into its equivalent binary code over a cable & fed either to
memory or processor. Microphone, Joystick, trackball, mouse, scanner etc are other input
devices.

Memory unit: -
Its function is to store programs and data. It is basically of two types

(i) Primary memory


(ii) Secondary memory

(i) Primary memory: - Is the one exclusively associated with the processor and operates
at the electronics speeds. Programs must be stored in this memory while they are being
executed. The memory contains a large number of semiconductors storage cells, each
capable of storing one bit of information. These are processed in a group of fixed size
called word.

To provide easy access to a word in memory, a distinct address is associated with


each word location. Addresses are numbers that identify memory location.

Number of bits in each word is called word length of the computer. Programs
must reside in the memory during execution. Instructions and data can be written into the
memory or read out under the control of processor.

Memory in which any location can be reached in a short and fixed amount of
time after specifying its address is called random-access memory (RAM). The time
required to access one word in called memory access time.

Caches are the small fast RAM units, which are coupled with the processor and
are often contained on the same IC chip to achieve high performance. Although primary
storage is essential it tends to be expensive.

(ii) Secondary memory: - Is used where large amounts of data & programs have to
be stored, particularly information that is accessed infrequently.

Computer Organization, Unit-I, VTA Page 3


Examples: - Magnetic disks & tapes, optical disks (ie CD-ROM’s), flash drives etc.,

Arithmetic logic unit (ALU):-

Most of the computer operations are executed in ALU of the processor like
addition, subtraction, division, multiplication, etc. the operands are brought into the ALU
from memory and stored in high speed storage elements called registers. Then
according to the instructions the operation is performed in the required sequence.

The control and the ALU are many times faster than other devices connected to a
computer system. This enables a single processor to control a number of external devices
such as key boards, displays, magnetic and optical disks, sensors and other mechanical
controllers.
Output unit:-
This is the counterpart of input unit. Its basic function is to send the processed
results to the outside world.

Examples:- Printer, speakers, monitors are called as I/O units as they provide both an input
and output functionality.

Control unit:-
It effectively is the nerve center that sends signals to other units and senses their
states. The actual timing signals that govern the transfer of data between input unit,
processor, memory and output unit are generated by the control unit.

3. Basic operational concepts

To perform a given task an appropriate program consisting of a list of instructions is


stored in the memory. Individual instructions are brought from the memory into the
processor, which executes the specified operations. Data to be used as operands are also
stored in the memory.

Example: - Add LOCA, R0

This instruction adds the operand at memory location LOCA, to operand in


register R0 and places the sum into register. This instruction requires the performance
of several steps,

1. First the instruction is fetched from the memory into the processor.
Computer Organization, Unit-I, VTA Page 4
2. The operand at LOCA is fetched and added to the contents of R0
3. Finally the resulting sum is stored in the register R0

The preceding add instruction combines a memory access operation with an ALU
operations. In some other type of computers, these two types of operations are performed
by separate instructions for performance reasons.
Load LOCA, R1
Add R1, R0
Transfers between the memory and the processor are started by sending the
address of the memory location to be accessed to the memory unit and issuing the
appropriate control signals. The data are then transferred to or from the memory.

Computer Organization, Unit-I, VTA Page 5


The fig. shows how memory & the processor can be connected. In addition to the
ALU & the control circuitry, the processor contains a number of registers used for several
different purposes.

The instruction register (IR):- Holds the instruction that is currently being executed.
Its output is available for the control circuits which generates the timing signals that
control the various processing elements in one execution of instruction.

The program counter PC:-


This is another specialized register that keeps track of execution of a program. It
contains the memory address of the next instruction to be fetched and executed.

Besides IR and PC, there are n-general purpose registers R0 through Rn-1.

The other two registers which facilitate communication with memory are: -
1. MAR – (Memory Address Register):- It holds the address of the location to be
accessed.
2. MDR – (Memory Data Register):- It contains the data to be written into or read
out of the address location.

Operating steps are


1. Programs reside in the memory & usually get there through the Input unit.
2. Execution of the program starts when the PC is set to point at the first instruction
of the program.
3. Contents of PC are transferred to MAR and a Read Control Signal is sent to the
memory.
4. After the time required to access the memory elapses, the address word is read out
of the memory and loaded into the MDR.
5. Now contents of MDR are transferred to the IR & now the instruction is ready to
be decoded and executed.
6. If the instruction involves an operation by the ALU, it is necessary to obtain the
required operands.
7. An operand in the memory is fetched by sending its address to MAR & Initiating
a read cycle.
8. When the operand has been read from the memory to the MDR, it is transferred
from MDR to the ALU.
9. After one or two such repeated cycles, the ALU can perform the desired
operation.
10. If the result of this operation is to be stored in the memory, the result is sent to
MDR.
11. Address of location where the result is stored is sent to MAR & a write cycle is
initiated.
Computer Organization, Unit-I, VTA Page 6
12. The contents of PC are incremented so that PC points to the next instruction that
is to be executed.

Normal execution of a program may be preempted (temporarily interrupted) if


some devices require urgent servicing, to do this one device raises an Interrupt signal.

An interrupt is a request signal from an I/O device for service by the processor.
The processor provides the requested service by executing an appropriate interrupt
service routine.

The Diversion may change the internal stage of the processor. Its state must
be saved in the memory location before interruption. When the interrupt-routine service
is completed the state of the processor is restored so that the interrupted program
may continue.

4 Bus structure

The simplest and most common way of interconnecting various parts of the
computer is to use a single bus. To achieve a reasonable speed of operation, a computer
must be organized so that all its units can handle one full word of data at a given time.
A group of lines that serve as a connecting port for several devices is called a bus.

In addition to the lines that carry the data, the bus must have lines for address and
control purpose. Simplest way to interconnect is to use the single bus as shown

Since the bus can be used for only one transfer at a time, only two units can
actively use the bus at any given time. Bus control lines are used to arbitrate multiple
requests for use of one bus.

Single bus structure is

 Low cost
 Very flexible for attaching peripheral devices

Computer Organization, Unit-I, VTA Page 7


Multiple bus structure certainly increases the performance but also increases the
cost significantly.

All the interconnected devices are not of same speed & time that leads to a bit of a
problem. This is solved by using cache registers (ie buffer registers). These buffers are
electronic registers of small capacity when compared to the main memory but of
comparable speed.

The instructions from the processor at once are loaded into these buffers and then
the complete transfer of data at a fast rate will take place.
Multi Bus structure

Computer Organization, Unit-I, VTA Page 8


5 SOFTWARE:

The computer must already contain some system software to enter and run application
programs. System software is a collection of programs that are executed as needed to perform
functions such as,

 Receiving and interpreting user commands


 Entering and editing application programs and storing them as files in secondary storage
devices
 Managing the storage and retrieval of files in secondary storage devices
 Running standard application programs such as word processors, spreadsheets, or games,
with data supplied by the user
 Controlling I/O units to receive input information and produce output results
 Translating programs from source form prepared by the user into object from consisting
of machine instructions
 Linking and running user-written application programs with existing standard library
routines, such as numerical computation packages

Computer Organization, Unit-I, VTA Page 9


Operating system software:

The operating system is a collection of routines that is used to control the sharing of and
interaction among various computer units as they execute application programs. The OS routines
perform the tasks required to assign computer resources to individual application programs.
These tasks include assigning memory and magnetic disk space to program and data files,
moving data between memory and disk units, and handling I/O operations.

Let us consider a system with one processor, one disk, and one printer. Assume that part
of the program’s task involves reading a data file from the disk into the memory, performing
some computations on the data, and printing the results.

A convenient way to illustrate the sharing of the processor time is by a time-line diagram, as
shown in the following diagram.

Computer Organization, Unit-I, VTA Page 10


During the time period t0 to t1, an OS routine initiates loading the application program
from disk to memory, waits until the transfer is completed, and then passes execution control to
the application program. A similar pattern of activity occurs during period t2 to t3 and period t4 to
t5, when the operating system transfers the data file from the disk and prints the results. At t 5, the
operating system may load and execute another application program.

The computer resources can be used more efficiently if several application programs are
to be processed. Notice that the disk and the processor are idle during most of the time period t 4
to t5. The operating system can load the next program to be executed into the memory from the
disk while the printer is operating. Similarly, during t 0 to t1, the operating system can arrange to
print the previous program’s results while the current program is being loaded from the disk.

Thus, the operating system manages the concurrent execution of several application
programs to make the best possible use of computer resources. This pattern of concurrent
execution is called multiprogramming or multitasking.

Computer Organization, Unit-I, VTA Page 11


Computer Levels of Programming Languages:
Language Categories: Computer programming languages are divided into three type
categories.

1. High level languages


2. Assembly languages
3. Machine language
High level languages: The languages with the highest level of abstraction are
collectively referred to as high-level languages.
High level languages are platform independent.
The same program code can be converted and run a computer with different microprocessors
and operating system without modification.
Eg: C++, Java, FORTRAN…….etc

Assembly languages: The languages with the lower level of abstraction are called
assembly languages.
Assembly languages are platform dependent.
Each microprocessor has its own assembly languages instruction set. I.c a program written in
the assembly languages of one microprocessor cannot be run on a computer that has different
microprocessor.
The new version microprocessor is able to execute the assembly language program designed
for previous versions.
Computer Organization, Unit-I, VTA Page 12
Eg: Intel’s Pentium III, Microprocessor can run program written in the assembly languages
of the Pentium II, Pentium pro, and Pentium…..etc.

Machine languages: The languages contain the binary values that cause the
microprocessor to perform certain operations.
When a microprocessor reads and executes an instruction it is a machine languages
instruction.
Programs written in high level assembly level languages are converted into machine level for
executed by the microprocessor.
Machine languages code that is backward compatible.

Translators

Compiler:
A compiler converts high level languages program into a machine level languages program
(byte code). The compiler takes a high level languages program as input and checks the
syntax errors of each statement and generates object code (Machine languages equivalent of
source code).
 After compilation a linker combined our object code with other required object codes
and finally gives executable file.
 A loader copies this executable file into memory and executed by the microprocessor.
The high level languages are platform independent. So a single compiler that produces
different objects code for different platforms.

A high level language statement is usually converted to a sequence of several machine code
instructions.

Computer Organization, Unit-I, VTA Page 13


Assembler:
An assembler converts assembly languages program into a machine language program (byte
code).
Assembler is less complex that that compilers. Because each assembles language instrucion
corresponds to anon unique machine code instruction.

The assembler takes an assembly languages program as input and converts into object code.
After it follows the linking and loading procedures for execution.

Some small applications written in assembly languages do not need linking other object files
directly the object file get after assembly can be executed.

Linker

a linker is a computer program that takes one or more object files generated by
a compiler and combines them into one, executable program.
Computer programs are usually made up of multiple modules that span separate object files,
each being a compiled computer program. The program as a whole refers to these separately-
compiled object files using symbols. The linker combines these separate files into a single,
unified program; resolving the symbolic references as it goes along.
Dynamic linking is a similar process, available on many operating systems, which
postpones the resolution of some symbols until the program is executed. When the program
is run, these dynamic link libraries are loaded as well. Dynamic linking does not require a
linker.
The linker bundled with most Linux systems is called ld; see our ld documentation page for
more information.
Computer Organization, Unit-I, VTA Page 14
Loaders

a loader is the part of an operating system that is responsible for


loading programs and libraries.
It is one of the essential stages in the process of starting a program, as it places programs
into memory and prepares them for execution.
Loading a program involves reading the contents of the executable file containing the
program instructions into memory, and then carrying out other required preparatory tasks to
prepare the executable for running.
Once loading is complete, the operating system starts the program by passing control to the
loaded program code.
All operating systems that support program loading have loaders, apart from highly
specialized computer systems that only have a fixed set of specialized programs.
Embedded systems typically do not have loaders, and instead the code executes directly from
ROM.
In order to load the operating system itself, as part of booting, a specialized boot loader is
used. In many operating systems the loader is permanently resident in memory, although
some operating systems that support virtual memory may allow the loader to be located in a
region of memory that is pagetable.

Computer Organization, Unit-I, VTA Page 15


6. Performance

The most important measure of the performance of a computer is how quickly it


can execute programs. The speed with which a computer executes program is affected by
the design of its hardware. For best performance, it is necessary to design the compiles,
the machine instruction set, and the hardware in a coordinated way.

The total time required to execute the program is called elapsed time which is a
measure of the performance of the entire computer system. It is affected by the speed of
the processor, the disk and the printer. The time needed to execute an instruction is
called the processor time.

Just as the elapsed time for the execution of a program depends on all units in a
computer system, the processor time depends on the hardware involved in the execution
of individual machine instructions. This hardware comprises the processor and the
memory which are usually connected by the bus as shown in the fig.

Computer Organization, Unit-I, VTA Page 16


Let us examine the flow of program instructions and data between the memory
and the processor. At the start of execution, all program instructions and the required data
are stored in the main memory. As the execution proceeds, instructions are fetched one
by one over the bus into the processor, and a copy is placed in the cache later if the same
instruction or data item is needed a second time, it is read directly from the cache.

The processor and relatively small cache memory can be fabricated on a single
IC chip. The internal speed of performing the basic steps of instruction processing on
chip is very high and is considerably faster than the speed at which the instruction and
data can be fetched from the main memory. A program will be executed faster if the
movement of instructions and data between the main memory and the processor is
minimized, which is achieved by using the cache.

For example:- Suppose a number of instructions are executed repeatedly over a short
period of time as happens in a program loop. If these instructions are available in the
cache, they can be fetched quickly during the period of repeated use. The same applies to
the data that are used repeatedly.

Processor clock: -
Processor circuits are controlled by a timing signal called clock. The clock
designs the regular time intervals called clock cycles. To execute a machine instruction
the processor divides the action to be performed into a sequence of basic steps that each
step can be completed in one clock cycle. The length P of one clock cycle is an important
parameter that affects the processor performance.
Processor used in today’s personal computer and work station have a clock rates
that range from a few hundred million to over a billion cycles per second.

Computer Organization, Unit-I, VTA Page 17


Basic performance equation

We now focus our attention on the processor time component of the total elapsed
time. Let ‘T’ be the processor time required to execute a program that has been prepared
in some high-level language.
The compiler generates a machine language object program that corresponds to
the source program. Assume that complete execution of the program requires the execution
of N machine cycle language instructions.
The number N is the actual number of instruction execution and is not
necessarily equal to the number of machine cycle instructions in the object program.
Some instruction may be executed more than once,
which in the case for instructions inside a program loop others may not be
executed all, depending on the input data used.

Suppose that the average number of basic steps needed to execute one machine
cycle instruction is S,
where each basic step is completed in one clock cycle. If clock rate is ‘R’ cycles
per second, the program execution time is given by
N× S
T=
R
this is often referred to as the basic performance equation.

We must emphasize that N, S & R are not independent parameters changing one
may affect another.
Introducing a new feature in the design of a processor will lead to improved
performance only if the overall result is to reduce the value of T.

Pipelining and super scalar operation: -

We assume that instructions are executed one after the other. Hence the value of
S is the total number of basic steps, or clock cycles, required to execute one instruction.
A substantial improvement in performance can be achieved by overlapping the execution
of successive instructions using a technique called pipelining.

Consider Add R1 R2 R3
This adds the contents of R1 & R2 and places the sum into R3.

The contents of R1 & R2 are first transferred to the inputs of ALU. After the
addition operation is performed, the sum is transferred to R3. The processor can read the
next instruction from the memory, while the addition operation is being performed. Then
of that instruction also uses, the ALU, its operand can be transferred to the ALU inputs at
the same time that the add instructions is being transferred to R3.
Computer Organization, Unit-I, VTA Page 18
In the ideal case if all instructions are overlapped to the maximum degree
possible the execution proceeds at the rate of one instruction completed in each clock
cycle. Individual instructions still require several clock cycles to complete. But for the
purpose of computing T, effective value of S is 1.

A higher degree of concurrency can be achieved if multiple instructions pipelines


are implemented in the processor.
This means that multiple functional units are used creating parallel paths
through which different instructions can be executed in parallel with such an
arrangement,
it becomes possible to start the execution of several instructions in every
clock cycle. This mode of operation is called superscalar execution.
If it can be sustained for a long time during program execution the effective
value of S can be reduced to less than one.
But the parallel execution must preserve logical correctness of programs, that
is the results produced must be same as those produced by
the serial execution of program instructions. Now a days may processor are designed in
this manner.

Clock rate

These are two possibilities for increasing the clock rate ‘R’.

1. Improving the IC technology makes logical circuit faster, which reduces the time
of execution of basic steps. This allows the clock period P, to be reduced and the
clock rate R to be increased.
2. Reducing the amount of processing done in one basic step also makes it possible
to reduce the clock period P. however if the actions that have to be performed by
an instructions remain the same, the number of basic steps needed may increase.

Increase in the value ‘R’ that are entirely caused by improvements in IC


technology affects all aspects of the processor’s operation equally with the exception of
the time it takes to access the main memory. In the presence of cache the percentage of
accesses to the main memory is small. Hence much of the performance gain excepted
from the use of faster technology can be realized.

Instruction set CISC & RISC:-


Simple instructions require a small number of basic steps to execute. Complex
instructions involve a large number of steps. For a processor that has only simple
instruction a large number of instructions may be needed to perform a given
programming task. This could lead to a large value of ‘N’ and a small value of ‘S’ on the
Computer Organization, Unit-I, VTA Page 19
other hand if individual instructions perform more complex operations, a fewer
instructions will be needed, leading to a lower value of N and a larger value of S. It is not
obvious if one choice is better than the other.

But complex instructions combined with pipelining (effective value of S ¿ 1)


would achieve one best performance. However, it is much easier to implement efficient
pipelining in processors with simple instruction sets.

Performance measurements
It is very important to be able to access the performance of a computer, designers
use performance estimates to evaluate the effectiveness of new features.

The previous argument suggests that the performance of a computer is given b y


the execution time T, for the program of interest.

Inspite of the performance equation being so simple, the evaluation of ‘T’ is


highly complex. Moreover the parameters like the clock speed and various architectural
features are not reliable indicators of the expected performance.

Hence measurement of computer performance using bench mark programs is


done to make comparisons possible, standardized programs must be used.

The performance measure is the time taken by the computer to execute a given
bench mark. Initially some attempts were made to create artificial programs that could be
used as bench mark programs. But synthetic programs do not properly predict the
performance obtained when real application programs are run.

A non profit organization called SPEC- system performance evaluation


corporation selects and publishes bench marks.

The program selected range from game playing, compiler, and data base
applications to numerically intensive programs in astrophysics and quantum chemistry. In
each case, the program is compiled under test, and the running time on a real computer is
measured. The same program is also compiled and run on one computer selected as
reference.

The ‘SPEC’ rating is computed as follows.

Computer Organization, Unit-I, VTA Page 20


If the SPEC rating = 50

Means that the computer under test is 50 times as fast as the ultra sparc 10. This
is repeated for all the programs in the SPEC suit, and the geometric mean of the result is
computed.

Let SPECi be the rating for program ‘i’ in the suite. The overall SPEC rating for
the computer is given by

Where ‘n’ = number of programs in suite.

Since actual execution time is measured the SPEC rating is a measure of the combined
effect of all factors affecting performance, including the compiler, the OS, the processor, the
memory of comp being tested.

7 Multiprocessors & multicomputer:

 Large computers that contain a number of processor units are called


multiprocessor system.

 These systems either execute a number of different application tasks in parallel or


execute subtasks of a single large task in parallel.
 All processors usually have access to all memory locations in such system &
hence they are called shared memory multiprocessor systems.
 The high performance of these systems comes with much increased complexity
and cost.
 In contrast to multiprocessor systems, it is also possible to use an interconnected
group of complete computers to achieve high total computational power. These
computers normally have access to their own memory units when the tasks they
are executing need to communicate data they do so by exchanging messages over
a communication network. This properly distinguishes them from shared memory
multiprocessors, leading to name message-passing multi computer.

Computer Organization, Unit-I, VTA Page 21


Data Types
• Registers contain either data or control information
• Control information is a bit or group of bits used to specify the sequence of command
signals needed for data manipulation
• Data are numbers and other binary-coded information that are operated on

• Possible data types in registers:


1.Numbers used in computations
2. Letters of the alphabet used in data processing
3.Other discrete symbols used for specific purposes

• All types of data, except binary numbers, are represented in binary-coded form
• A number system of base, or radix, r is a system that uses distinct symbols for r digits
• Numbers are represented by a string of digit symbols
• The string of digits 724.5 represents the quantity
2 1 0 -1
7 x 10 + 2 x 10 + 4 x 10 + 5 x 10
• The string of digits 101101 in the binary number system represents the quantity
5 4 3 2 1 0
1 x 2 + 0 x 2 + 1 x 2 + 1 x 2 + 0 x 2 + 1 x 2 = 45
• (101101)2 = (45)10
• We will also use the octal (radix 8) and hexidecimal (radix 16) number systems
2 1 0 -1
(736.4)8 = 7 x 8 + 3 x 8 + 6 x 8 + 4 x 8 = (478.5)10
1 0
(F3)16 = F x 16 + 3 x 16 = (243)10
• Conversion from decimal to radix r system is carried out by separating the number into
its integer and fraction parts and converting each part separately

• Divide the integer successively by r and accumulate the remainders


• Multiply the fraction successively by r until the fraction becomes zero
• Each octal digit corresponds to three binary digits
• Each hexadecimal digit corresponds to four binary digits
• Rather than specifying numbers in binary form, refer to them in octal or hexadecimal and
reduce the number of digits by 1/3 or ¼, respectively
n
• A binary code is a group of n bits that assume up to 2 distinct combinations
• A four bit code is necessary to represent the ten decimal digits – 6 are unused
• The most popular decimal code is called binary-coded decimal (BCD)
• BCD is different from converting a decimal number to binary
• For example 99, when converted to binary, is 1100011
• 99 when represented in BCD is 1001 1001
• The standard alphanumeric binary code is ASCII
• This uses seven bits to code 128 characters
• Binary codes are required since registers can hold binary information only

Complements
Computer Organization, Unit-I, VTA Page 22
• Complements are used in digital computers for simplifying subtraction and logical
manipulation
• Two types of complements for each base r system: r’s complement and (r – 1)’s
complement
n
• Given a number N in base r having n digits, the (r – 1)’s complement of N is defined as (r
– 1) – N
n
• For decimal, the 9’s complement of N is (10 – 1) – N
• The 9’s complement of 546700 is 999999 – 546700 = 453299
• The 9’s complement of 453299 is 999999 – 453299 = 546700
n
• For binary, the 1’s complement of N is (2 – 1) – N
• The 1’s complement of 1011001 is 1111111 – 1011001 = 0100110
• The 1’s complement is the true complement of the number – just toggle all bits
n
• The r’s complement of an n-digit number N in base r is defined as r – N
• This is the same as adding 1 to the (r – 1)’s complement
• The 10’s complement of 2389 is 7610 + 1 = 7611
• The 2’s complement of 101100 is 010011 + 1 = 010100
• Subtraction of unsigned n-digit numbers: M – N
o Add M to the r’s complement of N – this results in
n n
M + (r – N) = M – N + r
n
o If M ≥ N, the sum will produce an end carry r which is discarded
n
o If M < N, the sum does not produce an end carry and is equal to r – (N – M),
which is the r’s complement of (N – M). To obtain the answer in a familiar form,
take the r’s complement of the sum and place a negative sign in front.
Example: 72532 – 13250 = 59282. The 10’s complement of 13250 is 86750.
M = 72352
10’s comp. of N = +86750
Sum = 159282
Discard end carry = -100000
Answer = 59282
Example for M < N: 13250 – 72532 = -59282
M = 13250
10’s comp. of N = +27468
Sum = 40718
No end carry
Answer = -59282 (10’s comp. of 40718)
Example for X = 1010100 and Y = 1000011
X = 1010100
2’s comp. of Y = +0111101
Sum = 10010001
Discard end carry = -10000000
Answer X – Y = 0010001
Y = 1000011

Computer Organization, Unit-I, VTA Page 23


2’s comp. of X = +0101100
Sum = 1101111 No end carry
Answer = -0010001 (2’s comp. of 1101111)
Fixed-Point Representation
• Positive integers and zero can be represented by unsigned numbers
• Negative numbers must be represented by signed numbers since + and – signs are not
available, only 1’s and 0’s are
• Signed numbers have msb as 0 for positive and 1 for negative – msb is the sign bit
• Two ways to designate binary point position in a register
o Fixed point position
o Floating-point representation
• Fixed point position usually uses one of the two following positions
o A binary point in the extreme left of the register to make it a fraction
o A binary point in the extreme right of the register to make it an integer
o In both cases, a binary point is not actually present
• The floating-point representations uses a second register to designate the position of the
binary point in the first register
• When an integer is positive, the msb, or sign bit, is 0 and the remaining bits represent the
magnitude
• When an integer is negative, the msb, or sign bit, is 1, but the rest of the number can be
represented in one of three ways
o Signed-magnitude representation
o Signed-1’s complement representation
o Signed-2’s complement representation
• Consider an 8-bit register and the number +14
o The only way to represent it is 00001110
• Consider an 8-bit register and the number –14
o Signed magnitude: 1 0001110
o Signed 1’s complement: 1 1110001
o Signed 2’s complement: 1 1110010
• Typically use signed 2’s complement
• Addition of two signed-magnitude numbers follow the normal rules
o If same signs, add the two magnitudes and use the common sign
o Differing signs, subtract the smaller from the larger and use the sign of the larger
magnitude
o Must compare the signs and magnitudes and then either add or subtract
• Addition of two signed 2’s complement numbers does not require a comparison or
subtraction – only addition and complementation
o Add the two numbers, including their sign bits
o Discard any carry out of the sign bit position
o All negative numbers must be in the 2’s complement form
o If the sum obtained is negative, then it is in 2’s complement form
Computer Organization, Unit-I, VTA Page 24
+6 00000110 -6 11111010
+13 00001101 +13 00001101
+19 00010011 +7 00000111
+6 00000110 -6 11111010
-13 11110011 -13 11110011
-7 11111001 -19 11101101
• Subtraction of two signed 2’s complement numbers is as follows
o Take the 2’s complement form of the subtrahend (including sign bit)
o Add it to the minuend (including the sign bit)
o A carry out of the sign bit position is discarded
• An overflow occurs when two numbers of n digits each are added and the sum occupies n +
1 digits
• Overflows are problems since the width of a register is finite
• Therefore, a flag is set if this occurs and can be checked by the user
• Detection of an overflow depends on if the numbers are signed or unsigned
• For unsigned numbers, an overflow is detected from the end carry out of the msb
• For addition of signed numbers, an overflow cannot occur if one is positive and one is
negative – both have to have the same sign
• An overflow can be detected if the carry into the sign bit position and the carry out of the
sign bit position are not equal
+70 0 1000110 -70 1 0111010
+80 0 1010000 -80 1 0110000
+150 1 0010110 -150 0 1101010
• The representation of decimal numbers in registers is a function of the binary code used to
represent a decimal digit
• A 4-bit decimal code requires four flip-flops for each decimal digit
• This takes much more space than the equivalent binary representation and the circuits
required to perform decimal arithmetic are more complex
• Representation of signed decimal numbers in BCD is similar to the representation of signed
numbers in binary
• Either signed magnitude or signed complement systems
• The sign of a number is represented with four bits
o 0000 for +
o 1001 for –
• To obtain the 10’s complement of a BCD number, first take the 9’s complement and then
add one to the least significant digit
• Example: (+375) + (-240) = +135

Computer Organization, Unit-I, VTA Page 25


0 375 (0000 0011 0111 1010)
BCD

+9 760 (1001 0111 0110 0000)


BCD
0 135 (0000 0001 0011 0101)
BCD
Floating-Point Representation

• The floating-point representation of a number has two parts


• The first part represents a signed, fixed-point number – the mantissa
• The second part designates the position of the binary point – the exponent
• The mantissa may be a fraction or an integer
• Example: the decimal number +6132.789 is
o Fraction: +0.6123789
o Exponent: +04
+4
o Equivalent to +0.6132789 x 10
e
• A floating-point number is always interpreted to represent m x r
• Example: the binary number +1001.11 (with 8-bit fraction and 6-bit exponent)
o Fraction: 01001110
o Exponent: 000100
+4
o Equivalent to +(.1001110) x 2
2
• A floating-point number is said to be normalized if the most significant digit of the
mantissa is nonzero
• The decimal number 350 is normalized, 00350 is not
• The 8-bit number 00011010 is not normalized
• Normalize it by fraction = 11010000 and exponent = -3
• Normalized numbers provide the maximum possible precision for the floating-point
number

Other Binary Codes


• Digital systems can process data in discrete form only
• Continuous, or analog, information is converted into digital form by means of an analog-to-
digital converter
• The reflected binary or Gray code, is sometimes used for the converted digital data
• The Gray code changes by only one bit as it sequences from one number to the next
• Gray code counters are sometimes used to provide the timing sequences that control the
operations in a digital system
• Binary codes for decimal digits require a minimum of four bits
• Other codes besides BCD exist to represent decimal digits
• The 2421 code and the excess-3 code are both self-complementing
• The 9’s complement of each digit is obtained by complementing each bit in the code

Computer Organization, Unit-I, VTA Page 26


• The 2421 code is a weighted code
• The bits are multiplied by indicated weights and the sum gives the decimal digit
• The excess-3 code is obtained from the corresponding BCD code added to 3

Memory locations- Addresses and Encoded information

Number and character operands, as well as instructions, are stored in the memory
of a computer. The memory consists of many millions of storage cells, each of which can
store a bit of information having the value 0 or 1.
Because a single bit represents a very small amount of information, bits are
seldom handled individually.
The usual approach is to deal with them in groups of fixed size. For this
purpose, the memory is organized so that a group of n bits can be stored or retrieved in a
single, basic operation.
Each group of n bits is referred to as a word of information, and n is called
the word length. The memory of a computer can be schematically represented as a
collection of words as shown in figure.

Modern computers have word lengths that typically range from 16 to 64 bits. If
the word length of a computer is 32 bits, a single word can store a 32-bit 2’s complement
number or four ASCII characters, each occupying 8 bits (1 byte) as shown in figure.

Accessing the memory to store or retrieve a single item of information, either a


word or a byte, requires distinct names or addresses for each item location.
It is customary to use numbers from 0 through 2K-1, for some suitable values
of k, as the addresses of successive locations in the memory.
The 2k addresses constitute the address space of the computer, and the memory
can have up to 2k addressable locations. 24-bit address generates an address space of 224
(16,777,216) locations.
A 32-bit address creates an address space of 232 or 4G (4 giga) locations.

Computer Organization, Unit-I, VTA Page 27


BYTE ADDRESSABILITY:-

We now have three basic information quantities to deal with: the bit, byte and
word. A byte is always 8 bits, but the word length typically ranges from 16 to 64 bits.
The most practical assignment is to have successive addresses refer to successive byte

locations in the memory. This is the assignment used in most modern computers. The
Computer Organization, Unit-I, VTA Page 28
term byte-addressable memory is used for this assignment. Byte locations have addresses
0,1,2, …. Thus, if the word length of the machine is 32 bits, successive words are located
at addresses 0,4,8,…., with each word consisting of four bytes.

BIG-ENDIAN AND LITTLE-ENDIAN ASIGNMENTS:-

There are two ways that byte addresses can be assigned across words, as shown
in fig b. The name big-endian is used when lower byte addresses are used for the more
significant bytes (the leftmost bytes) of the word. The name little-endian is used for the
opposite ordering, where the lower byte addresses are used for the less significant bytes
(the rightmost bytes) of the word.

In addition to specifying the address ordering of bytes within a word, it is also


necessary to specify the labeling of bits within a byte or a word. The same ordering is
also used for labeling bits within a byte, that is, b7, b6, …., b0, from left to right.

WORD ALIGNMENT:-

In the case of a 32-bit word length, natural word boundaries occur at addresses 0,
4, 8, …, as shown in above fig. We say that the word locations have aligned addresses .
in general, words are said to be aligned in memory if they begin at a byte address that is a
multiple of the number of bytes in a word. The memory of bytes in a word is a power of
Computer Organization, Unit-I, VTA Page 29
2. Hence, if the word length is 16 (2 bytes), aligned words begin at byte addresses
0,2,4,…, and for a word length of 64 (23 bytes), aligned words begin at bytes addresses
0,8,16 ….

There is no fundamental reason why words cannot begin at an arbitrary byte


address. In that case, words are said to have unaligned addresses. While the most
common case is to use aligned addresses, some computers allow the use of unaligned
word addresses.

ACCESSING NUMBERS, CHARACTERS, AND CHARACTER STRINGS:-

A number usually occupies one word. It can be accessed in the memory by


specifying its word address. Similarly, individual characters can be accessed by their byte
address.

In many applications, it is necessary to handle character strings of variable


length.
The beginning of the string is indicated by giving the address of the byte
containing its first character.
Successive byte locations contain successive characters of the string. There are
two ways to indicate the length of the string.
A special control character with the meaning “end of string” can be used as the
last character in the string, or a separate memory word location or processor register can
contain a number indicating the length of the string in bytes.

Memory Operations
Both program instructions and data operands are stored in the memory. To
execute an instruction, the processor control circuits must cause the word (or words)
containing the instruction to be transferred from the memory to the processor.
Operands and results must also be moved between the memory and the processor.
Thus, two basic operations involving the memory are needed, namely, Load (or Read or
Fetch) and Store (or Write).

The load operation transfers a copy of the contents of a specific memory location
to the processor.
The memory contents remain unchanged. To start a Load operation, the processor
sends the address of the desired location to the memory and requests that its
contents be read.
The memory reads the data stored at that address and sends them to the processor.

The store operation transfers an item of information from the processor to a


specific memory location, destroying the former contents of that location.
The processor sends the address of the desired location to the memory,
Computer Organization, Unit-I, VTA Page 30
together with the data to be written into that location.

An information item of either one word or one byte can be transferred between
the processor and the memory in a single operation. Actually this transfer in between the
CPU register & main memory.

Instructions and Instruction Sequencing


A computer must have instructions capable of performing four types of
operations.
• Data transfers between the memory and the processor registers
• Arithmetic and logic operations on data
• Program sequencing and control
• I/O transfers

REGISTER TRANSFER NOTATION:-

Transfer of information from one location in the computer to another. Possible


locations that may be involved in such transfers are memory locations that may be
involved in such transfers are memory locations, processor registers, or registers in the
I/O subsystem.
Most of the time, we identify a location by a symbolic name standing for its
hardware binary address.

Example, names for the addresses of memory locations may be LOC, PLACE, A,
VAR2; processor registers names may be R0, R5; and I/O register names may be
DATAIN, OUTSTATUS, and so on.
The contents of a location are denoted by placing square brackets around the
name of the location. Thus, the expression
R1 [LOC]
Means that the contents of memory location LOC are transferred into processor register
R1.
As another example, consider the operation that adds the contents of registers R1
and R2, and then places their sum into register R3. This action is indicated as
R3[R1] + [R2]

This type of notation is known as Register Transfer Notation (RTN). Note that
the right-hand side of an RTN expression always denotes a value, and the left-hand side
is the name of a location where the value is to be places, overwriting the old contents of
that location.
Computer Organization, Unit-I, VTA Page 31
ASSEMBLY LANGUAGE NOTATION:-
Another type of notation to represent machine instructions and programs. For
this, we use an assembly language format. For example, an instruction that causes the
transfer described above, from memory location LOC to processor register R1, is
specified by the statement
Move LOC, R1

The contents of LOC are unchanged by the execution of this instruction, but the
old contents of register R1 are overwritten.

The second example of adding two numbers contained in processor registers R1


and R2 and placing their sum in R3 can be specified by the assembly language statement

Add R1, R2, R3

BASIC INSTRUCTION TYPES:-

The operation of adding two numbers is a fundamental capability in any


computer. The statement
C=A+B

In a high-level language program is a command to the computer to add the


current values of the two variables called A and B, and to assign the sum to a third
variable, C. When the program containing this statement is compiled, the three variables,
A, B, and C, are assigned to distinct locations in the memory. We will use the variable
names to refer to the corresponding memory location addresses. The contents of these
locations represent the values of the three variables. Hence, the above high-level
language statement requires the action.
C[A] + [B]

To carry out this action, the contents of memory locations A and B are fetched
from the memory and transferred into the processor where their sum is computed. This
result is then sent back to the memory and stored in location C.

Let us first assume that this action is to be accomplished by a single machine


instruction. Furthermore, assume that this instruction contains the memory addresses of
the three operands – A, B, and C. This three-address instruction can be represented
symbolically as
Computer Organization, Unit-I, VTA Page 32
Add A, B, C

Operands A and B are called the source operands, C is called the destination
operand, and Add is the operation to be performed on the operands. A general instruction
of this type has the format.
Operation Source1, Source 2, Destination

If k bits are needed for specify the memory address of each operand, the encoded
form of the above instruction must contain 3k bits for addressing purposes in addition to
the bits needed to denote the Add operation.

An alternative approach is to use a sequence of simpler instructions to perform


the same task, with each instruction having only one or two operands. Suppose that two-
address instructions of the form
Operation Source, Destination

Are available. An Add instruction of this type is


Add A, B

Which performs the operation B [A] + [B].

A single two-address instruction cannot be used to solve our original problem,


which is to add the contents of locations A and B, without destroying either of them, and
to place the sum in location C. The problem can be solved by using another two-address
instruction that copies the contents of one memory location into another. Such an
instruction is
Move B, C

Which performs the operations C [B], leaving the contents of location B unchanged.

The operation C[A] + [B] can be performed by the two-instruction sequence

Move B,C
Add A,C

Using only one-address instructions, the operation C[A] + [B] can be


performed by executing the sequence of instructions

Load A
Add B
Store C

Some early computers were designed around a single accumulator structure.


Computer Organization, Unit-I, VTA Page 33
Most modern computers have a number of general-purpose processor registers – typically
8 to 32, and even considerably more in some cases. Access to data in these registers is
much faster than to data stored in memory locations because the registers are inside the
processor.

Let Ri represent a general-purpose register. The instructions


Load A, Ri
Store Ri, A and
Add A, Ri

Are generalizations of the Load, Store, and Add instructions for the single-accumulator
case, in which register Ri performs the function of the accumulator.

When a processor has several general-purpose registers, many instructions


involve only operands that are in the register. In fact, in many modern processors,
computations can be performed directly only on data held in processor registers.
Instructions such as
Add Ri, Rj
Or
Add Ri, Rj, Rk
In both of these instructions, the source operands are the contents of registers Ri
and Rj. In the first instruction, Rj also serves as the destination register, whereas in the
second instruction, a third register, Rk, is used as the destination.

It is often necessary to transfer data between different locations. This is achieved


with the instruction
Move Source, Destination
When data are moved to or from a processor register, the Move instruction can be
used rather than the Load or Store instructions because the order of the source and
destination operands determines which operation is intended. Thus,
Move A,Ri is the same as
Load A, Ri and Move Ri, A is the same as
Store Ri , A
In processors where arithmetic operations are allowed only on operands that are
processor registers, the C = A + B task can be performed by the instruction sequence
Move A,Ri
Move B,Rj
Add Ri , Rj
Move Rj , C
In processors where one operand may be in the memory but the other must be in
register, an instruction sequence for the required task would be
Computer Organization, Unit-I, VTA Page 34
Move A, Ri
Add B, Ri
Move Ri, C
The speed with which a given task is carried out depends on the time it takes to
transfer instructions from memory into the processor and to access the operands
referenced by these instructions. Transfers that involve the memory are much slower than
transfers within the processor.
We have discussed three-, two-, and one-address instructions. It is also possible
to use instructions in which the locations of all operands are defined implicitly. Such
instructions are found in machines that store operands in a structure called a pushdown
stack. In this case, the instructions are called zero-address instructions.

INSTRUCTION EXECUTION AND STRAIGHT-LINE SEQUENCING:-

In the preceding discussion of instruction formats, we used to task


C [A] + [B] for illustration.
The following fig. shows a possible program segment for this task as it appears in the
memory of a computer.
We have assumed that the computer allows one memory operand per instruction and
has a number of processor registers.
The three instructions of the program are in successive word locations, starting at
location i. since each instruction is 4 bytes long, the second and third instructions start at
addresses i + 4 and i + 8.

Computer Organization, Unit-I, VTA Page 35


Let us consider how this program is executed. The processor contains a register
called the program counter (PC), which holds the address of the instruction to be
executed next.
To begin executing a program, the address of its first instruction (I in our example)
must be placed into the PC.
Then, the processor control circuits use the information in the PC to fetch
and execute instructions, one at a time, in the order of increasing addresses.
This is called straight-line sequencing. During the execution of each instruction,
the PC is incremented by 4 to point to the next instruction.
Thus, after the Move instruction at location i + 8 is executed, the PC contains the
value i + 12, which is the address of the first instruction of the next program segment.

Executing a given instruction is a two-phase procedure. In the first phase, called


instruction fetch, the instruction is fetched from the memory location whose address is in
the PC. This instruction is placed in the instruction register (IR) in the processor.
The instruction in IR is examined to determine which operation is to be
performed. The specified operation is then performed by the processor.

Computer Organization, Unit-I, VTA Page 36


This often involves fetching operands from the memory or from processor
registers, performing an arithmetic or logic operation, and storing the result in the
destination location.

BRANCHING:-

Consider the task of adding a list of n numbers. The program is shown in fig(a).
Instead of using a long list of add instructions, it is possible to place a single add
instruction in a program loop, as shown in fig (b).
The loop is a straight-line sequence of instructions executed as many times
as needed. It starts at location LOOP and ends at the instruction Branch > 0.
During each pass through this loop, the address of the next list entry is
determined, and that entry is fetched and added to R0.

Computer Organization, Unit-I, VTA Page 37


Assume that the number of entries in the list, n, is stored in memory location N,
as shown.
Register R1 is used as a counter to determine the number of time the loop is
executed. Hence, the contents of location N are loaded into register R1 at the beginning
of the program. Then, within the body of the loop, the instruction.
Decrement R1
Reduces the contents of R1 by 1 each time through the loop.

This type of instruction loads a new value into the program counter. As a result,
the processor fetches and executes the instruction at this new address, called the branch
target, instead of the instruction at the location that follows the branch instruction in

Computer Organization, Unit-I, VTA Page 38


sequential address order. A conditional branch instruction causes a branch only if a
specified condition is satisfied. If the condition is not satisfied, the PC is incremented in

the normal way, and the next instruction in sequential address order is fetched and
executed.
Branch > 0 LOOP

(branch if greater that 0) is a conditional branch instruction that causes a branch


to location LOOP if the result of the immediately preceding instruction,
which is the decremented value in register R1, is greater that zero. This
means that the loop is repeated, as long as there are entries in the list that are yet to be
added to R0.
at the end of the nth pass through the loop, the Decrement instruction produces
a value of zero, and hence, branching does not occur.

CONDITION CODES:-

The processor keeps track of information about the results of various operations
for use by subsequent conditional branch instructions.
This is accomplished by recording the required information in individual bits,
often called condition code flags.
These flags are usually grouped together in a special processor register called
the condition code register or status register.
Individual condition code flags are set to 1 or cleared to 0, depending on the
outcome of the operation performed.

Four commonly used flags are

N(negative) Set to 1 if the result is negative; otherwise, cleared to 0


Z(zero) Set to 1 if the result is 0; otherwise, cleared to 0
V(overflow) Set ot1 if arithmetic overflow occurs; otherwise, cleared to 0
C(carry) Set to 1 if a carry-out results from the operation; otherwise, cleared to 0

The instruction Branch > 0, discussed in the previous section, is an example of a


branch instruction that tests one or more of the condition flags.
It causes a branch if the value tested is neither negative nor equal to zero. That
is, the branch is taken if neither N nor Z is 1.
The conditions are given as logic expressions involving the condition code
flags.

In some computers, the condition code flags are affected automatically by


instructions that perform arithmetic or logic operations. However, this is not always the
Computer Organization, Unit-I, VTA Page 39
case. A number of computers have two versions of an Add instruction.

GENERATING MEMORY ADDRESSES:-

Let us return to fig b. The purpose of the instruction block at LOOP is to add a
different number from the list during each pass through the loop.
Hence, t h e Add instruction in the block must refer to a different address
during each pass. How are the

addresses to be specified ? The memory operand address cannot be given directly in a


single Add instruction in the loop. Otherwise,
it would need to be modified on each pass through the loop.

The instruction set of a computer typically provides a number of such methods,


called addressing modes.
While the details differ from one computer to another, the underlying concepts
are the same.

ADDRESSING MODES:
When a microprocessor accesses memory to either read or write data, it must specify the
memory address it needs to access.
An assembly languages instruction may use one of several addressing modes to generate this
address.
Eg: LD AC---it loads data from memory into the microprocessors AC register.

1) Direct Mode: The instruction includes a memory address.


Eg: LD AC 5 reads the data from memory location 5 and stores the data in the
CPU’S accumulator.
Ex: 0: LDAC 5

5: 10 stores into AC

2) Indirect Mode: in this the instruction includes the address of a memory location that
contains the address of an operand.
Eg: LD AC (5) - It first receives the content of location 5 that is 10 the CPU reads
the data from location 10 and loads into accumulator.

Ex: 0: LDAC (5)

5: 10

10: 20 stores into AC

Computer Organization, Unit-I, VTA Page 40


3) Register direct mode: The instruction includes the register it contains data value.
Eg: LDAC R the data loaded from register R to accumulator.

Ex: 0:LDAC R

R: 5 stores into AC
4) Register Indirect mode: the instruction contains the register that contains the
address of an operand.
Eg: LOAD (R)

Ex: 0:LDAC R

R: 5

5: 10 stores into AC
5) Immediate mode: the actual data is stored in instruction itself.
Ex: LOAD #5 the value 5 is loaded into AC register.

6) Implicit Mode: The instruction implicitly specifies the operand because it always
applies to a specific register.
Ex: CLAC Clear accumulator register.
7) Relative Mode: In this mode, the operand is an object, not the actual address. it is
added to the contents of the CPUS program counter to generate the required address.
The AC contains the address of the next instruction.
Ex: LD AC $5

EX: 0: LDAC $5

1:

5:

6: 12 PC value (1+5) is Added with Instruction


Adderss(6)
8) Index mode: the address specified in the instruction is added to the contents of tan
index register to get the actual address of an operand.
Ex: LD AC 5(X)
9) Base address mode: the address specified in instruction is added to base address
register content to get the actual address of tan operand.
Ex: LD AC 5(BR)

Name Assembler syntax Addressing function

Computer Organization, Unit-I, VTA Page 41


Immediate # Value Operand = Value
Register Ri EA = Ri
Absolute (Direct) LOC EA = LOC
Indirect (Ri) EA = [Ri]
(LOC) EA = [LOC]
Index X(Ri) EA = [Ri] + X
Base with index (Ri, Rj) EA = [Ri] + [Rj]
Base with index X (Ri, Rj) EA = [Ri] + [Rj] + X
and offset
Relative X(PC) EA = [PC] + X
Autoincrement (Ri)+ EA = [Ri]; Increment Ri
Autodecrement -(Ri) Decrement Ri; EA = [Ri]

EA = effective address
Value = a signed number

ADDITIONAL MODES:

Autoincrement mode – the effective address of the operand is the contents of a register
specified in the instruction. After accessing the operand, the contents of this register are
automatically to point to the next item in a list.

(Ri)+

Autodecrement mode – the contents of a register specified in the instruction are first
automatically decremented and are then used as the effective address of the operand.

-(Ri)

Computer Organization, Unit-I, VTA Page 42


Stacks and Queues
A computer program often needs to perform a particular subtask using the
familiar subroutine structure.
In order to organize the control and information linkage between the main
program and the subroutine, a data structure called a stack is used. This section will
describe stacks, as well as a closely related data structure called a queue.

Data operated on by a program can be organized in a variety of ways. We have


already encountered data structured as lists. Now,
we consider an important data structure known as a stack. A stack is a list of
data elements, usually words or bytes, with the accessing restriction that elements can
be added or removed at one end of the list only.
This end is called the top of the stack, and the other end is called the bottom.
Another descriptive phrase, last-in-first-out (LIFO) stack, is also used to describe this
type of storage mechanism;
the last data item placed on the stack is the first one removed when retrieval begins.
The terms push and pop are used to describe placing a new item on the stack and
removing the top item from the stack, respectively.
Fig b shows a stack of word data items in the memory of a computer. It contains
numerical values, with 43 at the bottom and -28 at the top.
A processor register is used to keep track of the address of the element of the
stack that is at the top at any given time. This register is called the stack pointer (SP).
It could be one of the general-purpose registers or a register dedicated to this function.

Computer Organization, Unit-I, VTA Page 43


Another useful data structure that is similar to the stack is called a queue. Data
are stored in and retrieved from a queue on a first-in-first-out (FIFO) basis.
Thus, if we assume that the queue grows in the direction of increasing
addresses in the memory, which is a common practice, new data are added at the
back (high-address end) and retrieved from the front (low-address end) of the queue.

There are two important differences between how a stack and a queue are
implemented.
One end of the stack is fixed (the bottom), while the other end rises and falls
as data are pushed and popped. A single pointer is needed to point to the top of the stack
at any given time.
On the other hand, both ends of a queue move to higher addresses as data
are added at the back and removed from the front.
So two pointers are needed to keep track of the two ends of the queue.

Computer Organization, Unit-I, VTA Page 44


Another difference between a stack and a queue is that, without further control, a
queue would continuously move through the memory of a computer in the direction of
higher addresses.
One way to limit the queue to a fixed region in memory is to use a circular
buffer. Let us assume that memory addresses from BEGINNING to END are assigned
to the queue.
The first entry in the queue is entered into location BEGINNING, and successive
entries are appended to the queue by entering them at successively higher addresses.
By the time the back of the queue reaches END, space will have been created at
the beginning if some items have been removed from the queue.
Hence, the back pointer is reset to the value BEGINNING and the process
continues. As in the case of a stack, care must be taken to detect when the region assigned
to the data structure is either completely full or completely empty.

Subroutines
In a given program, it is often necessary to perform a particular subtask many
times on different data-values. Such a subtask is usually called a subroutine.
For example, a subroutine may evaluate the sine function or sort a list of values into
increasing or decreasing order.

It is possible to include the block of instructions that constitute a subroutine at


every place where it is needed in the program.
However, to save space, only one copy of the instructions that constitute the
subroutine is placed in the memory, and any program that requires the use of the
subroutine simply branches to its starting location.
When a program branches to a subroutine we say that it is calling the subroutine.
The instruction that performs this branch operation is named a Call instruction.

After a subroutine has been executed, the calling program must resume
execution, continuing immediately after the instruction that called the subroutine.
The subroutine is said to return to the program that called it by executing a Return
instruction.

The way in which a computer makes it possible to call and return from
subroutines is referred to as its subroutine linkage method.
The simplest subroutine linkage method is to save the return address in a
specific location, which may be a register dedicated to this function.
Such a register is called the link register. When the subroutine completes its task,
the Return instruction returns to the calling program by branching indirectly through the link
register.

Computer Organization, Unit-I, VTA Page 45


The Call instruction is just a special branch instruction that performs the
following operations

• Store the contents of the PC in the link register

• Branch to the target address specified by the instruction


The Return instruction is a special branch instruction that performs the operation
• Branch to the address contained in the link register

Computer Organization, Unit-I, VTA Page 46


SUBROUTINE NESTING AND THE PROCESSOR STACK:-

A common programming practice, called subroutine nesting, is to have one subroutine


call another. In this case, the return address of the second call is also stored in the link register,
destroying its previous contents.
Hence, it is essential to save the contents of the link register in some other location
before calling another subroutine. Otherwise, the return address of the first subroutine will be
lost.
Subroutine nesting can be carried out to any depth. Eventually, the last
subroutine called completes its computations and returns to the subroutine that called it.
The return address needed for this first return is the last one generated in the nested call

sequence. That is, return addresses are generated and used in a last-in-first-out order.
This suggests that the return addresses associated with subroutine calls should be pushed
onto a stack.
A particular register is designated as the stack pointer, SP, to be used in this
operation. The stack pointer points to a stack called the processor stack.
The Call instruction pushes the contents of the PC onto the processor stack and loads
the subroutine address into the PC.
The Return instruction pops the return address from the processor stack into the PC.

PARAMETER PASSING:-
When calling a subroutine, a program must provide to the subroutine the
parameters, that is, the operands or their addresses, to be used in the computation.
Later, the subroutine returns other parameters, in this case, the results of the
computation.
This exchange of information between a calling program and a subroutine is referred
to as parameter passing. Parameter passing may be accomplished in several ways.
The parameters may be placed in registers or in memory locations, where they can be
accessed by the subroutine. Alternatively, the parameters may be placed on the processor
stack used for saving the return address.

Computer Organization, Unit-I, VTA Page 47


The purpose of the subroutines is to add a list of numbers. Instead of passing the
actual list entries, the calling program passes the address of the first number in the list.
This technique is called passing by reference. The second parameter is passed by value,
that is, the actual number of entries, n, is passed to the subroutine.

9. Additional instructions

LOGIC INSTRUCTIONS:

Logic operations such as AND, OR, and NOT, applied to individual bits, are the basic
building blocks of digital circuits, as described. It is also useful to be able to perform
logic operations is software, which is done using instructions that apply these operations
to all bits of a word or byte independently and in parallel. For example, the instruction

Not dst

SHIFT AND ROTATE INSTRUCTIONS:-


There are many applications that require the bits of an operand to be shifted right
or left some specified number of bit positions. The details of how the shifts are performed
depend on whether the operand is a signed number or some more general binary-coded
information. For general operands, we use a logical shift. For a number, we use an
arithmetic shift, which preserves the sign of the number.

Computer Organization, Unit-I, VTA Page 48


Logical shifts:-
Two logical shift instructions are needed, one for shifting left (LShiftL) and
another for shifting right (LShiftR). These instructions shift an operand over a number of
bit positions specified in a count operand contained in the instruction. The general form
of a logical left shift instruction is

LShiftL count, dst

Computer Organization, Unit-I, VTA Page 49


Rotate Operations:-
In the shift operations, the bits shifted out of the operand are lost, except for the
last bit shifted out which is retained in the Carry flag C.
To preserve all bits, a set of rotate instructions can be used. They move the bits
that are shifted out of one end of the operand back into the other end. Two versions of both
the left and right rotate instructions
are usually provided. In one version, the bits of the operand are simply rotated. In the
other version, the rotation includes the C flag.

Computer Organization, Unit-I, VTA Page 50


Computer Organization, Unit-I, VTA Page 51

You might also like