Module 1: Basic Structure of Computers 1.1 Basic Operational Concepts
Module 1: Basic Structure of Computers 1.1 Basic Operational Concepts
An Instruction consists of two parts, an Operation code and operand/s as shown below:
ADD LOCA, R0
This instruction is an addition operation. The following are the steps to execute the instruction:
Step 1: Fetch the instruction from main memory into the processor
Step 2: Fetch the operand at location LOCA from main memory into the processor
Step 3: Add the memory operand (i.e. fetched contents of LOCA) to the contents of register R0
Step 4: Store the result (sum) in R0.
The same instruction can be realized using two instructions as
Load LOCA, R1
Add R1, R0
Step 1: Fetch the instruction from main memory into the processor
Step 2: Fetch the operand at location LOCA from main memory into the processor Register R1
1.3 PERFORMANCE
1.3.1 PROCESSOR CLOCK
• Processor circuits are controlled by a timing signal called a clock.
• The clock defines 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 such that each step can be completed in one clock cycle.
• Let P=length of one clock cycle R=clock rate. Relation between P and R is given by R=1/P which is
measured in cycles per second.
• Cycles per second is also called hertz(Hz)
1.3.2 BASIC PERFORMANCE EQUATION
• Let T=processor time required to execute a program
N=actual number of instruction executions
S=average number of basic steps needed to execute one machine instruction
CSE DEPT., SMVITM 3
R=clock rate in cycles per second
• The program execution time is given by
• To achieve high performance, the computer designer must reduce the value of T, which means
reducing N and S, and increasing R.
o The value of N is reduced if source program is compiled into fewer machine instructions.
o The value of S is reduced if instructions have a smaller number of basic steps to perform.
o The value of R can be increased by using a higher frequency clock.
1.3.3 PERFORMANCE MEASUREMENT
Benchmark refers to standard task used to measure how well a processor operates. To evaluate the performance
of Computers, a non-profit organization known as SPEC-System Performance Evaluation Corporation
employs agreed-upon application programs of real world for benchmarks. Accordingly, it gives performance
measure for a computer as the time required to execute a given benchmark program. The SPEC rating is
computed as follows
If SPEC rating=50 means that the computer under test is 50times as fast as reference computer. The test is
repeated for all the programs in the SPEC suite, and the geometric mean of the results is computed.
Let SPECi be the rating for program i in the suite. The overall SPEC rating for the computer is given by
Example:
Consider a 32 bit integer (in hex): 0xabcdef12. It consists of 4 bytes: ab, cd, ef, and 12. Hence this integer
will occupy 4 bytes in memory. Say we store it at memory address starting 1000. There are 24 different
orderings possible to store these 4 bytes in4 locations (1000 - 1003). 2 among these 24 possibilities are very
popular. These are called as little endian and big endian.
CONDITION CODES
In order to do conditional branches and other instructions, operations implicitly set flags. Four commonly
used (1-bit) flags
• N (negative) 1 if result –ve else 0
• Z (zero) 1 if result 0 else 0
• 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.
1.8.1 ASSEMBLER DIRECTIVES
• Directives are the assembler commands to the assembler concerning the program being assembled.
These commands are neither translated into machine opcode nor assigned any memory location in the
object program.
• 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.
MEMORY-MAPPED I/O
• Some address values are used to refer to peripheral device buffer-registers such as DATAIN and
DATAOUT.
• No special instructions are needed to access the contents of the registers; data can be transferred
between these registers and the processor using instructions such as Move, Load or Store.
• For example, contents of the keyboard character buffer DATAIN can be transferred to register R1 in
the processor by the instruction
MoveByte DATAIN,R1
• The MoveByte operation code signifies that the operand size is a byte.
CSE DEPT., SMVITM 20
• The Testbit instruction tests the state of one bit in the destination, where the bit position to be tested is
indicated by the first operand.
1.10.2 QUEUE
• Data are stored in and retrieved from a queue on a FIFO basis.
• Difference between stack and queue?
o One end of the stack is fixed while the other end rises and falls as data are pushed and popped.
o A single pointer is needed to point to the top of the stack at any given time.
1.11 SUBROUTINES
• A subtask consisting of a set of instructions which is executed many times is called a subroutine.
o The program branches to a subroutine with a Call instruction.
• Once the subroutine is executed, the calling-program must resume execution starting from the
instruction immediately following the Call instructions i.e. control is to be transferred back to the
calling-program. This is done by executing a Return instruction at the end of the subroutine.
• 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.
Following is a program for adding a list of numbers using subroutine with the parameters passed to stack
• 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.
• syntax
o LShiftL count,dst
o LShiftR count,dst
• Vacated positions are filled with zeros, and the bits shifted out are passed through the Carry
flag, C, and then dropped.
Two decimal digits represented in ASCII code are located at LOC and LOC+1. Pack these two digits in a
single byte location PACKED.
• For signed numbers, we use arithmetic shifts ( to preserve the sign of the number)
• On a right shift the sign bit must be repeated as the fill-in bit for the vacated position.
o This requirement on right shifting distinguishes arithmetic shifts from logical shifts in
which the fill-in bit is always 0. Otherwise, the two types of shifts are very similar.
o The arithmetic left shift is exactly the same as the logical left shift.
• The OP code for given instruction refers to type of operation that is to be performed.
• Source and destination field refers to source and destination operand respectively.
• The "Other info" field allows us to specify the additional information that may be needed such as an
index value or an immediate operand.
• Using multiple words, we can implement complex instructions, closely resembling operations in high-
level programming languages. The term complex instruction set computers (CISC) refers to processors
that use instruction sets of this type.