Module 2 - Updated
Module 2 - Updated
1. The computer accepts information in the form of programs and data through
an input unit and stores it in the memory.
2. Information stored in the memory is fetched under program control into an
arithmetic and logic unit, where it is processed.
3. Processed information leaves the computer through an output unit.
4. All activities in the computer are directed by the control unit.
Basic Operational Concepts
Basic Operational Concepts
In addition to the ALU and the control circuitry, the processor contains a number of
registers used for several different purposes. The instruction register (IR) holds the
instruction that is currently being executed.The program counter (PC) contains the
memory address of the next instruction to be fetched and executed. During the
execution of an instruction, the contents of the PC are updated to correspond to
the address of the next instruction to be executed. In addition to the IR and PC,
there are general-purpose registers R0 through Rn−1, often called processor
registers. They serve a variety of functions, including holding operands that have
been loaded from the memory for processing.
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 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 that typically 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, as
Memory Locations and Addresses
Memory Locations and Addresses
We now have three basic information quantities to deal with: bit, byte, and word. A
byte is always 8 bits, but the word length typically ranges from 16 to 64 bits. It is
impractical to assign distinct addresses to individual bit locations in the memory.
The most practical method is to assign addresses to each byte in memory. The term
byte-addressable memory is used for this assignment.
There are two ways that byte addresses can be assigned across words. The name
big-endian is used when lower byte addresses are used for the more significant
bytes (the leftmost bytes) of the word. The name little-endian is used for the
opposite ordering, where the lower byte addresses are used for the less significant
bytes (the rightmost bytes) of the word.
Instruction Set Architecture
Instruction Set Architecture defines the type of instructions supported by the
processor. Based on the type of operation they perform instructions are classified
to 4:
ISA also defines the length and format of each type of instructions.
Some Instructions
● Possible locations that may be involved in transfers are memory locations,
processor registers, or registers in the I/O subsystem.
● For example, 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.
● R5. Registers in the I/O subsystem may be identified by names such as
DATAIN or OUTSTATUS.
● Load R2, LOC
This instruction reads the contents of a memory location whose address is
represented symbolically by the label LOC and loads them into processor
register R2. The originalcontents of location LOC are preserved, whereas
those of register R2 are overwritten.
Some Instructions
● Add R4, R2, R3
add the contents of registers R2 and R3, then places sum into register R4. The
operands in R2 and R3 are not altered, but R4 is overwritten by the sum.
● Store R4, LOC
copies the operand in register R4 to memory location LOC. The original
contents of location LOC are overwritten, but those of R4 are preserved.
● Add R4, R2
Add contents of registers R4 and R2 and place sum in register R4
● Load A Acc ← [ A ]
● Add R0 Acc ← [ Acc ] +[ R0 ]
● Store C C ← [ Acc ]
One operand will be taken as the accumulator (Special register that store
intermediate value of ALU)
Register Transfer Notation
To describe the transfer of information, the contents of any location are denoted by
placing square brackets around its name.
R2 ← [LOC]
contents of memory location LOC are transferred into processor register R2.
R4 ← [R2]+[R3]
adds the contents of registers R2 and R3, and places their sum into register R4.
This type of notation is known as Register Transfer Notation (RTN). Note that the
right hand side of an RTN expression always denotes a value, and the left-hand
side is the name of a location where the value is to be placed, overwriting the old
contents of that location.
Assembly Language Notation
Load R2, LOC
transfer of data, from memory location LOC to processor register R2
Add R4, R2, R3
adding two numbers contained in processor registers R2 and R3 and placing their
sum in R4
An instruction specifies an operation to be performed and the operands involved.
In the above examples, we used the English words Load and Add to denote the
required operations. In the assembly-language instructions of actual (commercial)
processors, such operations are defined by using mnemonics, which are typically
abbreviations of the words describing the operations.
Example : Load maybe LD, Store maybe ST or STR
RISC and CISC Instruction Sets
There are two fundamentally different approaches in the design of instruction sets
for modern computers.
1. One popular approach is based on the premise that higher performance can
be achieved if each instruction occupies exactly one word in memory, and all
operands required for an arithmetic or logic operation are already in processor
registers. The restriction that each instruction must fit into a single word
reduces the complexity and the number of different types of instructions that
may be included in the instruction set of a computer. Such computers are
called Reduced Instruction Set Computers (RISC).
2. Makes use of more complex instructions that takes more than one word of
memory. Instructions may take more than 1 clock cycle to execute. Required
more data types and more complex addressing modes. These are called called
Complex Instruction Set Computers (CISC).
Instruction Execution and Straight-Line Sequencing
Instruction Execution and Straight-Line Sequencing
● When the execution begins PC (Program Counter) will contain the address of
first instruction to be executed ie, i in fig.
● Next, 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.
● During the execution of each instruction, the PC is incremented by 4 to point to
the next instruction.
● Thus, after the Store instruction at location i + 12 is executed, the PC contains
the value i + 16, which is the address of the first instruction of the next program
segment.
Instruction Execution and Straight-Line Sequencing
Instead of using a long list of Load and Add instructions, it is possible to implement
a program loop using branch statements.
Assume that the number of entries in the list, n, is stored in memory location N and
it is loaded to Register R2 which is used as a counter to determine the number of
times the loop is executed.
Branching
This branch instruction loads a new address into the program counter. As a result, the
processor fetches and executes the instruction at this new address, called the branch
target, instead of the instruction that follows the branch instruction in sequential address
order. 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.
Branch_if_[R2]>0 LOOP
is a conditional branch instruction that causes a branch to location LOOP if the contents of
register R2 are greater than zero ie,there are more numbers to be added.
In generic assembly language: Branch_greater_than R2, #0, LOOP
Actual mnemonic : BGT R4, #0, LOOP
Addressing Modes
The different ways for specifying the locations of instruction operands are known
as addressing mode
1. Immediate Mode: The operand is given explicitly in the instruction.
Example : Add R4, R6, #200
adds the value 200 to the contents of register R6, and places the result into
register R4.
2. Register Mode : The operand is the contents of a processor register; the name
of the register is given in the instruction.
Example: Add R4, R2, R3
uses the Register mode for all three operands. Registers R2 and R3 hold the
two source operands, while R4 is the destination.
Addressing Modes
3. Absolute( Direct) Mode : The operand is in a memory location; the address of
this location is given explicitly in the instruction.
Example: Integer NUM1, NUM2, SUM
represent declaration of global variables in program
or Load R2, NUM1
which loads the value in the memory location NUM1 into register R2.
4. Indirect Addressing Mode : The effective address of the operand is the
contents of a register that is specified in the instruction. The register acts as a
pointer to the operand and we say the operand is accessed indirectly by using
the address in the register.
To execute the Load instruction in Figure 2.7, the processor uses the value B, which is in
register R5, as the effective address of the operand.
In Figure 2.8, we use register indirect mode to implement program for adding n numbers.
Here Register R4 is used as a pointer to the numbers in the list, and the operands are
accessed indirectly through R4. The initialization section of the program loads the counter
value n from memory location N into R2. Then, it uses the Clear instruction to clear R3 to
0. The next instruction uses the Immediate addressing mode to place the address value
NUM1, which is the address of the first number in the list, into R4.
Addressing Modes
5. Index Addressing Mode: The effective address of the operand is generated by adding a
constant value to the contents of a register. Weindicate the Index mode symbolically as :
X(Ri) EA = X+Ri The register used in this mode is
called the index register.
In Figure 2.9a, the index register, R5, contains the address of a memory location, and the
value X defines an offset. In Figure 2.9b X corresponds to a memory address, and the
contents of the index register R5 define the offset to the operand.
Consider a simple example involving a list of test scores for students taking a given
course.Assume that the list of scores, begin at location LIST. Each record consists of the
student’s identification number (ID), followed by the scores the student earned on three tests.
There are n students in the class, and the value n is stored in location N immediately in front
of the list. The list represents a two-dimensional array having n rows and four columns. Each
row contains the entries for one student, and the columns give the IDs and test scores.
Addressing Modes
Our aim is to compute the sum of all scores obtained on each of the tests and store
these three sums in memory locations SUM1, SUM2, and SUM3. In the program
Register R2 is used as the index register. Before the loop is entered, R2 is set to
point to the ID location of the first student record which is the address LIST.
On the first pass through the loop, test scores of the first student are added to the
sums held in registers R3, R4, and R5, which are initially cleared to 0. These scores
are accessed using the Index addressing modes 4(R2), 8(R2), and 12(R2). The index
register R2 is then incremented by 16 to point to the ID location of the second
student. Register R6, initialized to contain the value n, is decremented by 1 at the
end of each pass through the loop. When the contents of R6 reach 0, all student
records have been accessed, the loop terminates. The last three instructions
transfer the accumulated sums from registers R3, R4, and R5, into memory
locations SUM1, SUM2, and SUM3, respectively.
Addressing Modes
6. Base with index : The effective address is the sum of the contents of registers Ri and
Rj. The second register is usually called the base register. This form of indexed
addressing provides more flexibility in accessing operands, because both
components of the effective address can be changed.
Additional Addressing Modes ( CISC Arch modes)
7. Relative Addressing Mode: The effective address is determined by the Index
mode using the program counter in place of the general-purpose register Ri.
X(PC) EA = X+ PC
8. Auto increment Mode : The effective address of the operand is the contents of
a register specified in the instruction. After accessing the operand, the
contents of this register are automatically incremented to point to the next
operand in memory. ( Similar to R++) . Denoted by (Ri)+
9. 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. ( Similar to - -R ). Denoted by −(Ri)
Additional Addressing Modes ( CISC Arch modes)