Complet Csa Notes
Complet Csa Notes
Complet Csa Notes
and Memory
Addition and Subtraction with signed magnitude data, Hardware
implementation, Hardware Algorithm, Addition and Subtraction with
signed 2’ s Complement Data, Multiplication Algorithms: Hardware
implementation for signed Magnitude Data, Hardware Algorithm,
Booth Multiplication Algorithm, Array Multiplier, Division
Algorithms: Hardware implementation for signed Magnitude Data,
Divide Overflow, Floating Point Arithmetic: Basic Considerations,
Register Configuration, Addition, Subtraction, multiplication and
Division. The Memory System: Basic Concepts, Semiconductor RAM
Memories, ROM, Cache Memories, Virtual Memories.
Introduction
• Arithmetic instructions in digital computers manipulate data to produce results
necessary for the solutions of computational problems. These instructions
perform arithmetic calculations and are responsible for the bulk of activity
involved in processing data in a computer.
• The four basic arithmetic operations are addition,subtraction,multiplication and
division.
• From these four basic operations , it is possible to formulate other arithmetic
functions and solve problems by means of numerical analysis methods.
• An arithmetic processor is the pat of a processor unit that executes arithmetic
operations.
• An arithmetic instruction may specify binary or decimal data, and in each case
the data may be in fixed-point or floating point form.
• Negative numbers may be in signed magnitude or signed compliment
representation.
• Fixed point numbers may represents integers or fractions.
What is algorithm?
The solution to any problem that is stated by a finite number of well-
defined procedural steps is called an Algorithm.
In this class we develop the various arithmetic algorithms and show the
procedure for implementing them with digital hardware
we consider addition,subtraction,multiplication,and division for the
following types of data:
Fixed point binary data in signed-magnitude representation
Fixed point binary data in signed-2’s compliment representation
Floating point binary data
Binary-coded decimal(BCD) data
Addition and Subtraction
The addition and subtraction algorithm for data represented in signed
magnitude and again data represented in signed-2’s complement.
It is important to realize that the adopted representation for negative
numbers refers to the representation of numbers in the register before
and after the execution of the arithmetic operations.
For A 0 indicates that A<B, for this case it is necessary to take the 2’s
compliment of the value in A .this operation can be done with one micro
operation AĀ+1.
1
Unit 7 – Computer Arithmetic
Minuend in A Augend in A
=0 =1 =1 =0
A s ⊕ Bs A s ⊕ Bs
EA ← A+ B’ + 1
EA ← A+ B
As ≠ Bs
As ≠ Bs As = Bs
=0 =1
AVF ← E
E A≥B
A<B
≠0 =0
A ← A’ A
A←A+1 AS ← 0
As ← As ’
END
2
Multiplication algorithms:-
multiplication of two fixed point binary numbers in signed
magnitude representation is done with paper and pencil of
successive shift and add operation
Multiply
Multiplicand in BR
Multiplier in QR
AC ← 0
Qn + 1 ← 0
= 10 = 01
QnQn+1
AC ← AC + BR’ + 1 = 00 AC ← AC + BR
≠0 =0
SC
END
Figure 7.3: Booth algorithm for multiplication of signed-2's complement numbers
3
Unit 7 – Computer Arithmetic
Prior to the shifting, the multiplicand may be added to the partial product, subtracted
from the partial, or left unchanged according to the following rules:
1. The multiplicand is subtracted from the partial product upon encountering the
first least significant 1 in a string of 1’s in the multiplier.
2. The multiplicand is added to the partial product upon encountering the first 0 in a
string of 0’s in the multiplier.
3. The partial product does not change when multiplier bit is identical to the
previous multiplier bit.
The algorithm works for positive or negative multipliers in 2’s complement
representation.
This is because a negative multiplier ends with a string of 1’s and the last operation will
be a subtraction of the appropriate weight.
The two bits of the multiplier in Qn and Qn+1 are inspected.
If the two bits are equal to 10, it means that the first 1 in a string of 1 's has been
encountered. This requires a subtraction of the multiplicand from the partial product in
AC.
If the two bits are equal to 01, it means that the first 0 in a string of 0's has been
encountered. This requires the addition of the multiplicand to the partial product in AC.
When the two bits are equal, the partial product does not change.
If neither of the operands is equal to zero, the process continues with the exponent
addition.
The exponent of the multiplier is in q and the adder is between exponents a and b.
It is necessary to transfer the exponents from q to a, add the two exponents, and
transfer the sum into a.
Multiplicand in BR
Multiplier in QR
=0
BR
≠0
=0
QR
AC ← 0 ≠0
a←q
a←a+b
a ← a - bias
Multiply mantissa
=0
shl AQ
A1
a←a-1
=1
END
(product is in AC)
Since both exponents are biased by the addition of a constant, the exponent sum will
have double this bias.
The correct biased exponent for the product is obtained by subtracting the bias number
from the sum.
The multiplication of the mantissas is done as in the fixed-point case with the product
residing in A and Q.
Overflow cannot occur during multiplication, so there is no need to check for it.
The product may have an underflow, so the most significant bit in A is checked. If it is a
1, the product is already normalized.
5
Unit 7 – Computer Arithmetic
4. Multiply the (-9) with (-13) using Booth’s algorithm. Give each
step. (Sum’14)
A numerical example of booth algorithm is shown for n=5. It shows the step-by-step
multiplication of (-9) X (-13) = +117.
9: 01001 13: 01101
1’s complement of 9: 10110 1’s complement of 13: 10010
+ 1 + 1
2’s complement of 9: 10111 (-9) 2’s complement of 13: 10011 (-13)
AC QR(-13) Qn+1 M(BR)(-9) SC Comments
00000 10011 0 10111 5 Initial value
01001 10011 0 10111 Subtraction: AC=AC+BR’+1
4
00100 11001 1 10111 Arithmetic Shift Right
00010 01100 1 10111 3 Arithmetic Shift Right
11001 01100 1 10111 Subtraction: AC=AC+BR’+1
2
11100 10110 0 10111 Arithmetic Shift Right
11110 01011 0 10111 1 Arithmetic Shift Right
00111 01011 0 10111 Subtraction: AC=AC+BR’+1
0
00011 10101 1 10111 Arithmetic Shift Right
Answer: -9 X -13 =117 => 001110101
5. Multiply the (7) with (3) using Booth’s algorithm. Give each
step.
7: 0111 3: 0011
6
Unit 7 – Computer Arithmetic
6. Multiply the (15) with (13) using Booth’s algorithm. Give each
step.
15: 01111 13: 01101
15X13=195
AC QR(15) Qn+1 M(BR)(13) SC Comments
00000 01111 0 01101 5 Initial value
10011 01111 0 01101 Subtraction: AC=AC+BR’+1
4
11001 10111 1 01101 Arithmetic Shift Right
11100 11011 1 01101 3 Arithmetic Shift Right
11110 01101 1 01101 2 Arithmetic Shift Right
11111 00110 1 01101 1 Arithmetic Shift Right
01100 00110 1 01101 Addition: AC=AC+BR
0
00110 00011 1 01101 Arithmetic Shift Right
Answer: 15X13=195 => 0011000011
7. Multiply the (+15) with (-13) using Booth’s algorithm. Give each
step.
15: 01111 13: 01101
1’s complement of 13: 10010
+ 1
2’s complement of 13: 10011 (-13)
To verify 0011000010
+ 1
+195=> 0011000011
7
Array multiplier
The multiplication of the two binary numbers can be done with one micro-operation by means of a
combinational circuit that forms the product bits all at once. This is a fast way of multiplying two
numbers since all it takes is the time for the signals to propagate through the gate that form the
multiplication array.
4 bit by 3 bit array multiplexer
Division Algorithm
Division of two fixed-point binary numbers in signed magnitude
representation is done with paper and pencil by a process of successive
compare ,shift ,and subtract operations ..
Non-Restoring division, it is less complex than the restoring one because simpler operation are
involved i.e. addition and subtraction, also now restoring step is performed. In the method, rely on
the sign bit of the register which initially contain zero named as A.
MSB of
A=1
MSB of
A=1
•Step-1: First the registers are initialized with
corresponding values (Q = Dividend, M = Divisor, A = 0,
n = number of bits in dividend)
•Step-2: Check the sign bit of register A
•Step-3: If it is 1 shift left content of AQ and perform A
= A+M, otherwise shift left AQ and perform A = A-M
(means add 2’s complement of M to A and store it to A)
•Step-4: Again the sign bit of register A
•Step-5: If sign bit is 1 Q[0] become 0 otherwise Q[0]
become 1 (Q[0] means least significant bit of register
Q)
•Step-6: Decrements value of N by 1
•Step-7: If N is not equal to zero go to Step 2 otherwise
go to next step
•Step-8: If sign bit of A is 1 then perform A = A+M
•Step-9: Register Q contain quotient and A contain
remainder
N M A Q Action
Examples: Perform Non_Restoring
4 00011 00000 1011 Start
Division for Unsigned Integer
Dividend =11 Divisor =3 -M =11101
00001 011_ Left shift AQ
Quotient = 3 (Q)
00101 001_ Left Shift AQ
Remainder = 2 (A)
00010 001_ A=A-M
Register configuration
The register configuration for floating point operation is
quite similar to the layout for fixed point operation. As a general rule, the same
register and adder used for fixed point arithmetic are used for processing the
mantissas. The difference lies in the way the exponents are handled.
Register organization
Main Memory
The main memory is the central storage unit in a computer system.
Primary memory holds only those data and instructions on which computer is currently
working.
It has limited capacity and data is lost when power is switched off.
It is generally made up of semiconductor device.
These memories are not as fast as registers.
The data and instruction required to be processed reside in main memory.
It is divided into two subcategories RAM and ROM.
The designer of a computer system must calculate the amount of memory required for
the particular application and assign it to either RAM or ROM.
The interconnection between memory and processor is then established from
knowledge of the size of memory needed and the type of RAM and ROM chips available.
The addressing of memory can be established by means of a table that specifies the
memory address assigned to each chip.
The table, called a memory address map, is a pictorial representation of assigned
address space for each chip in the system, shown in table 9.1.
To demonstrate with a particular example, assume that a computer system needs 512
bytes of RAM and 512 bytes of ROM.
The RAM and ROM chips to be used are specified in figure 9.1 and figure 9.2.
1
Unit 9 – Memory Organization
2
Unit 9 – Memory Organization
Hardware Organization
The key register provides a mask for choosing a particular field or key in the argument
word.
The entire argument is compared with each memory word if the key register contains all
1's.
Otherwise, only those bits in the argument that have 1st in their corresponding position
of the key register are compared.
Thus the key provides a mask or identifying piece of information which specifies how the
reference to memory is made.
To illustrate with a numerical example, suppose that the argument register A and the key
register K have the bit configuration shown below.
Only the three leftmost bits of A are compared with memory words because K has 1's in
these position.
3
Unit 9 – Memory Organization
A 101 111100
K 111 000000
Word1 100 111100 no match
Word2 101 000001 match
Word 2 matches the unmasked argument field because the three leftmost bits of the
argument and the word are equal.
4
Unit 9 – Memory Organization
The number of bits in the index field is equal to the number of address bits required to
access the cache memory.
The internal organization of the words in the cache memory is as shown in figure 9.7.
6
Unit 9 – Memory Organization
Suppose that the CPU now wants to access the word at address 02000.
The index address is 000, so it is used to access the cache. The two tags are then
compared.
The cache tag is 00 but the address tag is 02, which does not produce a match.
Therefore, the main memory is accessed and the data word 5670 is transferred to the
CPU.
The cache word at index address 000 is then replaced with a tag of 02 and data of 5670.
The disadvantage of direct mapping is that two words with the same index in their
address but with different tag values cannot reside in cache memory at the same time.
7
Unit 9 – Memory Organization
The comparison logic is done by an associative search of the tags in the set similar to an
associative memory search: thus the name "set-associative”.
When a miss occurs in a set-associative cache and the set is full, it is necessary to replace
one of the tag-data items with a new value.
The most common replacement algorithms used are: random replacement, first-in first-
out (FIFO), and least recently used (LRU).
Write-Back (Copy-Back)
The second procedure is called the write-back method.
In this method only the cache location is updated during a write operation.
The location is then marked by a flag so that later when the word is removed from the
cache it is copied into main memory.
The reason for the write-back method is that during the time a word resides in the
cache, it may be updated several times.
However, as long as the word remains in the cache, it does not matter whether the copy
in main memory is out of date, since requests from the word are filled from the cache.
It is only when the word is displaced from the cache that an accurate copy need be
rewritten into main memory.
Virtual Memory
Virtual memory is used to give programmers the illusion that they have a very large
memory at their disposal, even though the computer actually has a relatively small main
memory.
A virtual memory system provides a mechanism for translating program-generated
addresses into correct main memory locations.
8
Unit 9 – Memory Organization
Address space
An address used by a programmer will be called a virtual address, and the set of such addresses
is known as address space.
Memory space
An address in main memory is called a location or physical address. The set of such locations is
called the memory space.
Auxiliary Memory Main Memory 32k=215
Program 1
Data 1,1
Data 1,2 Program 1
Program 2
Data 2,1
Data 1,1
Address space 1024k=210
Figure 9.9: Relation between address and memory space in a virtual memory system
As an illustration, consider a computer with a main-memory capacity of 32K words (K =
1024). Fifteen bits are needed to specify a physical address in memory since 32K = 215.
Suppose that the computer has available auxiliary memory for storing 220 = 1024K
words.
Thus auxiliary memory has a capacity for storing information equivalent to the capacity
of 32 main memories.
Denoting the address space by N and the memory space by M, we then have for this
example N = 1024K and M = 32K.
In a multiprogramming computer system, programs and data are transferred to and
from auxiliary memory and main memory based on demands imposed by the CPU.
Suppose that program 1 is currently being executed in the CPU. Program 1 and a portion
of its associated data are moved from auxiliary memory into main memory as shown in
figure 9.9.
Portions of programs and data need not be in contiguous locations in memory since
information is being moved in and out, and empty spaces may be available in scattered
locations in memory.
In our example, the address field of an instruction code will consist of 20 bits but physical
memory addresses must be specified with only 15 bits.
Thus CPU will reference instructions and data with a 20-bit address, but the information
at this address must be taken from physical memory because access to auxiliary storage
for individual words will be too long.
9
Unit 9 – Memory Organization
Figure 9.10 Address and Memory space split into group of 1K words
10
Unit 9 – Memory Organization
The page field specifies the page within the segment and word field gives specific word
within the page.
A page field of k bits can specify up to 2k pages.
A segment number may be associated with just one page or with as many as 2k pages.
Thus the length of a segment would vary according to the number of pages that are
assigned to it.
The mapping of the logical address into a physical address is done by means of two
tables, as shown in figure 9.12.
The segment number of the logical address specifies the address for the segment table.
The entry in the segment table is a pointer address for a page table base.
The page table base is added to the page number given in the logical address.
The sum produces a pointer address to an entry in the page table.
The concatenation of the block field with the word field produces the final physical
mapped address.
The two mapping tables may be stored in two separate small memories or in main
memory.
In either case, memory reference from the CPU will require three accesses to memory:
one from the segment table, one from the page table and the third from main memory.
This would slow the system significantly when compared to a conventional system that
requires only one reference to memory.
12