Professional Documents
Culture Documents
Basic
Structure of Computers
Functional Units
Functional Units
Arithmetic
Input and
logic
Memory
Output Control
I/O Processor
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
Sign Extension
Task:
Given w-bit signed integer x
Rule:
Make k copies of sign bit:
• • •
X • • • • • •
k w
Chapter 2.
Instruction Set
Architecture
Objectives
Machine instructions and program execution,
including branching and subroutine call and return
operations.
Addressing methods for accessing register and
memory operands.
Assembly language for representing machine
instructions, data, and programs.
Program-controlled Input/Output operations.
Memory Locations
and Addresses
Memory Location, Addresses,
and Operation
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. 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 Load R2, A
i+4
4-instruction
program
- One memory operand
Load R3, B
segment per instruction
i+8 Add R4, R2, R3
- 32-bit word length
I + 12 Store R4, C
- 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
Pop
Load Rj, (SP)
Add SP, SP, #4
Stack Organization
Current
Top of Stack
LIFO TOS 0
Last In First Out 1
2
3
4
5
SP 6 0 1 2 3
7 0 0 5 5
FULL EMPTY 8 0 0 0 8
9 0 0 2 5
Stack Bottom 10 0 0 1 5
Stack
Stack Organization
Current 1 6 9 0
Top of Stack
PUSH TOS 0
SP ← SP – 1 1
M[SP] ← DR 2
3
If (SP = 0) then (FULL ← 1) 4
EMPTY ← 0 5 1 6 9 0
SP 6 0 1 2 3
7 0 0 5 5
FULL EMPTY 8 0 0 0 8
9 0 0 2 5
Stack Bottom 10 0 0 1 5
Stack
Stack Organization
Current
Top of Stack
POP TOS 0
DR ← M[SP] 1
SP ← SP + 1 2
3
If (SP = 11) then (EMPTY ← 1) 4
FULL ← 0 5 1 6 9 0
SP 6 0 1 2 3
7 0 0 5 5
FULL EMPTY 8 0 0 0 8
9 0 0 2 5
Stack Bottom 10 0 0 1 5
Stack
Stack Organization
Memory Stack
PUSH PC 0
1
SP ← SP – 1 2
M[SP] ← DR
POP AR 100
DR ← M[SP] 101
102
SP ← SP + 1
200
SP 201
202
Subroutines
A block of instructions that is executed each time
a task has to be performed is called subroutine.
Implemented using CALL and RETURN
instructions.
The way in which a computer makes it possible
to call and return from subroutines is referred to
as its subroutine linkage method.
The simplest subroutine linkage method is to
save the return address in a specific location,
which may be a register dedicated to this
function. Such a register is called the link
register.
Call instruction steps:
Store the contents of the PC in the link
register
Branch to the target address specified by the
Call instruction
Return instruction steps:
Branch to the address contained in the link
register.
Subroutine Nesting and Processor
Stack
One subroutine calling another.
Subroutine nesting can be carried out to any
depth.
The last subroutine called completes its
computations and returns to the subroutine
that called it.
Return addresses associated with subroutine
calls should be pushed onto the processor
stack
Parameter Passing
Registers:
Parameter Passing
Stack:
Parameter Passing
Stack:
Parameter Passing
Stack:
Stack Frame
During execution of the subroutine, locations at
the top of the stack contain entries that are
needed by the subroutine.
These locations constitute a private work space
for the subroutine, allocated at the time the
subroutine is entered and deallocated when the
subroutine returns control to the calling program.
Such space is called a stack frame.
In addition to the stack pointer SP, it is useful to
have another pointer register, called the frame
pointer (FP), for convenient access to the
parameters passed to the subroutine and to the
local memory variables used by the subroutine.
Stack Frame
FP register points to
the location just
above the stored
parameters.
The parameters can
be accessed by using
addresses 4(FP),
8(FP), . . . .
The local variables
can be accessed by
using addresses
−4(FP), −8(FP), . . . .
The contents of FP
remain fixed
throughout the
execution of the
subroutine, unlike
SP.
Additional
Instructions
Logical Shifts
Logical shift – shifting left (LShiftL) and shifting right
(LShiftR)
C R0 0
before: 0 0 1 1 1 0 . . . 0 1 1
after: 1 1 1 0 . . . 0 1 1 0 0
0 R0 C
before: 0 1 1 1 0 . . . 0 1 1 0
after: 0 0 0 1 1 1 0 . . . 0 1
R0 C
before: 1 0 0 1 1 . . . 0 1 0 0
after: 1 1 1 0 0 1 1 . . . 0 1
before: 0 0 1 1 1 0 . . . 0 1 1
Rotate after: 1 1 1 0 . . . 0 1 1 0 1
C R0
before: 0 0 1 1 1 0 . . . 0 1 1
after: 1 1 1 0 . . . 0 1 1 0 0
R0 C
before: 0 1 1 1 0 . . . 0 1 1 0
after: 1 1 0 1 1 1 0 . . . 0 1
R0 C
before: 0 1 1 1 0 . . . 0 1 1 0
after: 1 0 0 1 1 1 0 . . . 0 1