Module 2
Module 2
Arithmetic logic unit, Integer multiplication- Booth’s algorithm; Floating point representation
principles, Machine instruction characteristics, Addressing modes, Instruction formats –
Instruction length, Allocation of bits; Processor organization, Register organization – User
visible registers, Control and status registers; Instruction cycle.
The ALU is the part of the computer that actually performs arithmetic
and logical operations on data.
All of the other elements of the computer system— control unit, registers, memory, I/O—
are there mainly to bring data into the ALU for it to process and then to take the results back
out.
In the above figure, operands for arithmetic and logic operations are presented to the
ALU in registers, and the results of an operation are stored in registers.
• In the binary number system, arbitrary numbers can be represented with just the digits
zero and one, the minus sign (for negative numbers), and the period, or radix point (for
numbers with a fractional component).
-1101.01012 = -13.312510
255, such as
00000000 = 0
00101001 = 41
10000000 = 128
11111111 = 255
+18 = 00010010
+ 010 = 00000000
Steps:
1. Take the Boolean complement of each bit of the integer (including the sign bit). That
is, set each 1 to 0 and each 0 to 1.
2. Treating the result as an unsigned binary integer, add 1.
INTEGER ARITHMETIC:
• If the result of the operation is positive, we get a positive number in twos complement
form, which is the same as in unsigned-integer form. If the result of the operation is
negative, we get a negative number in twos complement form
• On any addition, the result may be larger than can be held in the word size being used.
This condition is called overflow. When overflow occurs, the ALU must signal this fact so that
no attempt is made to use the result.
SUBTRACTION RULE: To subtract one number (subtrahend) from another (minuend), take
the twos complement (negation) of the subtrahend and add it to the minuend
Unsigned integer
1. Multiplication involves the generation of partial products, one for each digit in the
multiplier. These partial products are then summed to produce the final product.
2. The partial products are easily defined. When the multiplier bit is 0, the partial product is
0. When the multiplier is 1, the partial product is the multiplicand.
3. The total product is produced by summing the partial products. For this operation, each
successive partial product is shifted one position to the left relative to the preceding partial
product.
4. The multiplication of two n-bit binary integers results in a product of up to 2n bits in
length
Principles:
• The floating-point representation can implement operations for high range values. The
numerical evaluations are carried out using floating-point values.
• The floating-point representation breaks the number into two parts, the left-hand side is
a signed, fixed-point number known as a mantissa and the right-hand side of the number is
known as the exponent.
• For decimal numbers, we get around this limitation by using scientific notation. Thus,
976,000,000,000,000 can be represented as 9.76 * 1014 , and 0.0000000000000976 can be
represented as 9.76 * 10-14
• This same approach can be taken with binary numbers. We can represent a number in the
form
±M * B ± E
• Each instruction must contain the information required by the processor for execution.
ADD R, Y
may mean add the value contained in data location Y to the contents of register R. In this
example, Y refers to the address of a location in memory, and R refers to a particular
register.
Instruction Types
For example, X = X + Y
• This statement instructs the computer to add the value stored in Y to the value stored in X
and put the result in X. How might this be accomplished with machine instructions? Let us
assume that the variables X and Y correspond to locations 513 and 514. If we assume a
simple set of machine instructions, this operation could be accomplished with three
instructions:
• Data storage: Movement of data into or out of register and or memory locations.
• Logic (Boolean) instructions operate on the bits of a word as bits rather than as numbers;
thus, they provide capabilities for processing any other type of data the user may wish to
employ. These operations are performed primarily on data in processor registers.
• Memory instructions for moving data between memory and the registers.
• I/O instructions are needed to transfer programs and data into memory and the results
of computations back out to the user.
• Test instructions are used to test the value of a data word or the status of a computation.
• Branch instructions are then used to branch to a different set of instructions depending
on the decision made.
Number of Addresses
• Virtually all arithmetic and logic operations are either unary (one source operand) or
binary (two source operands).
• The result of an operation must be stored, suggesting a third address, which defines a
destination operand.
• Finally, after completion of an instruction, the next instruction must be fetched, and its
address is needed.
• In most architectures, many instructions have one, two, or three operand addresses,
with the address of the next instruction being implicit (obtained from the program counter).
• The address field or fields in a typical instruction format are relatively small.
• We would like to be able to reference a large range of locations in main
memory or, for some systems, virtual memory.
• To achieve this objective, a variety of addressing techniques has been employed.
• They all involve some trade-off between address range and/or addressing flexibility, on
the one hand, and the number of memory references in the instruction and/or the
complexity of address calculation, on the other.
Addressing techniques:
• Immediate
• Direct
• Indirect
• Register
• Register indirect
• Displacement
• Stack
Immediate Addressing:
• The simplest form of addressing is immediate addressing, in which the operand value is
present in the instruction:
Operand = A
• This mode can be used to define and use constants or set initial values of variables.
Examples-
• The advantage of immediate addressing is that no memory reference other than the
instruction fetch is required to obtain the operand, thus saving one memory or cache cycle
in the instruction cycle.
• The disadvantage is that the size of the number is restricted to the size of the address
field, which, in most instruction sets, is small compared with the word length.
Direct Addressing:
• A very simple form of addressing is direct addressing, in which the address field
contains the effective address of the operand:
• The technique was common in earlier generations of computers, but is not common on
contemporary architectures. It requires only one memory reference and no special
calculation. The obvious limitation is that it provides only a limited address space.
Example-
• ADD X will increment the value stored in the accumulator by the value stored at
memory location X.
• AC ← AC + [X]
Indirect Addressing:
With direct addressing, the length of the address field is usually less than the word
length, thus limiting the address range. One solution is to have the address field
refer to the address of a word in memory, which in turn contains a full- length address
of the operand. This is known as indirect addressing:
EA = (A)
Example-
ADD X will increment the value stored in the accumulator by the value stored at memory
location specified by X.
Advantage of this approach is that for a word length of N, an address space of 2N is now
available. The disadvantage is that instruction execution requires two memory
references to fetch the operand: one to get its address and a second to get its value.
Register Addressing:
Register addressing is similar to direct addressing. The only difference is that the
address field refers to a register rather than a main memory address:
EA = R
Example-
ADD R will increment the value stored in the accumulator by the content of register R.
AC ← AC + [R]
EA = (R)
The advantages and limitations of register indirect addressing are basically the same as
for indirect addressing. In both cases, the address space limitation (limited range of
addresses) of the address field is overcome by having that field refer to a word-length
location containing an address. In addition, register indirect addressing uses one less
memory reference than indirect addressing.
Example-
• ADD R will increment the value stored in the accumulator by the content of memory
AC ← AC + [[R]]
Displacement Addressing:
EA = A + (R)
Stack Addressing:
• Associated with the stack is a pointer whose value is the address of the top of the stack.
• To understand the organization of the processor, let us consider the requirements placed
on the processor, the things that it must do:
• Fetch instruction: The processor reads an instruction from memory (register, cache,
main memory).
• The major components of the processor are an arithmetic and logic unit (ALU) and a
control unit (CU).
• The ALU does the actual computation or processing of data.
• The control unit controls the movement of data and instructions into and out of the
• An instruction format defines the layout of the bits of an instruction, in terms of its
constituent fields.
• An instruction format must include an opcode and, implicitly or explicitly, zero or more
operands.
• Each explicit operand is referenced using one of the addressing modes.
• The format must, implicitly or explicitly, indicate the addressing mode for each operand.
• The most basic design issue to be faced is the Instruction format length.
• This decision is affected by memory size, memory organization, bus structure,
processor complexity, and processor speed.
• This decision determines the richness and flexibility of the machine as seen by the
assembly-language programmer.
• The most obvious trade-off here is between the desire for a powerful instruction set
and a need to save space.
• Programmers want more opcodes, more operands, more addressing modes, and greater
address range.
• More opcodes and more operands make life easier for the programmer, because shorter
programs can be written to accomplish given tasks.
• Similarly, more addressing modes give the programmer greater flexibility in
implementing certain functions, such as table manipulations and multiple- way branching.
• With the increase in main memory size and the increasing use of virtual memory,
programmers want to be able to address larger memory ranges.
• All of these things (opcodes, operands, addressing modes, address range) require bits
and push in the direction of longer instruction lengths.
• But longer instruction length may be wasteful.
• For a given instruction length, there is clearly a trade- off between the number of opcodes
and the power of the addressing capability. For an instruction format of a given length, this
reduces the number of bits available for addressing.
• Use variable-length opcodes to solve this issue.
• In this approach, there is a minimum opcode length but, for some opcodes, additional
operations may be specified by using additional bits in the instruction. For a fixed-length
instruction, this leaves fewer bits for addressing. Thus, this feature is used for those
instructions that require fewer operands and/or less powerful addressing.
Interrelated factors:
• A user-visible register is one that may be referenced by means of the machine language
that the processor executes.
• These registers are visible to the assembly or machine language programmers and they
use them effectively to minimize the memory references in the instructions.
• These registers can only be referenced using the machine or assembly language.
Data Register:
• The term itself describes that these registers are employed to hold the data. But the
programmers can’t use these registers for calculating operand address.
Address Register:
• Now, the address registers contain the address of an operand or it can also act as a
general- purpose register.
• An address register may be dedicated to a certain addressing mode.
(c) Stack Pointer Register: The stack register has the address that points the stack top.
This allows implicit addressing; that is, push, pop, and other stack instructions need not
contain an explicit stack operand.
• Condition codes are the flag bits which are the part of the control register. The
condition codes are set by the processor as a result of an operation and they are implicitly
read through the machine instruction.
• The programmers are not allowed to alter the conditional codes. Generally, the condition
codes are tested during conditional branch operation.
Design issues:
• The control and status register holds the address or data that is
important to control the processor’s operation.
• The most important thing is that these registers are not visible to the users.
• All the control and status registers are essential for the execution of
an instruction.
Types
1. Program Counter
2. Instruction Register
• Instruction register has the instruction that is currently fetched. It helps in analysing
the opcode and operand present in the instruction.
• The memory buffer register holds the data that has to be written to a memory location
or it holds the data that is recently been read.
• The memory address registers (MAR) and memory buffer registers (MBR) are used to
move the data between processor and memory.
• Apart from the above registers, several processors have a register termed as Program
Status Word (PSW). As the word suggests it contains the status information.
• The fields included in Program Status Word (PSW):
– Sign: This field has the resultant sign bit of the last arithmetic operation performed.
– Zero: This field is set when the result of the operation is zero.
– Carry: This field is set when an arithmetic operation results in a carry into or borrow out.
– Equal: If a logical operation results in, equality the Equal bit is set.
– Overflow: This bit indicates the arithmetic overflow.
– Interrupt: This bit is set to enable or disable the interrupts.
– Supervisor: This bit indicates whether the processor is executing in the supervisor mode
or the user mode.