Module 1 –Part 2
Module 1 –Part 2
Stack:
Advantages: Simple Model of expression evaluation (reverse polish). Short
instructions.
Disadvantages: A stack can't be randomly accessed This makes it hard to
generate efficient code. The stack itself is accessed every operation and
becomes a bottleneck.
Accumulator:
Advantages: Short instructions.
Disadvantages: The accumulator is only temporary storage so memory
traffic is the highest for this approach.
GPR:
Advantages: Makes code generation easy. Data can be stored for long
periods in registers.
Disadvantages: All operands must be named leading to longer
instructions.
Why GPR based CPU?
-The Index mode facilitates access to an operand whose location is defined relative to a
reference point within the data structure in which the operand appears.
Operand is implicitly on top of the stack.
Used in zero-address machines earlier.
Examples:
– ADD
– PUSH X
– POP X
Many processors have a special register called the stack pointer
(SP) that keeps track of the stack-top in memory.
– PUSH, POP, CALL, RET instructions automatically modify SP.
Effective address(EA)
Base addressing
– The processor has a special register called the base register or
segment register.
– All operand addresses generated are added to the base register
to get the final memory address.
– Allows easy movement of code and data in memory.
Auto-increment and Auto-decrement
– First introduced in the PDP-11 computer system.
– The register holding the operand address is automatically
incremented or decremented after accessing the operand (like
a++ and a-- in C).
1. Numerical Problem
The two-word instruction at address 200 and 201 is a "load to AC"
instruction with an address field equal to 500. The first word of
the instruction specifies the operation code and mode, and the
second word specifies the address part. PC has the value 200 for
fetching this instruction. The content of processor register R 1 is
400, and the content of an index register XR is 100. AC receives
the operand after the instruction is executed. The figure lists a
few pertinent addresses and shows the memory content at each
of these addresses.
Evaluate the EA and operand if the addressing mode of the
instruction is:
1. Direct 2.Immediate 3. Indirect
4. Relative 5. Index mode 6.Register mode 7.Register Indirect
2. Numerical Problem
An instruction is stored at location 500 with its address field at
location 501. The address field has the value 300. A processor
register R1 contains the number 100. Evaluate the effective
address if the addressing mode of the instruction is
1. Immediate 2. Direct 3. Register Indirect
4. Relative 5. Index with R1 as the index register.
What is the Performance?
clock period
2nd instruction
3rd instruction
1st instruction
4th
5th
6th
...
time
time
Example 2:
CPU clock rate is 500 MHz
Program takes 45 million cycles to execute
What’s the CPU time
CPU Time Example
Example 1:
CPU clock rate is 1 MHz
Program takes 45 million cycles to execute
What’s the CPU time?
Example 2:
CPU clock rate is 500 MHz
Program takes 45 million cycles to execute
What’s the CPU time
24
= 1.2 times
20
Instruction Types and CPI
• Consider a program executing on a processor, with n types or
classes of instructions (like, load, store, ALU, branch, etc.).
ICi = number of instructions of type i executed
CPIi = cycles per instruction for type i
• The following expressions follow.
CPI Example
24
= 1.2 times
20
Practice Example
1.Suppose that Machine A execute a program with average CPI of
2.3.Consider another machine B (with same instruction set & complier)
that execute a same program with 20% less instruction and with CPI of
1.7 at 1.2GHz.What should be clock rate of Machine A so that 2
machines have same performance.
MIPS (Million Instructions Per Second)
Hexadecimal
Conversion of binary to decimal
Q. 1.Convert Integer 101011 to decimal
0000 +0 1111 -0
0001 +1 1110 -1
0010 +2 1100 -2
0011 +3 1100 -3
0100 +4 1011 -4
0101 +5 1010 -5
0110 +6 1001 -6
0111 +7 1000 -7
Two’s complement representation
2’s complement
For n=4
0000 +0 1000 -8
0001 +1 1111 -1
0010 +2 1110 -2
0011 +3 1101 -3
0100 +4 1100 -4
0101 +5 1011 -5
0110 +6 1010 -6
0111 +7 1001 -7
Q.1Convert Decimal to binary:41.6875
Ans:14 1 . 6875) = ( 1 0 1 00 1 . 1 0 1 1 )
Q.2.Convert 1938 to hexadecimal.
Q.3. Obtain the l's and 2's complements of the following eight-digit
binary numbers: 10101 1 10; 10000001; 10000000; 00000001; and
00000000.