Module 1
Module 1
chapter 1
BASIC STRUCTURE OF COMPUTERS
FUNCTIONAL UNITS
Input Unit
• The computer accepts the information in the form of program & data through an input-
device.
Eg: keyboard
• Whenever a key is pressed, the corresponding letter/digit is automatically translated into its
corresponding binary-code and transmitted over a cable to either the memory or the
processor.
Memory Unit
• This unit is used to store programs & data.
• There are 2 classes of storage:
2) Secondary-storage is used when large amounts of data & many programs have to
be stored. Eg: magnetic disks and optical disks(CD-ROMs).
• The memory contains a large number of semiconductor storage cells(i.e. flip-flops), each
capable of storing one bit of information.
• The memory is organized so that the contents of one word can be stored or retrieved in one
basic operation.
• Memory in which any location can be reached in a short and fixed amount of time after
specifying its address is called RAM (Random Access Memory).
Output Unit
• This unit is used to send processed-results to the outside world.
Eg: printer, graphic displays etc.
Control Unit
• This unit is used for controlling the activities of the other units (such as memory, I/O
device).
• This unit sends control-signals (read/write) to other units and senses their states.
• Data transfers between processor and memory are also controlled by the control-unit
through timing-signals.
• Timing-signals are signals that determine when a given action is to take place.
• At some point during execution, contents of PC are incremented to point to next instruction
in the program. [The instruction is a combination of opcode and operand].
BUS STRUCTURE
• A bus is a group of lines that serves as a connecting path for several devices.
• Bus must have lines for data transfer, address & control purposes.
• Because the bus can be used for only one transfer at a time, only 2 units can actively use
the bus at any given time.
• Bus control lines are used to arbitrate multiple requests for use of the bus.
• Main advantage of single bus: Low cost and flexibility for attaching peripheral devices.
• Systems that contain multiple buses achieve more concurrency in operations by allowing 2
or more transfers to be carried out at the same time. Advantage: better performance.
Disadvantage: increased cost.
Buffer registers prevent a high-speed processor from being locked to a slow I/O device
during a sequence of data transfers.
PROCESSOR CLOCK
CLOCK RATE
⚫ Increase clock rate
➢ Improve the integrated-circuit (IC) technology to make the circuits faster
➢ Reduce the amount of processing done in one basic step (however, this may increase
the number of basic steps needed)
Increases in R that are entirely caused by improvements in IC technology affect all aspects of
the processor’s operation equally except the time to access the main memory.
-----(1)
• To achieve high performance, the computer designer must reduce the value of T, which
means reducing N and S, and increasing R.
• Care has to be taken while modifying the values since changes in one parameter may affect
the other.
PERFORMANCE MEASUREMENT
• 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
2. 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
so, T = (N*S)/R= 250*4+400*5+350*3/1*109 =1000+2000+1050/1*109= 4.05 μs
3. Assuming that the reference computer is ultra SPARCIO work station with 300 MHz
ultra SPARC processor. A company has to purchase 1000 new computers, hence
ordered testing of new computer with SPEC 2000. The following observations are
made.
The company system manager will place the order for purchasing new computers only
if the overall SPEC rating is at least 12.After the said test will the system manager
place order for purchase of new computers?
SOLUTION:
Chapter 2
MACHINE INSTRUCTIONS & PROGRAMS
• The memory consists of many millions of storage cells (flip-flops), each of which can store
a bit of information having the value 0 or 1 (Figure 2.5).
• Each group of n bits is referred to as a word of information, and n is called the word length.
• The word length can vary from 8 to 64bits.
• A unit of 8 bits is called a byte.
• Accessing the memory to store or retrieve a single item of information (either a word or a
byte) requires distinct addresses for each item location. (It is customary to use numbers from
0 through 2k-1 as the addresses of successive locations in the memory).
• If 2k=number of addressable locations, then 2k addresses constitute the address space of the
computer. For example, a 24-bit address generates an address space of 224 locations (16MB).
• Characters can be letters of the alphabet, decimal digits, punctuation marks and so on.
• Characters are represented by codes that are usually 8 bits long. E.g. ASCII code
• The three basic information quantities are: bit, byte and word.
• A byte is always 8 bits, but the word length typically ranges from 1 to 64 bits.
• It is impractical to assign distinct addresses to individual bit locations in the memory.
• In byte addressable memory, successive addresses refer to successive byte locations in the
memory.
• Byte locations have addresses 0, 1, 2. . . . .
• If the word length is 32 bits, successive words are located at addresses 0, 4, 8. .with each
word having 4 bytes.
1) Big-endian assignment: lower byte addresses are used for the more
significant bytes of the word (Figure 2.7).
WORD ALIGNMENT
• 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.
• For example, if the word length is 16(2 bytes), aligned words begin at byte addresses 0, 2, 4
. . . . . And for a word length of 64, aligned words begin at byte addresses 0, 8, 16. . . . . . .
• Words are said to have unaligned addresses, if they begin at an arbitrary byte address.
• 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.
→ a special control character with the meaning "end of string" can be used as the last
character in the string, or
MEMORY OPERATIONS
• The Load operation transfers a copy of the contents of a specific memory location to the
processor. The memory contents remain unchanged.
• The Store operation transfers the information from the processor register to the specified
memory location. This will destroy the original contents of that memory location.
R<-[LOC] means that the contents of memory location LOC are transferred into
processor register R1 (Thecontents of a location are denoted by placing square
brackets around the name of the location). R3<-[R1]+[R2] indicates the operation
that adds the contents of registers R1 and R2 ,and then placestheir sum into register
R3.
• To represent machine instructions and programs, assembly language format can be used.
• For example,
Move LOC, R1; This instruction transfers data from memory-location LOC to
processor-register R1. Thecontents of LOC are unchanged by the execution of this
instruction, but the old contents of register R1 are overwritten.
Add R1, R2, R3; This instruction adds 2 numbers contained in processor-registers R1
and R2, and placestheir sum in R3.
• A computer performs its task according to the program stored in memory. A program is a
collection of instructions which tell the processor to perform a basic operation like addition,
reading from keyboard etc.
• Possible locations that may be involved in data transfers are memory locations, processor
registers or registers in the I/O subsystem.
• C=A+B; This statement is a command to the computer to add the current values of the two
variables A and B,and to assign the sum to a third variable C.
• When the program is compiled, each variable is assigned a distinct address in memory.
• The contents of these locations represent the values of the three variables
• The statement C<-[A]+[B] indicates that the contents of memory locations A and B are
fetched from memory, transferred to the processor, sum is computed and then result is stored
in memory location C.
Three-Address Instruction
• The instruction has general format
Operation Source1, Source2, Destination
• For example, 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.
Two-Address Instruction
• The instruction has general format
Operation Source, Destination
Add A, C
One-Address Instruction
• For example, Add A ; Add the contents of memory location A to the contents of the
accumulator register and place the sum back into the accumulator.
• Load A; This instruction copies the contents of memory location A into the accumulator and
Store A; This instruction copies the contents of the accumulator into memory location
A.
• The locations of all operands are defined implicitly. The operands are stored in a structure
called pushdown stack. In this case, the instructions are called zero-address instructions.
• Access to data in the registers is much faster than to data stored in memory locations
because the registers are inside the processor.
•
The operation C<-[A]+[B] can be performed by executing the sequence of instructions
PUSH A
PUSH B
ADD
STORE X
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.
• In processors where arithmetic operations as allowed only on operands that are in processor
registers, the C=A+B task can be performed by the instruction sequence.
1) Initially, the address of the first instruction is loaded into PC (Program counter is a register
which holds the address of the next instruction to be executed)
2)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 (Figure 2.8)
3) During the execution of each instruction, the PC is incremented by 4 to point to the next
instruction.
4) Executing given instruction is a two-phase procedure.
i) In fetch phase, the instruction is fetched from the memory location (whose address
is in the PC) and placed in the IR of the processor
• 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.
• Register R1 is used as a counter to determine the number of times the loop is executed.
Hence, the contents of location N are loaded into register R1 at the beginning of the program.
• Within the body of the loop, 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.
• 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).
ADDRESSING MODES
• The different ways in which the location of an operand is specified in an instruction are
referred to as addressing modes (Table 2.1).
• Variables & constants are the simplest data-types and are found in almost every computer
program.
Register Mode
• The operand is the contents of a register.
• The name (or address) of the register is given in the instruction.
• Registers are used as temporary storage locations where the data in a register are accessed.
• For example, the instruction,
Move R1, R2 ;Copy content of register R1 into register R2
Immediate Mode
• In this case, the instruction does not give the operand or its address explicitly; instead, it
provides information from which the memory-address of the operand can be determined. We
refer to this address as the effective address(EA) of the operand.
Indirect Mode
•The register (or memory-location) that contains the address of an operand is called a
pointer. {The indirection is denoted by ( ) sign around the register or memory-location}.
* 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 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.
• 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)
* 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.
• This added flexibility is useful in accessing multiple components inside each item in a
record, where the beginning of an item is specified by the (Ri, Rj) part of the addressing-
mode. In other words, this mode implements a 3-dimensional array.
• This is similar to index-mode with an exception: The effective address is determined using
the PC in place of the general purpose register Ri.
• X(PC) denotes an effective-address of the operand which is X locations above or below the
current contents of PC.
• Since the addressed-location is identified "relative" to the PC, the name Relative mode is
associated with this type of addressing.
Branch > 0 LOOP ;Causes program execution to go to the branch target location
identified by name LOOP if branch condition is satisfied.
• The following 2 modes are useful for accessing data items in successive locations in the
memory.
Auto-increment Mode
• The effective-address of operand is the contents of a register specified in the instruction
(Fig: 2.16).
• After accessing the operand, the contents of this register are automatically incremented to
point to the next item in a list.
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.
• 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.
• 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.
• The instruction
• 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.
• Most assembly languages require statements in a source program to be written in the form:
Label Operation Operands Comment
→ The Operation field contains the OP-code mnemonic of the desired instruction
or assembler → The
• Assembler program
• 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. Thus, when a name appears a second time,
it is replaced with its value from the table. Hence, such an assembler is called a two-pass
assembler.
• Debugger program is used to help the user find the programming errors.
• Consider the problem of moving a character-code from the keyboard to the processor. For
this transfer, buffer-register(DATAIN) & a status control flags(SIN) are used.
• An analogous process takes place when characters are transferred from the processor to the
display. A buffer-register, DATAOUT, and a status control flag, SOUT are used for this
transfer.
• The buffer registers DATAIN and DATAOUT and the status flags SIN and SOUT are part
of circuitry commonly known as a device interface.
• 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.
MoveByte DATAIN,R1
• The MoveByte operation code signifies that the operand size is a byte.
• 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.
STACKS
• A stack is a list of data elements 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 (Figure: 2.21).
• 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.
• 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 SP (Stack Pointer).
• If we assume a byte-addressable memory with a 32-bit word length,
Subtract #4,SR
Move NEWITEM,(SP)
Move (SP),ITEM
Add #4,SP
QUEUE
2) A single pointer is needed to point to the top of the stack at any given time.
3) 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.
SUBROUTINES
• 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
• 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.
• The Call instruction is a special branch instruction that performs the following operations:
→ Store the contents of PC into 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.
• In this case, the return-address of the second call is also stored in the link-register,
destroying its previous contents.
• 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 LIFO order.
• This suggests that the return-addresses associated with subroutine calls should be pushed
onto a stack. A particular register is designated as the SP(Stack Pointer) to be used in this
operation.
Return instruction pops the return-address from the processor-stack into the PC.
PARAMETER PASSING
• Alternatively, parameters may be placed on the processor-stack used for saving the return-
address • Following is a program for adding a list of numbers using subroutine with the
parameters passed through registers.
• The work-space is
• Following is a program for adding a list of numbers using subroutine with the parameters
passed to stack
• Fig: 2.27 show an example of a commonly used layout for information in a stack-frame.
• The contents of FP remains fixed throughout the execution of the subroutine, unlike stack-
pointer SP, which must always point to the current top element in the stack.
Operation on Stack Frame
• Now, SP points to this return-address, and the first instruction of the subroutine is executed.
• Now, FP is to be initialized and its old contents have to be stored. Hence, the first 2
instructions in the subroutine are:
Move FP,-(SP)
Move SP,FP
• The FP is initialized to the value of SP i.e. both FP and SP point to the saved FP address.
• The 3 local variables may now be pushed onto the stack. Space for local variables is
allocated by executing the instruction
Subtract #12,SP
• Finally, the contents of processor-registers R0 and R1 are saved in the stack. At this point,
the stack-frame has been set up as shown in the fig 2.27.
• Stack is very useful data structure for holding return-addresses when subroutines are nested.
• When nested subroutines are used; the stack-frames are built up in the processor-stack.
• Consider the following program to illustrate stack frames for nested subroutines (refer fig
no. 2.28 from text book).
The Flow of Execution is as follows:
• Main program pushes the 2 parameters param2 and param1 onto the stack and then calls
SUB1.
• SUB1 has to perform an operation & send result to the main-program on the stack
(Fig:2.28& 29).
• During the process, SUB1 calls the second subroutine SUB2 (in order to perform some
subtask).
• After SUB2 executes its Return instruction; the result is stored in register R2 by SUB1.
• SUB1 then continues its computations & eventually passes required answer back to main-
program on the stack.
• When SUB1 executes return statement, the main-program stores this answers in memory-
location RESULT and continues its execution.
• 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
• 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.
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.
• 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.
• 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.
Multiply Ri,Rj
Rj= [Ri]*[Rj]
Division Ri,Rj
Rj=[Ri]/[Rj]
• The instructions that use symbolic names and acronyms are called assembly language
instructions.
• We have seen instructions that perform operations such as add, subtract, move, shift, rotate,
and branch. These instructions may use operands of different sizes, such as 32-bit and 8-bit
numbers.
Add R1, R2 ;Has to specify the registers R1 and R2, in addition to the OP code. If the
processor has 16registers, then four bits are needed to identify each
register. Additional bits are needed to indicate that the Register
addressing-mode is used for each operand.
The instruction
• 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.
• In RISC (reduced instruction set computers), any instruction occupies only one word.
• The RISC approach introduced other restrictions such as that all manipulation of data must
be done on operands that are already in processor registers.
1. Consider a computer that has a byte addressable meory organized in 32 bit words
according to the big endian scheme. A program reads ASCII characters entered at a
keyboard and stores them in successive byte locations, starting at location 2000. Show
the contents of the 3 memory words at locations 2000, 2004 and 2008 after a string
“VTUBELAGAVI” has been entered.
3. Registers R1 and R2 of a 32 bit- computer contain the decimal values 1600 and 5500.
What is the effective address of the memory operand in each of the following
instructions?
a) Load 20(R1), R5
b) Move #400, R6
c) Store R5, 30(R1,R2)
d) Add –(R2), R5
e) Subtract (R1)+, R5