Professional Documents
Culture Documents
Course Code:18EC35
Semester: 3rd ,B.E
Department: Electronics and Communication
Name and designation of the faculty:Mangala S Jolad,Asst Prof
1
MODULE 1
Basic Structure of
Computers
(UNIT-2)
2
Machine Instructions and Programs
3
4
5
6
7
Hexadecimal to Binary Conversion
•Translate every hexadecimal digit into its 4-bit binary
equivalent.
•Examples:
(3A5)16 =(0011 1010 0101)2
(12.3D)16 = (0001 0010 . 0011 1101)2
(1.8)16 = (0001 . 1000)2
8
How are Hexadecimal Numbers Written?
•Using the suffix “H” or using the prefix “0x”.
•Examples:
- ADDI R1,2AH // Add the hex number 2A to register R1
- 0x2AB4 // The 16-bit number 0010 1010 1011 0100
- 0xFFFFFFFF // The 32-bit number for the all-1 string
9
Unsigned Binary Numbers
•An n-bit binary number can have 2n distinct combinations.
– For example, for n=3, the 8 distinct combinations are:
000, 001, 010, 011, 100, 101, 110, 111
(0 to 23-1 = 7 in decimal).
Number of bits (n) Range of Numbers
8 0 to 28-1 (255)
16 0 to 216-1 (65535)
32 13
0 to 232-1 (4294967295)
64 0 to 264-1
10
•An n-bit binary integer:
b
n-1bn-2 … b2b1b0
•Equivalent unsigned decimal value:
D = bn-12n-1 + bn-22n-2 + … + b222 + b121 + b020
11
Signed Integer Representation:
12
a) Sign-magnitude Representation
For an n-bit number representation:
The most significant bit (MSB) indicates sign (0: positive, 1:
negative).
The remaining (n-1) bits represent the magnitude of the number.
Range of numbers: – (2n-1 – 1) to + (2n-1 – 1)
13
b) Ones Complement Representation
Basic idea:
Positive numbers are represented exactly as in sign-magnitude
form.
Negative numbers are represented in 1’s complement form.
How to compute the 1’s complement of a number?
Complement every bit of the number (1->0 and 0->1).
MSB will indicate the sign of the number (0: positive, 1: negative).
14
15
Range of numbers that can be represented in 1’s complement:
Maximum :: + (2n-1 – 1)
Minimum :: - (2n-1 – 1)
A problem:
Two different representations of zero.
+0 --> 0 000….0
-0 --> 1 111….1
Advantage of 1’s complement representation:
Subtraction can be done using addition.
Leads to substantial saving in circuitry.
16
c) Twos Complement Representation
Basic idea:
Positive numbers are represented exactly as in sign-magnitude form.
Negative numbers are represented in 2’s complement form.
How to compute the 2’s complement of a number?
Complement every bit of the number (1 -> 0 and 0 -> 1 ), and then
add one to the resulting number.
MSB will indicate the sign of the number (0: positive, 1: negative).
17
To find the representation of, say, -4, first note that
+4 = 0100
-4 = 2’s complement of 0100 = 1011 + 1
= 1100
18
Range of numbers that can be represented in 2’s
complement:
Maximum :: + (2n-1 – 1)
Minimum :: - 2n-1
19
Some other features of 2’s complement representation
a)Weighted number representation, with the MSB having weight -2n-1.
b) Shift left by k positions with zero padding multiplies the number by 2k.
20
c) Shift right by k positions with sign bit padding divides the number
21
Addition of Positive numbers
The sum of 1 and 1 requires the 2-bit vector 10 to represent the value
2.
The sum is 0 and the carry-out is 1.
In order to add multiple-bit numbers, we use a method analogous to that
used for manual computation with decimal numbers.
We add bit pairs starting from the low-order (right) and of the bit vectors,
propagating carries toward the high-order (left) end.
22
Memory locations and addresses
Memory consists of many millions of storage cells (flip-flops).
Each cell can store a bit of information i.e. 0 or 1 (Figure 2.1).
Each group of n bits is referred to as a word of information, and n is called
the word length.
The word length can vary from 8 to 64 bits.
A unit of 8 bits is called a byte.
Accessing the memory to store or retrieve a single item of information
(word/byte) requires unique addresses for each item location. (It is
customary to use numbers from 0 through 2k-1 as the addresses of successive-
locations in the memory).
23
Memory locations and addresses contd..
If 2k = no. of addressable locations;
Then 2k addresses constitute the address-space of the computer.
For example, a 24-bit address generates an address-space of 2 24 locations (16
MB).
24
Memory locations and addresses contd..
BYTE-ADDRESSABILITY
In byte-addressable memory, successive addresses refer to successive byte locations
in the memory.
Byte locations have addresses 0, 1, 2. . . . .
If the word-length is 32 bits, successive words are located at addresses 0, 4, 8. . with
each word having 4 bytes.
25
Memory locations and addresses contd..
BIG-ENDIAN & LITTLE-ENDIAN ASSIGNMENTS
There are two ways in which byte-addresses are arranged (Figure 2.3).
Big-Endian: Lower byte-addresses are used for the more significant bytes of the
word.
Little-Endian: Lower byte-addresses are used for the less significant bytes of the
word
In both cases, byte-addresses 0, 4, 8. . . . . are taken as the addresses of successive
words in the memory.
26
Memory locations and addresses contd..
27
Memory locations and addresses contd..
WORD ALIGNMENT
28
Memory locations and addresses contd..
29
Memory locations and addresses contd..
MEMORY OPERATIONS
30
Memory locations and addresses contd..
MEMORY OPERATIONS
The Store operation transfers the information from the register to the
specified memory-location.
This will destroy the original contents of that memory-location.
Steps for Store operation are:
Processor sends the address of the memory-location where it wants to store
data.
Processor issues „write‟ signal to memory to store the data.
Content of register(MDR) is written into the specified memory-location.
31
Memory locations and addresses contd..
The second example of adding two numbers contained in processor registers R1 and
R2 and placing their sum in R3 can be specified by the assembly language statement
Add R1, R2, R3
3.BASIC INSTRUCTIONS:-
The statement C=A+B
In a high-level language program is a command to the computer to add the current
values of the two variables called A and B, and to assign the sum to a third variable, C.
The contents of these locations represent the values of the three variables. Hence,
the above high-level language statement requires the action. C <- [A] + [B]
34
The three-address instruction can be represented symbolically as
Add A, B, C
Operands A and B are called the source operands, C is called the destination
operand, and Add is the operation to be performed on the operands.
A general instruction of this type has the format.
Operation Source1, Source 2, Destination
above instruction can be replaced by two address instructions as
MOVE B,C
ADD A,C
Instruction with only one operand
ADD A
Add the content of memory location A to the content of accumulator
Load A
Store A
The operation C <- [A] + [B] can be performed by executing the sequence of
instructions
Load A
Add B
Store C
35
Let Ri represent a general-purpose register. The instructions
Load A, Ri
Store Ri, A
Add A, Ri
In both of below instructions, the source operands are the contents of
registers Ri and Rj.
In the first instruction, Rj also serves as the destination register, whereas in
the second instruction, a third register, Rk, is used as the destination.
Add Ri, Rj
Add Ri, Rj,Rk
36
4. INSTRUCTION EXECUTION AND STRAIGHT-LINE
SEQUENCING:-
Let us consider the task C<-[A] +[B].
A possible program segment for this task as it
appears in the memory of a computer.
Assume that the computer allows one memory
operand per instruction and has a number of
processor registers.
Assume that the word length is 32 bits and
memory is byte addressable.
The three instructions of the program are in
successive word locations, starting at location i.
Since each instruction is 4 bytes long, these
second and third instructions start at addresses
i+4 and i+8.
37
Execution of instruction has two-phase
procedure
I. Instruction fetch-> fetch the instruction
from memory and store in IR reg
II. Instruction execute-> instruction in IR is
examined to determine which operation is
to be done. It involves
*fetching of operands from memory or
from processor register
*performing the operation
*storing the result
38
5. BRANCHING:-
Consider the task of adding a list of n
numbers.
Instead of using a long list of add instructions,
it is possible to place a single add instruction in
a program loop, as shown.
The loop is a straight-line sequence of
instructions executed as many times as
needed.
It starts at location LOOP and ends at the
instruction Branch > 0.
During each pass through this loop, the
address of the next list entry is determined,
and that entry is fetched and added to R0
39
5. BRANCHING:-
Consider the task of adding a list of „n‟ numbers .
Number of entries in the list „n‟ is stored in memory-location
N.
Register R1 is used as a counter to determine the number of
times the loop is executed.
The Loop is a straight line sequence of instructions executed
as many times as needed.
The loop starts at location LOOP and ends at the instruction
Branch>0.
During each pass,
→ address of the next list entry is determined and
→ that entry is fetched and added to R0.
The instruction Decrement R1 reduces the contents of R1 by 1
each time through the loop.
Then Branch Instruction loads a new value into the program
counter. As a result, the processor fetches and executes the
instruction at this new address called the Branch Target.
A Conditional Branch Instruction causes a branch only if a
specified condition is satisfied. If the condition is not satisfied,
the PC is incremented in the normal way, and the next
instruction in sequential address order is fetched and executed 40
6. CONDITION CODES
The processor keeps track of information about the results of various operations. This
is accomplished by recording the required information in individual bits, called
Condition Code Flags.
These flags are grouped together in a special processor-register called the condition
code register (or statue register).
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.
41