Computer Organization and Architecture (18EC35) - Machine Instructions and Programs - Part 1 (Module 1)
Computer Organization and Architecture (18EC35) - Machine Instructions and Programs - Part 1 (Module 1)
and Architecture
Carl Hamacher, Zvonko Vranesic, Safwat Zaky,
Computer Organization, 5th Edition,
Tata McGraw Hill, 2002.
Machine Instructions
and Programs - Part 1
Module 1
Numbers, Arithmetic
Operations, and
Characters
Introduction
⚫ Computers are built using logic circuits that
operate on information represented by two-
valued electrical signals
⚫ Labelled as 0 and 1
⚫ We define the amount of information
represented by such a signal as a bit of
information, where bit stands for binary digit.
⚫ The most natural way to represent a number
in a computer system is by a string of bits,
called a binary number.
Number Representation
⚫ Consider an n-bit vector
𝐵 = 𝑏𝑛−1 … … 𝑏1 𝑏0
Where 𝑏𝑖 = 0 𝑜𝑟 1 for 0 ≤ 𝑖 ≤ 𝑛 − 1
⚫ This vector can represent unsigned integer
values 𝑉 in the range 0 to 2𝑛 − 1, where
𝑉 𝐵 = 𝑏𝑛−1 × 2𝑛−1 + ⋯ + 𝑏1 × 21 + 𝑏0 × 20
⚫ We obviously need to represent both positive
and negative numbers.
Signed Integer
⚫ 3 major representations:
⚫ Sign-and-magnitude
⚫ 1’s complement
⚫ 2’s complement
⚫ Assumptions:
⚫ 4-bit machine word
⚫ 16 different values can be represented
⚫ Roughly half are positive, half are negative
Sign-and-Magnitude Representation
-7 +0
-6 1111 0000 +1
1110 0001
-5 +2 +
1101 0010
-4 1100 0011 +3 0 100 = + 4
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
-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
Characters
⚫ In addition to numbers, computers must be
able to handle nonnumeric text information
consisting of characters.
⚫ Characters can be letters of the alphabet,
decimal digits, punctuation marks, and so on.
⚫ They are represented by codes that are
usually eight bits long.
⚫ American Standards Committee on Information
Interchange (ASCII) code is widely used.
ASCII Table
Memory Locations,
and Addresses
Memory Locations and
Addresses
n bits
first word
⚫ Memory consists
second word
of many millions of
storage cells,
•
each of which can •
•
store 1 bit.
⚫ Data is usually i th word
accessed in n-bit
groups called •
words. •
•
⚫ n is called word
length. last word
b31 b30 b1 b0
•
•
•
Sign bit: b31= 0 for positive numbers
b31= 1 for negative numbers
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
i
Assumptions:
Begin execution here Move A,R0
3-instruction - One memory operand
i+4 Add B,R0 program
i+8
segment per instruction
Move R0,C
- 32-bit word length
- Memory is byte
addressable
A - Full memory address
can be directly specified
in a single-word instruction
B Data for
the program
Two-phase procedure
-Instruction fetch
-Instruction execute
C
Page 43
•
•
•
i + 4n - 4 Add NUM n,R0
i + 4n Move R0,SUM
•
•
•
SUM
NUM1
NUM2
•
•
•
NUM n
Branching LOOP
Determine address of
"Next" number and add
Program "Next" number to R0
loop
Decrement R1
Branch>0 LOOP
Branch target
Move R0,SUM
Conditional branch
•
•
•
SUM
N n
NUM1
•
•
•
NUM n
Condition Codes
⚫ The processor keeps track of information
about the results of various operations for
use by subsequent conditional branch
instructions.
⚫ Accomplished by recording the required
information in individual bits, often called condition
code flags.
⚫ These flags are usually grouped together in a
special processor register called the condition
code register or status register.
Condition Codes
⚫ Four commonly used flags are
⚫ N (negative)
⚫ Set to 1 if the result is negative; otherwise, cleared to 0
⚫ Z (zero)
⚫ Set to 1 if the result is 0; otherwise, cleared to 0
⚫ V (overflow)
⚫ Set to 1 if arithmetic overflow occurs; otherwise, cleared to 0
⚫ C (carry)
⚫ Set to 1 if a carry-out results from the operation; otherwise,
cleared to 0
Conditional Branch
Instructions
⚫ Example: A: 11110000
⚫ A: 1 1 1 1 0 0 0 0 +(−B): 1 1 1 0 1 1 0 0
⚫ B: 0 0 0 1 0 1 0 0 11011100
C=1 Z=0
N=1
V=0
Status Bits
Cn-1
A B
Cn ALU
F
V Z N C
Fn-1
Zero Check