Cs3351 Dpco Unit 3 Notes
Cs3351 Dpco Unit 3 Notes
COMPUTER FUNDAMENTALS
Functional Units of a Digital Computer: Von Neumann Architecture – Operation and
Operands of Computer Hardware Instruction – Instruction Set Architecture (ISA): Memory
Location, Address and Operation – Instruction and Instruction Sequencing – Addressing
Modes, Encoding of Machine Instruction – Interaction between Assembly and High Level
Language
Input Unit
The input unit consists of input devices that are attached to the computer.
These devices take input from the user and feed that in to the computer understands.
Input devices are keyboard, mouse, joystick, scanner
Central Processing Unit (CPU)
Once the information is entered into the computer by the input device, the processor
processes it.
The CPU is the control center of the computer. It first fetches instructions from memory
and then interprets them to know what is to be done. If required, data is fetched from
memory or input device.
CPU executes or performs the required computation and then either stores the output
or displays on the output device.
The CPU has three main components which are responsible for different functions
1. Arithmetic Logic Unit (ALU): This unit performs mathematical calculations and
takes logical decisions. Arithmetic calculations include addition, subtraction,
multiplication and division
2. Logical decisions involve comparison of two data items to see which one is larger
or smaller or equal
Control Unit (CU)
The Control unit coordinates and controls the data flow in and out of CPU and also
controls all the operations of ALU, memory registers and also input/output units.
It is also responsible for carrying out all the instructions stored in the program.
It decodes the fetched instruction, interprets it and sends control signals to
input/output devices until the required operation is done properly by ALU and
memory.
Memory registers
A register is a temporary unit of memory in the CPU. These are used to store the data
which is directly used by the processor.
Registers can be of different sizes(16 bit, 32 bit, 64 bit ) and each register inside the
CPU has a specific function like storing data, storing an instruction, storing address of a
location in memory etc.
The user registers can be used by an assembly language programmer for storing
operands, intermediate results etc.
Accumulator (ACC) is the main register in the ALU and contains one of the operands of
an operation to be performed in the ALU.
Memory
Memory attached to the CPU is used for storage of data and instructions and is called
internal memory, it is divided into many storage locations, each of which can store data
or instructions.
Each memory location is of the same size and has an address.
With the address, the computer can read any memory location easily without having to
search the entire memory.
when a program is executed, it’s data is copied to the internal memory and is stored in
the memory till the end of the execution.
The internal memory is also called the Primary memory or Main memory.
This memory is also called as RAM, i.e. Random Access Memory. The time of access of
data is independent of its location in memory, therefore this memory is also called
Random Access memory (RAM).
Smallest form of memory is cache and they are inbuilt within CPU and are faster to
access
The Secondary memory is used to store large volume of information. They are magnetic
disks, optical disks.
Output Unit
The output unit consists of output devices that are attached with the computer. It
converts the binary data coming from CPU to human understandable form. The
common output devices are monitor, printer, plotter etc
Interconnection between Functional Components
A computer consists of input unit that takes input, a CPU that processes the input and
an output unit that produces output. All these devices communicate with each other
through a common bus.
A bus is a transmission path, made of a set of conducting wires over which data or
information in the form of electric signals, is passed from one component to another in
a computer. The bus can be of three types – Address bus, Data bus and Control Bus.
The address bus carries the address location of the data or instruction.
The data bus carries data from one component to another
the control bus carries the control signals.
The system bus is the common communication path that carries signals to/from CPU,
main memory and input/output devices.
The input/output devices communicate with the system bus through the controller
circuit which helps in managing various input/output devices attached to the computer.
2 types of Computers:
1. Fixed Program Computers – Their function is very specific and they couldn’t be re-
programmed, e.g. Calculators.
2. Stored Program Computers – These can be programmed to carry out many different tasks,
In this stored-program concept, programs and data are stored in a separate storage unit
called memories. A computer built with this architecture would be much easier to reprogram.
The modern computers are based on a stored-program concept introduced by John Von
Neumann.
It is also known as ISA (Instruction set architecture) computer and is having three basic units:
1. The Central Processing Unit (CPU)
2. The Main Memory Unit
3. The Input/Output Device
Control Unit
A control unit (CU) handles all processor control signals. It directs all input and output
flow, fetches code for instructions, and controls how data moves around the system.
Arithmetic and Logic Unit (ALU)
The arithmetic logic unit is that part of the CPU that handles all the calculations the CPU
may need, e.g. Addition, Subtraction, Comparisons.
It performs Logical Operations, Bit Shifting Operations, and Arithmetic operations.
Main Memory Unit (Registers)
1. Accumulator: Stores the results of calculations made by ALU.
2. Program Counter (PC): Keeps track of the memory location of the next instructions
to be dealt with. The PC then passes this next address to Memory Address Register
(MAR).
3. Memory Address Register (MAR): It stores the memory locations of instructions that
need to be fetched from memory or stored into memory.
4. Memory Data Register (MDR): It stores instructions fetched from memory or any
data that is to be transferred to, and stored in, memory.
5. Current Instruction Register (CIR): It stores the opcode of the instructions that is
currently being executed.
6. Instruction Buffer Register (IBR): The instruction that is not to be executed
immediately is placed in the instruction buffer register IBR.
Input/Output Devices
Program or data is read into main memory from the input device or secondary storage
under the control of CPU input instruction.
Output devices are used to output the information from a computer. If some results
are evaluated by computer and it is stored in the computer, then with the help of
output devices, we can present them to the user.
Buses
Data is transmitted from one part of a computer to another, connecting all major
internal components to the CPU and memory, by the means of Buses.
Types:
o Data Bus: It carries data among the memory unit, the I/O devices, and the
processor.
o Address Bus: It carries the address of data (not the actual data) between memory
and processor.
o Control Bus: It carries control commands from the CPU (and status signals from
other devices) in order to control and coordinate all the activities within the
computer.
Von Neumann bottleneck –
Instruction are executed only one at a time and can be carried out sequentially.
Uniprocessor :
A type of architecture that is based on a single computing unit.
All operations (additions, multiplications, etc ) are done sequentially on the unit.
Multiprocessor :
A type of architecture that is based on multiple computing units.
Some of the operations are done in parallel and the results are joined afterwards.
Flynn Taxonomy.
MIPS Operands
Operands of the Computer Hardware Instruction
Register operand
Memory operand
Constant or immediate operands
Register Operand
In MIPS instruction set architecture, operand can either in register or memory. Most of the
arithmetic and logical instructions use register operands.
Registers are limited number of special location built directly in hardware and they are visible to
the programmer
The size of a register in the MIPS architecture is 32 bits;
groups of 32 bits are given the name word in the MIPS architecture.
The number of registers is limited to 32
Answer
The compiled program is very similar to the prior example, except we replace the variables with
the register names mentioned above plus two temporary registers, $t0 and $t1, which
correspond to the temporary variables above:
Memory Operands
Programming languages have simple variables that contain single data elements, as in these
examples, but they also have more complex data structures —arrays and structures.
These complex data structures can contain many more data elements than there are registers in
a computer.The processor can keep only a small amount of data in registers, but computer
memory contains billions of data elements.
Hence, data structures (arrays and structures) are kept in memory.
As explained above, arithmetic operations occur only on registers in MIPS instructions; thus,
MIPS must include instructions that transfer data between memory and registers. Such
instructions are called data transfer instructions.
To access a word in memory, the instruction must supply the memory address.
Memory is just a large, single-dimensional array, with the address acting as the index to that
array, starting at 0. For example, in the followingFigure, the address of the third data element is
2, and the value of Memory[2] is 10
Fig: Memory addresses and contents of memory at those locations
The data transfer instruction that copies data from memory to a register is traditionally called
load.
The format of the load instruction is the name of the operation followed by the register to be
loaded, then a constant and register used to access memory.
The sum of the constant portion of the instruction and the contents of the second register forms
the memory address. The actual MIPS name for this instruction is lw, standing for l oad word.
Fig: Actual MIPS memory addresses and contents of memory for those words.
Alignment restriction
In MIPS, words must start at addresses that are multiples of 4. This requirement is called an
alignment restriction
alignment restriction A requirement that data be aligned in memory on natural boundaries
.many architecture have alignment restriction
Big endian and little Endian
8 bit bytes are divided into two parts:
Address of the left most byte is called ―big endian‖ and right most byte is called ―little endian ―
Compiling an Assignment When an Operand Is in Memory
Example 1:
Let‘s assume that A is an array of 100 words and that the compiler has associated the variables g
and h with the registers $s1 and $s2 as before.
Let‘s also assume that the starting address, or base address, of the array is in $s3. Compile this C
assignment statement:
MIPS Code
In the given statement, there is a single operation. Whereas, one of the operands is in memory,
so we must carry this operation in two steps:
Step 1: load the temporary register($s3) + 8
Step 2: perform addition with h(($s2)), and store result in g($s1)
The constant in a data transfer instruction (8) is called the offset, and the register added to form
the address ($s3) is called thebase register.
Example 2:
Compiling Using Load and Store
What is the MIPS assembly code for the C assignment statement below?
Assume variable h is associated with register $s2 and the base address of the array A is in $s3.
MIPS code
The final instruction stores the sum into A[12], using 48 (4 × 12) as the offset and register $s3
as the base register
Load word and store word are the instructions that copy words between memory and registers
in the MIPS architecture. Other brands of computers use other instructions along with load and
store to transfer data.
Constant or Immediate Operands
Constant variables are used as one of the operand for many arithmetic operation in MIPS
architecture
The constants would have been placed in memory whenthe program was loaded.
To avoid load instruction used in arithmetic instruction we can use one operand a constant
This quick add instruction with one constant operand is called add immediate or addi. To add 4
to register $s3, we just write
Design Principle 3: Make the common case fast.
•
ADDRESSING MODES
The different ways in which the location of an operand is specified in instructions are referred to
as addressing modes.
Different types of addresses involve tradeoffs between instruction length, addressing
flexibility and complexity of address calculation.
The different types of addressing modes are:
1. Immediate addressing mode
2. Direct or absolute addressing mode
3. Indirect addressing mode
4. Register addressing mode
5. Indexed addressing mode(Displacement)
6. Relative addressing mode
7. Auto increment
8. Auto decrement
9. Implied (Stack, and a few others)
1. Immediate Addressing and Small Operands
The operand is given explicitly in the instruction.
Example: MOVE #200, R0
The above statement places the value 200 in the register R0. A common convention is to use the
sharp sign (#) in front of the value to indicate that this value is to be used as an immediate
operand.
2. Direct Addressing (Absolute addressing mode)
The operand is in a memory location; the address of this location is given explicitly in the
instruction. (In some assembly languages, this mode is called Direct Mode.
Example: MOVE LOC, R2
This instruction copies the contents of memory location of LOC to register R2.
Address field contains address of operand.
Look in memory at address for operand.
Single memory reference to access data.
3. Memory-Indirect Addressing
The effective address of the operand is the contents of a register or memory location whose
address appears in the instruction.
Ex 1 Add (R2),R0 here Register R2 is used as a pointer to the address of the operand .
Ex 2 MOV [A], R0
The initialization section of the program loads the counter value n from memory location N into
Rl and uses the immediate addressing mode to place the address value NUM 1, which is the
address of the first number in the list, into R2.
- (Ri)
11.Stack Addressing
• A stack ia linear array of reserved memory locations,It is associated with a pointer called Stack
Pointer(SP)
• In this mode, the SP always contains the address of TOP of stack, where the operand is to be
stored or located.
• This is a special case of register indirect addressing where referenced registeri is a stack pointer
• Operand is (implicitly) on top of stack.
e.g. PUSH, POP
• PUSH R – This instruction decrements SP and copies the cntents register R on to the top of stack
pointer by SP
Ex Consider the computer with three instruction classes and CPI measurements as given below
and instruction counts for each instruction class for the same program from two different
compilers are given. Assume that the computer’s clock rate is 4 GHZ. Which code sequence
will execute faster according to execution time? (6) (NOV/DEC2014)
Code from CPI for the instruction class A
B C
CPI 1 2 3
Code from Instruction count for each class
A B C
Compiler 1 2 1 2
Compiler 2 4 1 1
ANSWER
aa. Sequence 1 executes 2 + 1 + 2 = 5 instructions. Sequence 2 executes 4 + 1 + 1 = 6
instructions. Therefore, sequence 1 executes fewer instructions. We can use the equation
for CPU clock cycles based on instruction count and CPI to find the total number of clock
cycles for each sequence:
• Requires 18 bits to denote the OP code, the addressing modes, and the register.
• This leaves 14 bits to express the address that corresponds to LOC, which is clearly insufficient.
And #$FF000000. R2
• In which case the second word gives a full 32-bit immediate operand. If we want to allow an
instruction in which two operands can be specified using the Absolute addressing mode, for
example
o Move LOC1, LOC2
• Then it becomes necessary to use an additional words for the 32-bit addresses of the operands. This
approach results in instructions of variable length, dependent on the number of operands and the
type of addressing modes used.
• Using multiple words, we can implement quite complex instructions, closely resembling operations
in high-level programming languages.
• The term complex instruction set computer (CISC) has been used to refer to processors that use
instruction sets of this type.
• The restriction that an instruction must occupy only one word has led to a style of computers that
have become known as reduced instruction set computer (RISC).
• The RISC approach introduced other restrictions, such as that all manipulation of data must be done
on operands that are already in processor registers.
• This restriction means that the above addition would need a two-instruction sequence
Move (R3), R1 Add R1, R2
• If the Add instruction only has to specify the two registers, it will need just a portion of a 32-bit
word. So, we may provide a more powerful instruction that uses three operands
o Add R1, R2, R3
• Which performs the operation R3 -> [R1] + [R2]
• A possible format for such an instruction in shown in fig c. Of course, the processor has to be able
to deal with such three-operand instructions.
• In an instruction set where all arithmetic and logical operations use only register operands, the only
memory references are made to load/store the operands into/from the processor registers.
• RISC-type instruction sets typically have fewer and less complex instructions than CISC -type sets.
66. Give the formula for CPU execution time for a program.(Nov/Dec 2016)
A simple formula relates the most basic metrics (clock cycles and clock cycle time) to CPU time:
Alternatively, because clock rate and clock cycle time are inverses,
This formula makes it clear that the hardware designer can improve performance by reducing
the number of clock cycles required for a program or the length of the clock cycle.
67. What is an instruction register? (Nov/Dec 2016)
In computing, an instruction register (IR) is the part of a CPU's control unit that holds the instruction
currently being executed or decoded.
68. State the need for indirect addressing mode. Give an example. Apr/May 2017
The register or memory location that contains theaddress of the operand is a pointer. When an
execution takes place in such mode, instruction may be told to go to a specific address. Once it's there,
instead of finding an operand, it finds an address where the operand is located.
In this case the number is usually enclosed with square brackets.
LD Acc, [5];Load the value stored in the memory location pointed to by the operand into the
accumulator Memory location 5 is accessed which contains 3. Memory location 3 is accessed which is
17.
Ax becomes 17.
69. Specify the CPU performance equation. Nov/ Dec 2012
The performance equation analyzes execution time as a product of three factors that are relatively
independent of each other. The three factors are, in order, known as the instruction count (IC), clocks
per instruction (CPI), and clock time (CT). CPI is computed as an effective value.
f represents the frequency of energy-consuming transition s (0→1)
70. Give the MIPS code for the statement f=(g+h)-(i+j). May 2019
Simple arithmetic expression,assignment
int f, g, h, i, j;
f = (g + h) - (i + j);
Assume variables are assigned to $s0, $s1, $s2, $s3, $s4 respectively add
$s0, $s1, $s2 # $s0 = g + h
add $s1, $s3, $s4 # $s1 = i + j
sub $s0, $s0, $s1 # f = (g + h) - (i + j)
Part B
1.Explain the functional units of a digital computer in detail(16)
2.Explain the Von-Neumann Architecture in details(8 or 10)
3.Write about Operation and Operands of a Computer Hardware instruction(16)
4.Explain ISA in detail(8)
5.Explain the different types of addressing modes in detail(16)
6.Explain the single instruction execution in detail(8)
7.Explain about the encoding of instructions(8)
8.Write about Assembly language and High Level Language(8)