COA Unit2 - G Maity
COA Unit2 - G Maity
COA Unit2 - G Maity
DEVELOPED BY
GITIKA MAITY, LECTURER IN CST
DEPARTMENT OF COMPUTER SCIENCE & TECHNOLOGY
DR. MEGHNAD SAHA INSTITUTE OF TECHNOLOGY, HALDIA
DEBHOG, HALDIA, PURBA MEDINIPORE, PIN-721657
Unit: 2 2.1 Instruction Format. 0,1,2,3 address
Name of the Topics: instruction.
Instruction structure and Execution steps of a typical instruction
addressing modes, Number through different parts of CPU and
Representation memory.
2.2 Different addressing modes with
example.
2.3 Representation of Integers in
Computer system.
2.4 Representation of Floating point
numbers in computer system.
2.5 Biased exponent, IEEE format for
single and double precision numbers.
2.1 Instruction Format. 0,1,2,3 address instruction.
Execution steps of a typical instruction through different parts of
CPU and memory.
THREE-ADDRESS INSTRUCTIONS
Computers with three-address instruction formats can use each address field to
specify either a processor register or a memory operand. The program in
assembly language that evaluates X = (A + B) * (C + D) is shown below, together
with comments that explain the register transfer operation of each instruction.
ADD R1, A, B R1 ← M [A] + M [B]
ADD R2, C, D R2 ← M [C] + M [D]
MUL X, R1, R2 M [X] ← R1 * R2
It is assumed that the computer has two processor registers, R1 and R2. The
symbol M [A] denotes the operand at memory address symbolized by A.
The advantage of the three-address format is that it results in short programs
when evaluating arithmetic expressions.
The disadvantage is that the binary-coded instructions require too many bits to
specify three addresses.
An example of a commercial computer that uses three-address instructions is the
Cyber 170. The instruction formats in the Cyber computer are restricted to either
three register address fields or two register address fields and one memory
address field.
TWO-ADDRESS INSTRUCTIONS
Two address instructions are the most common in commercial computers. Here
again each address field can specify either a processor register or a memory word.
The program to evaluate X = (A + B) * (C + D) is as follows:
MOV R1, A R1 ← M [A]
ADD R1, B R1 ← R1 + M [B]
MOV R2, C R2 ← M [C]
ADD R2, D R2 ← R2 + M [D]
MUL R1, R2 R1 ← R1* R2
MOV X, R1 M [X] ← R1
The MOV instruction moves or transfers the operands to and from memory and
processor registers. The first symbol listed in an instruction is assumed to be
both a source and the destination where the result of the operation is transferred.
ONE-ADDRESS INSTRUCTIONS
One-address instructions use an implied accumulator (AC) register for all data
manipulation. For multiplication and division there is a need for a second
register. However, here we will neglect the second and assume that the AC
contains the result of tall operations. The program to evaluate X = (A + B) * (C +
D) is
LOAD A AC ← M [A]
ADD B AC ← A [C] + M [B]
STORE T M [T] ← AC
LOAD C AC ← M [C]
ADD D AC ← AC + M [D]
MUL T AC ← AC * M [T]
STORE X M [X] ← AC
All operations are done between the AC register and a memory operand. T is the
address of a temporary memory location required for storing the intermediate
result.
ZERO-ADDRESS INSTRUCTIONS
A stack-organized computer does not use an address field for the instructions
ADD and MUL. The PUSH and POP instructions, however, need an address field
to specify the operand that communicates with the stack. The following program
shows how X = (A + B) * (C + D) will be written for a stack organized computer.
(TOS stands for top of stack)
PUSH A TOS ← A
PUSH B TOS ← B
ADD TOS ← (A + B)
PUSH C TOS ← C
PUSH D TOS ← D
ADD TOS ← (C + D)
MUL TOS ← (C + D) * (A + B)
POP X M [X] ← TOS
To evaluate arithmetic expressions in a stack computer, it is necessary to convert
the expression into reverse Polish notation. The name “zero-address” is given to
this type of computer because of the absence of an address field in the
computational instructions.
Instruction Cycle
An instruction cycle, also known as fetch-decode-execute cycle is the
basic operational process of a computer. This process is repeated
continuously by CPU from boot up to shut down of computer.
Following are the steps that occur during an instruction cycle:
Register Mode
In this mode the operand is stored in the register and this register is
present in CPU. The instruction has the address of the Register where the
operand is stored.
Advantages
Disadvantages
Integer Representation
Integers are whole numbers or fixed-point numbers with the radix
point fixed after the least-significant bit. They are contrast to real
numbers or floating-point numbers, where the position of the radix point
varies. It is important to take note that integers and floating-point numbers
are treated differently in computers. They have different representation and
are processed differently (e.g., floating-point numbers are processed in a so-
called floating-point processor). Floating-point numbers will be discussed
later.
Computers use a fixed number of bits to represent an integer. The
commonly-used bit-lengths for integers are 8-bit, 16-bit, 32-bit or 64-bit.
Besides bit-lengths, there are two representation schemes for integers:
1. Unsigned Integers: can represent zero and positive integers.
2. Signed Integers: can represent zero, positive and negative integers.
Three representation schemes had been proposed for signed integers:
a. Sign-Magnitude representation
b. 1's Complement representation
c. 2's Complement representation
You, as the programmer, need to decide on the bit-length and representation
scheme for your integers, depending on your application's requirements.
Suppose that you need a counter for counting a small quantity from 0 up to
200, you might choose the 8-bit unsigned integer scheme as there is no
negative numbers involved.
Signed Integers
Signed integers can represent zero, positive integers, as well as negative
integers. Three representation schemes are available for signed integers:
1. Sign-Magnitude representation
2. 1's Complement representation
3. 2's Complement representation
In all the above three schemes, the most-significant bit (msb) is called
the sign bit. The sign bit is used to represent the sign of the integer - with 0
for positive integers and 1 for negative integers. The magnitude of the
integer, however, is interpreted differently in different schemes.
Because of the fixed precision (i.e., fixed number of bits), an n-bit 2's
complement signed integer has a certain range. For example, for n=8, the
range of 2's complement signed integers is -128 to +127. During addition
(and subtraction), it is important to check whether the result exceeds this
range, in other words, whether overflow or underflow has occurred.
Example 4: Overflow: Suppose that n=8, 127D + 2D = 129D (overflow -
beyond the range)
127D → 0111 1111B
2D → 0000 0010B(+
1000 0001B → -127D (wrong)
The following diagram explains how the 2's complement works. By re-
arranging the number line, values from -128 to +127 are represented
contiguously by ignoring the carry bit.
Normalized Form
Let's illustrate with an example, suppose that the 32-bit pattern is 1 1000
0001 011 0000 0000 0000 0000 0000, with:
S=1
E = 1000 0001
F = 011 0000 0000 0000 0000 0000
In the normalized form, the actual fraction is normalized with an implicit
leading 1 in the form of 1.F. In this example, the actual fraction is 1.011
0000 0000 0000 0000 0000 = 1 + 1×2^-2 + 1×2^-3 = 1.375D.
The sign bit represents the sign of the number, with S=0 for positive
and S=1 for negative number. In this example with S=1, this is a negative
number, i.e., -1.375D.
In normalized form, the actual exponent is E-127 (so-called excess-127 or
bias-127). This is because we need to represent both positive and negative
exponent. With an 8-bit E, ranging from 0 to 255, the excess-127 scheme
could provide actual exponent of -127 to 128. In this example, E-127=129-
127=2D.
Hence, the number represented is -1.375×2^2=-5.5D.
De-Normalized Form
Normalized form has a serious problem, with an implicit leading 1 for the
fraction, it cannot represent the number zero! Convince yourself on this!
De-normalized form was devised to represent zero and other numbers.
For E=0, the numbers are in the de-normalized form. An implicit leading 0
(instead of 1) is used for the fraction; and the actual exponent is always -
126. Hence, the number zero can be represented
with E=0 and F=0 (because 0.0×2^-126=0).
We can also represent very small positive and negative numbers in de-
normalized form with E=0. For example, if S=1, E=0, and F=011 0000 0000
0000 0000 0000. The actual fraction is 0.011=1×2^-2+1×2^-3=0.375D.
Since S=1, it is a negative number. With E=0, the actual exponent is -126.
Hence the number is -0.375×2^-126 = -4.4×10^-39, which is an extremely
small negative number (close to zero).
Summary
In summary, the value (N) is calculated as follows:
For 1 ≤ E ≤ 254, N = (-1)^S × 1.F × 2^(E-127). These numbers are in the
so-called normalized form. The sign-bit represents the sign of the
number. Fractional part (1.F) are normalized with an implicit leading 1.
The exponent is bias (or in excess) of 127, so as to represent both
positive and negative exponent. The range of exponent is -126 to +127.
For E = 0, N = (-1)^S × 0.F × 2^(-126). These numbers are in the so-
called denormalized form. The exponent of 2^-126 evaluates to a very
small number. Denormalized form is needed to represent zero
(with F=0 and E=0). It can also represent very small positive and negative
number close to zero.
For E = 255, it represents special values, such as ±INF (positive and
negative infinity) and NaN (not a number). This is beyond the scope of
this article.
Example 1: Suppose that IEEE-754 32-bit floating-point representation
pattern is 0 10000000 110 0000 0000 0000 0000 0000.
Sign bit S = 0 ⇒ positive number
E = 1000 0000B = 128D (in normalized form)
Fraction is 1.11B (with an implicit leading 1) = 1 + 1×2^-1 + 1×2^-2 = 1.75D
The number is +1.75 × 2^(128-127) = +3.5D
References:
Books:
Online materials :
1. https://www.iare.ac.in/sites/default/files/PPT/CO%20Lecture%20Notes.pdf
2. http://www.c-jump.com/CIS77/CPU/InstrCycle/lecture.html
3. https://www.geeksforgeeks.org/different-instruction-cycles/
4. https://www3.ntu.edu.sg/home/ehchua/programming/java/datarepresentation.
html#:~:text=Computers%20use%20a%20fixed%20number,%2Dbit%20or%2064%
2Dbit.&text=Unsigned%20Integers%3A%20can%20represent%20zero,zero%2C%2
0positive%20and%20negative%20integers.