Basic Structure of Computers
Basic Structure of Computers
Module 1 Chapter 1
Functional Units
Arithmetic
Input and
logic
Memory
Output Control
Main Cache
memory memory Processor
Bus
The processor and a relatively small cache
memory can be fabricated on a single
integrated circuit chip.
Cost is high.
Processor Clock
Keywords: Clock, clock cycle, and clock rate
R – clock rate
N S
T
R
Basic Performance Equation
How to improve T?
To achieve high performance
Example:
SPEC2000
Ultra SPARC 10
Running time on the reference computer
SPEC rating
Running time on the computer under test
n 1
SPEC rating ( SPECi ) n
i 1
Machine Instructions and
Programs
Module 1 Chapter 2
Memory Locations and
Addresses
Byte Addressability
Endian Formats
Word Alignment
Accessing number, character and string
Memory Location 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. n is called •
word length. •
•
last word
b31 b30 b1 b0
•
•
•
Sign bit: b31= 0 for positive numbers
b31= 1 for negative numbers
Unique and
continuous
addresses are
assigned to
successive
bytes in the
memory.
Byte Addressability
If word size is
n bytes, and
every word
starts at the
address
multiple of n.
Word Aligned Memory
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,….
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
4. I/O transfers
Register Transfer Notation
Identify a location by a symbolic name standing
for its hardware binary address (LOC, R0,…)
i
Assumptions:
Begin execution here Move A,R0
i+4
3-instruction
program
- One memory operand
Add B,R0
segment per instruction
i+8 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 NUMn,R0
i + 4n Move R0,SUM
•
•
•
SUM
NUM1
NUM2
•
•
•
NUMn
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
•
•
•
NUMn
Condition Codes
Condition code / flags
Condition code register / status register
N (negative)
Z (zero)
V (overflow)
C (carry)
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
S=1
V=0
Status Bits
Cn-1
A B
Cn ALU
F
V Z S C
Fn-1
Zero Check
Addressing Modes
1. Register Addressing
2. Direct (Absolute) Addressing
3. Immediate Addressing
4. Indirect Addressing
5. Index Addressing
6. Relative Addressing
Direct Address
Use the given address to access a memory
location
Addressing Modes
Indirect Address
Indicate the memory location that holds the
address of the memory location that holds the
data
AR = 101
100
101 0 1 0 4
102
103
104 1 1 0 A
Addressing Modes
Relative Address
0
EA = PC + Relative Addr 1
PC = 2 2
100
AR = 100
101
102 1 1 0 A
Could be Positive or 103
Negative 104
(2’s Complement)
Addressing Modes
Indexed
EA = Index Register + Relative Addr
Useful with XR = 2
“Autoincrement” or
“Autodecrement”
+
100
AR = 100
101
Could be Positive or
Negative 102 1 1 0 A
(2’s Complement) 103
104
Addressing Modes
Base Register
EA = Base Register + Relative Addr
Could be Positive or AR = 2
Negative
(2’s Complement)
+
100 0 0 0 5
BR = 100
101 0 0 1 2
102 0 0 0 A
Usually points to 103 0 1 0 7
the beginning of 104 0 0 5 9
an array
Addressing Modes
Name Assembler syntax Addressingfunction
The different
ways in which Immediate #Value Op erand = Value
the location of
an operand is Register Ri EA = Ri
specified in Absolute (Direct) LOC EA = LOC
an instruction
are referred Indirect (Ri ) EA = [Ri ]
to as (LOC) EA = [LOC]
addressing
modes. Index X(R i) EA = [Ri ] + X
Figure 2.16. The Autoincrement addressing mode used in the program of Figure 2.12.
Assembly
Language
Types of Instructions
Data Transfer Instructions
Name Mnemonic Data value is
Load LD not modified
Store ST
Move MOV
Exchange XCH
Input IN
Output OUT
Push PUSH
Pop POP
Data Transfer Instructions
Mode Assembly Register Transfer
Direct address LD ADR AC ← M[ADR]
Indirect address LD @ADR AC ← M[M[ADR]]
Relative address LD $ADR AC ← M[PC+ADR]
Immediate operand LD #NBR AC ← NBR
Index addressing LD ADR(X) AC ← M[ADR+XR]
Register LD R1 AC ← R1
Register indirect LD (R1) AC ← M[R1]
Autoincrement LD (R1)+ AC ← M[R1], R1 ← R1+1
Data Manipulation Instructions
Name Mnemonic
Arithmetic Increment INC
Decrement DEC
Logical & Bit Manipulation Add ADD
Shift Subtract SUB
Multiply MUL
Divide DIV
Add with carry ADDC
Name Mnemonic Subtract with borrow SUBB
Clear CLR Negate NEG
Complement COM Name Mnemonic
AND AND Logical shift right SHR
OR OR Logical shift left SHL
Exclusive-OR XOR Arithmetic shift right SHRA
Clear carry CLRC Arithmetic shift left SHLA
Set carry SETC Rotate right ROR
Complement carry COMC Rotate left ROL
Enable interrupt EI Rotate right through carry RORC
Disable interrupt DI Rotate left through carry ROLC
Program Control Instructions
Name Mnemonic
Branch BR
Jump JMP
Skip SKP
Subtract A – B but
Call CALL don’t store the result
Return RET
Compare
CMP
(Subtract) 10110001
Test (AND) TST
00001000
Mask
00000000
Conditional Branch
Instructions
Program-Controlled I/O
Processor
DATAIN
SIN
Key board
SOUT
Display
Example
- Registers
- Flags
- Device interface
Program-Controlled I/O
Example
Machine instructions that can check the state
of the status flags and transfer data:
READWAIT Branch to READWAIT if SIN = 0
Input from DATAIN to R1
Alternate solution?
Interrupt
Stacks and Queues
0
.
.
.
.
TOP 0
1
SP 2 34
3 45 STACK
4 67
5 34
BOTTOM 6 95
.
.
.
2K-1
If word size is 32bit and stack memory is word sized
PUSH
SUBSTRACT #4, SP
MOVE NEWITEM, (SP)
POP
MOVE (SP), ITEM
ADD #4, SP
Textbook follows
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