Unit 3
Unit 3
ORGANIZATION
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.
FUNCTIONAL UNITS OF A DIGITAL COMPUTER: VON NEUMANN ARCHITECTURE
The modern day computer system’s functional unit is given by Von Neumann Architecture
Historically there have been 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, applications are
stored on them, hence the name.
The modern computers are based on a stored-program concept introduced by John Von Neumann. In this stored-
program concept, programs and data are stored in a separate storage unit called memories.
• 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.
• Basically the computer converts one source program to an object
program. i.e. into machine language.
• 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 source program/high level language program/coded
information/simply data is fed to a computer through input devices.
• keyboard 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.
• Joysticks, trackballs, mouse, scanners etc are other input devices
Central Processing Unit (CPU)
• Control unit:-
It 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.
Basic operational concepts
1. Programs reside in the memory & usually get these through the I/P
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. 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. If the result of this operation is to be stored in the memory, the
result is sent to MDR.
9. Address of location where the result is stored is sent to MAR & a
write cycle is initiated.
10. The contents of PC are incremented so that PC points to the next
instruction that is to be executed.
Operations of Computer Hardware
• Every computer must be able to perform arithmetic. The MIPS
assembly language notation is:
add a, b, c #add b and c and put in a
Example : To add four variables (adding b,c,d and e and place in a)
Compiling Two C Assignment Statements into MIPS
This segment of a C program contains the five variables a, b, c, d, and e.
a = b + c;
d = a – e;
The translation from C to MIPS assembly language instructions is
performed by the compiler.
A MIPS instruction operates on two source operands and places the
result in one destination operand. Hence, the two simple statements
above compile directly into these two MIPS assembly language
instructions:
add a, b, c
sub d, a, e
Compiling a Complex C Assignment into MIPS
• A somewhat complex statement contains the five variables f, g, h, i,
and j:
f = (g + h) – (i + j);
What might a C compiler produce?
• The compiler must break this statement into several assembly
instructions, since only one operation is performed per MIPS
instruction.
add t0,g,h # temporary variable t0 contains g + h
add t1,i,j # temporary variable t1 contains i + j
sub f,t0,t1 # f gets t0 – t1, which is (g + h) – (i + j)
Operands of the Computer Hardware
• The operands of arithmetic instructions must be from special
locations built directly in hardware called registers.
• Registers are primitives used in hardware design. They are the bricks
of computer construction.
• The size of a register in the MIPS architecture is 32 bits; groups of 32
bits are said to be word.
• One major difference between the variables of a programming
language and registers is the limited number of registers
• Although we could simply write instructions using numbers for
registers, from 0 to 31, the MIPS convention is to use two-character
names following a dollar sign to represent a register.
• Use $s0, $s1, . . . for registers that correspond to variables in C and
Java programs and $t0, $t1, . . . for temporary registers needed to
compile the program into MIPS instructions.
Compiling a C Assignment Using Registers
• Example assignment statement:
f = (g + h) – (i + j);
• The variables f, g, h, i, and j are assigned to the registers $s0, $s1, $s2,
$s3, and $s4, respectively. What is the compiled MIPS code?
• Replace the variables with the register names and two temporary
registers, $t0 and $t1, which correspond to the temporary variables
above:
add $t0,$s1,$s2 # register $t0 contains g + h
add $t1,$s3,$s4 # register $t1 contains i + j
sub $s0,$t0,$t1 # f gets $t0 – $t1, which is (g + h)–(i + j)
Memory Operands
• The processor can keep only a small amount of data in registers, but
computer memory contains billions of data elements.
• 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, the
address of the third data element is 2, and the value of Memory [2] is
10.
• 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 load
word.
• Compiling an Assignment When an Operand Is in Memory
• 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:
g = h + A[8];
• The data should be placed in a temporary register for use in the next
instruction. The compiled instruction is
lw $t0,32($s3) # Temporary reg $t0 gets A[8]
# 8*4(4 bytes per word)
add $s1,$s2,$t0 # g = h + A[8]
• Th e constant in a data transfer instruction (8) is called the off set, and
the register added to form the address ($s3) is called the base register.
• Compiling Using Load and Store
• Assume variable h is associated with register $s2 and the base address of
the array A is in $s3. What is the MIPS assembly code for the C assignment
statement below?
A[12] = h + A[8];
lw $t0,32($s3) # Temporary reg $t0 gets A[8]
add $t0,$s2,$t0 # Temporary reg $t0 gets h + A[8]
• The final instruction stores the sum into A[12], using 48 (4 12) as the off
set and register $s3 as the base register.
sw $t0,48($s3) # Stores h + A[8] back into A[12]
• 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
• Most of the MIPS arithmetic instructions have a constant as an
operand. We would have to load a constant from memory.
• For example, to add the constant 4 to register $s3, we could use the
code
lw $t0, AddrConstant4($s1) # $t0 = constant 4
add $s3,$s3,$t0 # $s3 = $s3 + $t0 ($t0 == 4)
assuming that $s1 + AddrConstant4 is the memory address of the
constant 4.
• This quick add instruction with one constant operand is called add
immediate or addi.
To add 4 to register $s3, we just write
addi $s3,$s3,4 # $s3 = $s3 + 4
Memory Locations and Addresses
• The memory consists of many millions of storage cells, each of which
can store a bit of information having the value 0 or 1.
• The usual approach is to deal with them in groups of fixed size.
• 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.
• Modern computers have word lengths range from 16 to 64 bits.
• If the word length of a computer is 32 bits, a single word can store a
32-bit signed number. or four ASCII-encoded characters, each
occupying 8 bits.
• A unit of 8 bits is called a byte.
Byte Addressability
Three basic information quantities : bit, byte, and word.
• A byte is always 8 bits, but the word length typically ranges from 16
to 64 bits.
• It is difficult to assign distinct addresses to individual bit locations in
the memory rather assign byte locations in the memory.
• The 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 Assignments
There are two ways that byte addresses can be assigned:
• big-endian - used when lower byte addresses are used for the more
significant bytes (the leftmost bytes) of the word.
• little-endian - used when the lower byte addresses are used for the
less significant bytes (the rightmost bytes) of the word.
Word Alignment
• 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 byte addresses 0, 8, 16, . . . .
Accessing Numbers and Characters
• A number usually occupies one word, and can be accessed in the
memory by specifying its word address.
• Similarly, individual characters can be accessed by their byte address.
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 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, Read and Write.
• The Read operation transfers a copy of the contents of a specific
memory location to the processor.
• The Write operation transfers an item of information from the
processor to a specific memory location.
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
• Possible locations are memory locations, processor registers, or
registers in the I/O subsystem.
• Names that represent the addresses of memory locations may be
LOC, PLACE, A, or VAR2.
• Predefined names for the processor registers may be R0 or R5.
• Registers in the I/O subsystem may be identified by names such as
DATAIN or OUTSTATUS.
• To describe the transfer of information, the contents of any location
are denoted by placing square brackets around its name.
Thus, the expression
R2 ← [LOC]
means that the contents of memory location LOC are transferred
into processor register R2.
• As another example, consider the operation that adds the contents of
registers R2 and R3, and places their sum into register R4. This action
is indicated as
R4 ← [R2] + [R3]
• This type of notation is known as Register Transfer Notation (RTN).
• Transferring data from a source location A to a destination location B
means that the contents of location A are read and then written into
location B.
Assembly-Language Notation
• This is another type of notation to represent machine instructions and
programs.
• For this, we use assembly language. For example, transfer from
memory location LOC to processor register R2, is specified by the
statement
Load R2, LOC
• The second example of adding two numbers contained in processor
registers R2 and R3 and placing their sum in R4 can be specified by the
assembly-language statement
Add R4, R2, R3
• In this case, registers R2 and R3 hold the source operands, while R4 is
the destination.
RISC and CISC Instruction Sets
• The restriction that each instruction must fit into a single word
reduces the complexity and the number of different types of
instructions. Such computers are called Reduced Instruction Set
Computers (RISC).
• An alternative to the RISC approach is to make use of more complex
instructions which may span more than one word of memory, and
which may specify more complicated operations. Computers based on
this idea have been subsequently called Complex Instruction Set
Computers (CISC).
Introduction to RISC Instruction Sets
Two key characteristics of RISC instruction sets are:
• Each instruction fits in a single word.
• A load/store architecture is used, in which
– Memory operands are accessed only using Load and Store instructions.
– All operands involved in an arithmetic or logic operation must either be
in processor registers, or one of the operands may be given explicitly
within the instruction word.
• At the start of execution of a program, all instructions and data used in the
program are stored in the memory of a computer.
• If operands are expected to be in processor registers before they can be used
by an instruction, then it is necessary to first bring these operands into the
registers.
• This task is done by Load instructions which copy the contents of a memory
location into a processor register.
Load instructions are of the form
Load destination, source
or more specifically
Load processor_register, memory_location
• Let us now consider a typical arithmetic operation.