Module 4 Co
Module 4 Co
MODULE – 1
Basic Structure of Computers: Basic Operational of Concepts, Bus Structures, Performance– Processor
Clock, Basic Performance Equation, Clock Rate, Performance Measurement.
Machine Instructions and Programs: Memory Location and Addresses, Memory Operations,
Instructions and Instruction Sequencing, Addressing Modes, Assembly Language, Additional
Instructions.
Textbook 1: Ch 1: 1.3, 1.4, 1.6.1, 1.6.2, 1.6.4, 1.6.7. Ch 2: 2.2, 2.3, 2.4, 2.5, 2.6, 2.10
PERFORMANCE
What are the factors that affect performance? Explain any four.
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 and its machine level instructions, compiler that translates
program into machine level language. For best performance, it is necessary to design the compiler, the machine instruction set,
and the hardware in a coordinated way.
The total time required to execute the program is elapsed time 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 c.
The pertinent parts of the fig. c are repeated in figure which includes the cache memory as part of the processor unit.
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
Define processor clock.
• The processor circuits are controlled by timing signals called as Clock.
• It defines constant time intervals and are called as Clock Cycles.
• To execute one instruction there are 3 basic steps namely (fetch, decode and execute).
• The performance of the processor depends on the length of the clock cycle. To obtain high performance reduce the
length of the clock cycle. Let ‘ P ’ be the number of clock cycles generated by the Processor and ‘ R ‘ be the Clock rate .
• The Clock rate is inversely proportional to the number of clock cycles.i.e R = 1/P.
Explain basic performance equation. Explain the role of parameters in the equation of the computer.
BASIC PERFORMANCE EQUATION
• Let ‘ T ‘ be total time required to execute the program.
‘N ‘ be the number of instructions contained in the program.
S ‘ be the average number of steps required to one instruction.
R’ be number of clock cycles per second generated by the processor to execute one program.
T=N*S/R
This equation is called as Basic Performance Equation.
• For the programmer the value of T is important. To obtain high performance it is necessary to reduce the values of N and
S and to increase the value of R.
CLOCK RATE
Define clock rate.
There are 2 possibilities for increasing the clock rate R.
i)Improving the integrated circuit technology(IC) makes logic circuit faster , which reduce the time needed to complete
basic step. This allows clock period P to be reduced and clock rate R to be R to be increased.
ii) Reducing the amount of processing done in one basic step , also makes it possible to reduce the clock period P.
• In the presence of a cache , the percentage of accesses to the main memory is small.Hence , much of the performance
gain expected from the use of faster technology can be realized. The value of T will be reduced by the same factor as R
is increased because S and N are not affected.
PERFORMANCE MEASUREMENT
Explain performance measurement? (OR) Explain the overall SPEC rating for the computer in a
program suite.
• The performance measure is the time taken by the computer to execute a given bench mark.
• A non profit organization called SPEC( system performance evaluation corporation) selects and publishes bench marks.
If the SPEC rating = 50 Means that the computer under test is 50 times as fast as the ultra sparc 10
• The SPEC 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
• The 2k addresses constitute the address space of the computer, and the memory can have up to 2 k addressable locations.
24-bit address generates an address space of 2 24 (16,777,216) locations. A 32-bit address creates an address space of 232
or 4G (4 giga) locations.
BYTE ADDRESSABILITY
Each• byte of addressable
In byte the memory aresuccessive
memory, addressed, thisrefer
addresses addressing usedbyteinlocations
to the successive most computers
in the memory.are called byte
• Byte locations
addressability. Hencehave addresses 0,1,2……
Byte Addressability is the process of assignment of address to successive
• If the word length of the machine is 32 bits, successive words are located at addresses 0,4,8,…., with each word
bytes consisting
of the memory. The successive bytes have the addresses 1, 2, 3, 4………….2n-1. The
of four bytes.
BIG-ENDIAN AND LITTLE-ENDIAN ASIGNMENTS
memory is accessed in words.
Define byte addressability. Explain Big-endian and Little –endian with an example.
There are two ways in which byte addresses are arranged
1) BIG-ENDIAN: lower byte addresses are used for the more significant bytes (the leftmost bytes) of the word.
2) LITTLE-ENDIAN: lower byte addresses are used for the less significant bytes (the rightmost bytes) of the word.
The same ordering is also used for labeling bits within a byte, that is, b7, b6, …., b0, from left to right.
• Consider a 32-bit integer (in hex): 0x12345678 which consists of 4 bytes: 12, 34, 56, and 78.
➢ Hence this integer will occupy 4 bytes in memory.
➢ Assume, we store it at memory address starting 1000.
➢ On little-endian, memory will look like
Address Value
1000 78
1001 56
1002 34
1003 12
WORD ALLIGNMENT
• 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 2.
• For example
(a) , if the word length is 16 (2 bytes), aligned words begin at byte addresses 0,2,4,…,
(b) a word length of 64 (23 bytes), aligned words begin at bytes addresses 0,8,16 ….
Words are said to have unaligned addresses, if words can begin at an arbitrary byte address.
MEMORY OPERATIONS
Two basic operations involving the memory are needed,
• LOAD (Read or Fetch): The load operation transfers a copy of the contents of a specific memory location to the
processor. The memory contents remain unchanged.
• STEPS
(1) Processor sends the address of the desired location to the memory
(2) Processor issues “read‟ signal to memory to fetch the data .
(3) Memory reads the data stored at that address.
(4) Memory sends the read data to the processor processor sends the address of the desired location to the memory
and requests that its contents be read.
(5) The memory reads the data stored at that address and sends them to the processor.
• STORE(Write): The store operation transfers an item of information from the processor to a
specific memory location, destroying the former contents of that location.
• STEPS
(a) Processor sends the address of the memory location where it wants to store data.
(b) Processor issues „write‟ signal to memory to store the data.
(c) Content of register(MDR) is written into the specified memory location The processor sends the address of
the desired location to the memory.
______________________________________________________________________________________________________
BRANCHING
• Consider the task of adding a list of n numbers.
• The number of entries in the list n is stored in memory location N. (Figure 2.10).
• Register R1 is used as a counter to determine the number of time the loop is executed.
• The contents of location N are loaded into register R1 at the beginning of the program.
• 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
• entry is fetched and added to R0. .
• The instruction Decrement R1 reduces the contents of R1 by 1 each time through the loop.
Then Branch 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.
✓ 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.
CONDITION CODES
What are condition code flags? Explain four commonly used flags.
The processor keeps track of information about the results of various operations. This is accomplished by recording the required
information in individual bits, called condition code flags.
✓ These flags are grouped together in a special processor-register called the condition code register (or statue register).
✓ 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 to 1 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.
ADDRESSING MODES
*****What is an addressing mode? Explain different generic addressing mode with an example for each.
The different ways in which the location of an operand is specified in an instruction are referred to as addressing modes.
✓ To execute the Add instruction in fig (a), the processor uses the value which is in register R1, as the EA of the operand.
✓ It requests a read operation from the memory to read the contents of location B. The value read is the desired operand,
which the processor adds to the contents of register R0.
✓ Indirect addressing through a memory location is also possible as shown in fig (b). In this case, the processor first reads
the contents of memory location A, then requests a second read operation using the value B as an address to obtain the
operand.
➢ In above program, Register R2 is used as a pointer to the numbers in the list, and the operands are accessed indirectly
through R2.
➢ The initialization-section of the program loads the counter-value n from memory-location N into R1 and uses the
immediate addressing-mode to place the address value NUM1, which is the address of the first number in the list, into
R2. Then it clears R0 to 0.
➢ The first two instructions in the loop implement the unspecified instruction block starting at LOOP.
➢ The first time through the loop, the instruction Add (R2), R0 fetches the operand at location NUM1 and adds it to R0.
➢ The second Add instruction adds 4 to the contents of the pointer R2, so that it will contain the address value NUM2 when
the above instruction is executed in the second pass through the loop.
INDEXING AND ARRAYS
✓ A different kind of flexibility for accessing operands is useful in dealing with lists and arrays.
Index mode
✓ The operation is indicated as X(Ri)
where X=the constant value contained in the instruction
Ri=the name of the index register
✓ The effective-address of the operand is given by EA=X+[Ri] .
✓ The contents of the index-register are not changed in the process of generating the effective-address.
✓ In an assembly language program, the constant X may be given either
→ as an explicit number or
→ as a symbolic-name representing a numerical value.
✓ Fig(a) illustrates two ways of using the Index mode. In fig(a), the index register, R1, contains the address of a memory
location, and the value X defines an offset(also called a displacement) from this address to the location where the
operand is found.
✓ An alternative use is illustrated in fig(b). Here, the constant X corresponds to a memory address, and the contents of the
index register define the offset to the operand. In either case, the effective address is the sum of two values; one is given
explicitly in the instruction, and the other is stored in a register.
Auto-decrement 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.
➢ This mode is denoted as
-(Ri) ;where Ri=pointer register
➢ These 2 modes can be used together to implement an important data structure called a stack.
__________________________________________________________________________________________________________________________________
ASSEMBLY LANGUAGE
➢ A complete set of symbolic names and rules for their use constitute an assembly language.
➢ The set of rules for using the mnemonics in the specification of complete instructions and programs is called the syntax
of the language.
➢ Programs written in an assembly language can be automatically translated into a sequence of machine instructions by a
program called an assembler.
➢ The user program in its original alphanumeric text formal is called a source program, and the assembled machine
language program is called an object program.
➢ Move instruction is written is MOVE R0,SUM ;The mnemonic MOVE represents the binary pattern, or OP code, for the
operation performed by the instruction.
➢ The instruction ADD #5,R3 ;Adds the number 5 to the contents of register R3 and puts the result back into register R3.
ASSEMBLER DIRECTIVES
What is an assembler directive? Explain some of commands in assembler directive.
➢ EQU informs the assembler about the value of an identifier (Figure: 2.18).
Ex: SUM EQU 200 ; This statement informs the assembler that the name SUM should be replaced by the value 200
wherever it appears in the program.
➢ ORIGIN tells the assembler about the starting-address of memory-area to place the data block.
➢ DATAWORD directive tells the assembler to load a value (say 100) into the location (say 204). Ex: N DATAWORD 100
➢ RESERVE directive declares that a memory-block of 400 bytes is to be reserved for data and that the name NUM1 is to
be associated with address 208.
Ex: NUM1 RESERVE 400
➢ END directive tells the assembler that this is the end of the source-program text.
➢ RETURN directive identifies the point at which execution of the program should be terminated.
➢ Any statement that makes instructions or data being placed in a memory-location may be given a label. The label(say N
or NUM1) is assigned a value equal to the address of that location.
General format of a statement
➢ Most assembly languages require statements in a source program to be written in the form:
Label Operation Operands Comment
➢ Label is an optional name associated with the memory-address where the machine language instruction produced from
the statement will be loaded.
➢ The Operation field contains the OP-code mnemonic of the desired instruction or assembler → The
➢ Operand field contains addressing information for accessing one or more operands, depending on the type of instruction.
➢ Comment field is used for documentation purpose to make the program easier to understand.
➢ Assembler program
→ replaces all symbols denoting operations & addressing-modes with binary-codes used in machine instructions.
→ replaces all names and labels with their actual values.
→ assigns addresses to instructions & data blocks, starting at the address given in the ORIGIN directive.
→ inserts constants that may be given in DATAWORD directives.
→ reserves memory-space as requested by RESERVE directives.
• Two Pass Assembler has 2 passes:
1) First Pass: Work out all the addresses of labels.
➢ As the assembler scans through a source-program, it keeps track of all names of numerical- values that
correspond to them in a symbol-table.
2) Second Pass: Generate machine code, substituting values for the labels.
➢ When a name appears a second time in the source-program, it is replaced with its value from the table
➢ The assembler stores the object-program on a magnetic-disk. The object-program must be loaded into the memory of the
computer before it is executed. For this, a Loader program is used.
➢ Debugger program is used to help the user find the programming errors.
➢ Debugger program enables the user
→ to stop execution of the object-program at some points of interest and
→ to examine the contents of various processor registers and memory-location .
Dept. of ISE / GAT Page 14
COMPUTER ORGANIZATION (21ISE34)
_________________________________________________________________________________________________________________________________
ADDITIONAL INSTRUCTIONS
LOGIC INSTRUCTIONS
• Logic operations such as AND, OR, and NOT applied to individual bits.
• These are the basic building blocks of digital-circuits.
• This 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.
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.
ROTATE OPERATIONS
• In 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.
Problem 1:
Problem 2:
List the steps needed to execute the machine instruction:
Add R4, R2, R3
in terms of transfers between the components of processor and some simple control commands. Assume that the
address of the memory-location containing this instruction is initially in register PC. Solution:
1. Transfer the contents of register PC to register MAR.
2. Issue a Read command to memory.
And, then wait until it has transferred the requested word into register MDR.
3. Transfer the instruction from MDR into IR and decode it.
4. Transfer contents of R1 and R2 to the ALU.
5. Perform addition of two operands in the ALU and transfer answer into R3.
6. Transfer contents of PC to ALU.
7. Add 1 to operand in ALU and transfer incremented address to PC.
Problem 3:
(a) Give a short sequence of machine instructions for the task “Add the contents of memory-location A
to those of location B, and place the answer in location C”. Instructions:
Load Ri, LOC and
Store Ri, LOC
are the only instructions available to transfer data between memory and the general purpose registers. Add instructions
are described in Section 1.3. Do not change contents of either location A or B.
(b) Suppose that Move and Add instructions are available with the formats:
Move Location1,
Location2 and
Add Location1, Location2
These instructions move or add a copy of the operand at the second location to the first location, overwriting the
original operand at the first location. Either or both of the operands can be in the memory or the general-purpose
registers. Is it possible to use fewer instructions of these types to accomplish the task in part (a)? If yes, give the
sequence.
Solution:
(a)
Load A, R0 Load B, R1 Add R0, R1
Store R1, C
(b) Yes;
Move B, C Add A, C
Problem 4:
A program contains 1000 instructions. Out of that 25% instructions requires 4 clock cycles,40% instructions requires 5
clock cycles and remaining require 3 clock cycles for execution. Find the total time required to execute the program
running in a 1 GHz machine.
Solution:
N = 1000
25% of N= 250 instructions require 4 clock cycles.
40% of N =400 instructions require 5 clock cycles.
35% of N=350 instructions require 3 clock cycles.
T = (N*S)/R= (250*4+400*5+350*3)/1X109 =(1000+2000+1050)/1*109= 4.05 μs.
Problem 5:
For the following processor, obtain the performance.
Clock rate = 800 MHz
No. of instructions executed = 1000
Average no of steps needed / machine instruction = 20
Solution: