Module 1 CO & CA
Module 1 CO & CA
• Types of computer
• Personal/ Desktop Computer
• Portable Notebook computer
• Workstations
• Enterprise Systems, Servers
• Supercomputers
Functional Units
Arithmetic
Input and
logic
Memory
Output Control
I/O Processor
• Individual instructions are brought from the memory into the processor, which
executes the specified operations.
• Add LOCA, R0
• Add the operand at memory location LOCA to the operand in a register R0
in the processor.
• Place the sum into register R0.
• The original contents of LOCA are preserved.
• The original contents of R0 is overwritten.
• Instruction is fetched from the memory into the processor – the operand at
LOCA is fetched and added to the contents of R0 – the resulting sum is
stored in register R0.
• It combines Memory Access and ALU operation
Separate Memory Access and ALU
Operation
• Load LOCA, R1
• Add R1, R0
• Whose contents will be overwritten?
Connection Between the Processor
and the Memory
Memo ry
MAR MDR
Co n t ro l
PC R0
R1
Pro ces s o r
IR
ALU
Rn - 1
n g en eral p u rp o s e
reg i s t ers
Single-bus
Main Cache
memory memory Processor
Bus
N S
T How to improve T?
R
Pipeline and Superscalar Operation
i 1
Chapter 2. Machine Instructions
and Programs
Objectives
We need to represent both positive and negative numbers. Three systems used for representing
such numbers are
Signed Integer
• 3 major representations:
Sign and magnitude
One’s complement
Two’s complement
• Assumptions:
4-bit machine word
16 different values can be represented
Roughly half are positive, half are negative
Binary, Signed-Integer
Representations
B alues
V represented
Sign and
b 3 b 2b 1b 0 magnitude 1's complement 2's complement
0 1 1 1 + 7 + 7 + 7
0 1 1 0 + 6 + 6 + 6
0 1 0 1 + 5 + 5 + 5
0 1 0 0 + 4 + 4 + 4
0 0 1 1 + 3 + 3 + 3
0 0 1 0 + 2 + 2 + 2
0 0 0 1 + 1 + 1 + 1
0 0 0 0 + 0 + 0 + 0
1 0 0 0 - 0 - 7 - 8
1 0 0 1 - 1 - 6 - 7
1 0 1 0 - 2 - 5 - 6
1 0 1 1 - 3 - 4 - 5
1 1 0 0 - 4 - 3 - 4
1 1 0 1 - 5 - 2 - 3
1 1 1 0 - 6 - 1 - 2
1 1 1 1 - 7 - 0 - 1
2n-1= 15= 1 1 1 1
10000 (16)
0111 (7
010 0 1 (-7)
Addition of Positive Numbers
Sign and Magnitude Representation
-7 +0
-6 1111 0000 +1
1110 0001
-5 +2 +
1101 0010
-4 1100 0011 +3 0 100 = + 4
-0 +0
-1 1111 0000 +1
1110 0001
-2 +2 +
1101 0010
-3 1100 0011 +3 0 100 = + 4
• Rule 1:
To add two numbers, add their n-bit representation, ignoring their carry-out signal from MSB
position. Sum will be algebraically correct value in 2’s compliment representation if
answer is in the range - 2n-1 to +2n-1-1.
• Rule 2:
• To subtract two numbers X and Y, ie to perform X-Y, form the 2’s compliment of Y and
then add it to X as in rule 1. Again result will be algebraically correct value in 2’s
compliment representation if answer is in the range - 2 n-1 to +2n-1-1.
Addition and Subtraction – 2’s Complement
4 0100 -4 1100
If carry-in to the
high +3 0011 + (-3) 1101
order bit =
carry-out then 7 0111 -7 11001
ignore
carry
+3 0011
-
-7 1001===
0011
0111
1 0 1 0----6 arithmetic overflow
+6
-2===1000 (-8)
Overflow - Add two positive numbers to get a negative
number or two negative numbers to get a positive number
-1 +0 -1 +0
-2 1111 0000 +1 -2 1111 0000 +1
1110 0001 1110 0001
-3 +2 -3
1101 1101 +2
0010 0010
-4 -4
1100 0011 +3 1100 0011 +3
-5 1011 -5 1011
0100 +4 0100 +4
1010 1010
-6 0101 -6 0101
1001
+5 +5
0110 1001
0110
-7 1000 0111 +6 -7 1000 +6
0111
-8 +7 -8 +7
5 + 3 = -8 -7 - 2 = +7
Overflow Conditions
0111 1000
5 0101 -7 1001
3 0011 -2 1100
-8 1000 7 10111
Overflow Overflow
0000 1111
5 0101 -3 1101
2 0010 -5 1011
7 0111 -8 11000
No overflow No overflow
Overflow when carry-in to the high-order bit does not equal carry out
Arithmetic overflow
•Overflow cannot occur when 2 no’s having opposite sign are added.
•Overflow can occur only when 2 No’s having the same sign are added
•Overflow can be detected by considering carry into MSB position(Cn-1) and carry out of
MSB position(Cn ). These two are mutually exclusive.
w
X • • •
k copies of MSB
• +4= 0100
• 0000 0100 • • •
• -4=1100 X • • • • • •
• 1111 1100
k w
Memory Locations, Addresses, and Operations
• Number and character operands as well as instructions are stored in the memory of a
computer.
• Memory is organized so that group of n bits can be stored or retrieved in a single basic
operation.
• Each group of n bits is referred as word of information and n is called as world length.
• Modern Computers have word length ranges from 16-64 bits.
• A unit of 8 bits is called as byte.
• Accessing the memory to store or retrieve single item of information requires distinct
names/addresses for each item location.
• A number from 0 to 2k -1 indicates addressable location.
• 24 bit address generates address space of 224 (16 M)
• 32-bit address generates address space of 232 (4 G)
Memory Location, Addresses, and
Operation
32-bit word length example
32 bits
b 31 b 30 b1 b0
•
•
•
Sign bit: b 31 = for
0 positive numbers
b 31 = for
1 negative numbers
W ord
address Byte address Byte address
0 0 1 2 3 0 3 2 1 0
4 4 5 6 7 4 7 6 5 4
• •
• •
• •
k k k k k k k k k k
2 - 4 2 - 4 2 - 3 2 - 2 2 - 1 2 - 4 2 - 1 2 - 2 2 - 3 2 - 4
Big-endian
As we know that in big-endian MSB Byte will store first. It means the MSB Byte will store at the
lowest memory address.
Little-endian
In the little endian machine, LSB byte will store first. So the LSB Byte will store at the lowest memory
address. See the table,
Memory Location, Addresses, and
Operation
Address ordering of bytes
Word alignment
◦ Words are said to be aligned in memory if they begin at a byte addr. that is
a multiple of the num of bytes in a word.
16-bit word: word addresses: 0, 2, 4,….
32-bit word: word addresses: 0, 4, 8,….
64-bit word: word addresses: 0, 8,16,….
Access numbers, characters, and character strings
Memory Operation
[1] Carl Hamacher, Zvonko Vranesic, SafwatZaky: Computer Organization, 5th Edition,
Tata McGraw Hill, 2017