Beruflich Dokumente
Kultur Dokumente
SCSR2033
Computer Organization
and Architecture
Lecture slides prepared by “Computer Organization and Architecture”, 9/e, by William Stallings, 2013.
1
Module 4
Instruction Set Architecture
(ISA)
Objectives:
q To provide a more detailed look at machine
instruction sets.
q To look at different instruction types and
operand types, and how instructions access
data in memory.
q To understanding how instruction sets are designed and
how their function can help to understand the more
intricate details of the architecture of the machine itself.
m @ Feb 2019 1
SCSR2033 - Computer Architecture and Organization
Module 4
Instruction Set Architecture
(ISA)
4.1 Introduction
4.2 Machine Instruction Characteristics
4.3 Types of Operands
4.4 Addressing Modes
4.5 Instruction Formats
4.6 Summary
Module 4
Instruction Set Architecture
(ISA)
m @ Feb 2019 2
SCSR2033 - Computer Architecture and Organization
4
Overview
ALU (Arithmetic Logic Unit)
William Stallings (2013). Computer Organization and Architecture: Designing for Performance (9th Edition). United States: Pearson Education Limited, p.248. 5
4
Some important questions to ask:
n What is an assembler?
m @ Feb 2019 3
SCSR2033 - Computer Architecture and Organization
4
Hierarchy of Computer Languages
4
Assembly and Machine Languages
m @ Feb 2019 4
SCSR2033 - Computer Architecture and Organization
4
Compiler and Assembler
4
High-Level Languages: Advantages
m @ Feb 2019 5
SCSR2033 - Computer Architecture and Organization
4
Why Assembly Languages?
11
4
HLL (High Level Language)
12
m @ Feb 2019 6
SCSR2033 - Computer Architecture and Organization
4
General Concepts:
X86 Processor Architecture
Irvine, K.R. (2011). Assembly Language for x86 Processors (6th Edition). New Jersey: Pearson Education Limited, p.29. 13
4
Basic Microcomputer Design
(Section 5.2)
n One
Registers
m @ Feb 2019 7
SCSR2033 - Computer Architecture and Organization
4
CPU (Central Processing Unit)
Elements Description
Clock o synchronizes the internal CPU operations.
Control Unit (CU) o coordinates sequence of execution steps.
Arithmetic Logic o performs arithmetic and bitwise
Unit (ALU). processing.
Irvine, K.R. (2011). Assembly Language for x86 Processors (6th Edition). New Jersey: Pearson Education Limited, p.30. 15
4
Clock
Irvine, K.R. (2011). Assembly Language for x86 Processors (6th Edition). New Jersey: Pearson Education Limited, p.31. 16
m @ Feb 2019 8
SCSR2033 - Computer Architecture and Organization
Instruction 4
Execution Cycle
Registers
n ___________
ALU
n ___________
n ___________
n ___________
n Store output Figure: Simplified
CPU block diagram.
Irvine, K.R. (2011). Assembly Language for x86 Processors
(6th Edition). New Jersey: Pearson Education Limited, p.31.
4
Reading From Memory
m @ Feb 2019 9
SCSR2033 - Computer Architecture and Organization
4
n Multiple machine cycles are required when reading from
memory, because it responds much more slower than the
CPU.
n The steps are:
n Cycle 1: address placed on address bus (ADDR).
Irvine, K.R. (2011). Assembly Language for x86 Processors (6th Edition). New Jersey: Pearson Education Limited, p.33. 19
4
How Program Run?
Assembling, Linking, and Running Programs
Link
Library
Step 2: Step 3: Step 4:
Source assembler Object linker Executable OS loader
Output
File File File
Listing Map
Step 1: text editor File File
m @ Feb 2019 10
SCSR2033 - Computer Architecture and Organization
4
Listing File
n Contains:
q source code
q addresses
q object code (machine language)
q segment names
q symbols (variables, procedures, and constants)
n Example: addSub.lst
21
m @ Feb 2019 11
SCSR2033 - Computer Architecture and Organization
4
• 32-bit addresses
• indicate the relative byte
distance of each statement
from the beginning of the
program’s code area
• contain no executable
instructions
4
• … directives,
m @ Feb 2019 12
SCSR2033 - Computer Architecture and Organization
4
Map File
q ending address
q size
q segment type
26
m @ Feb 2019 13
SCSR2033 - Computer Architecture and Organization
4
Design Decisions for Instruction Sets
Linda Null and Julia Lobur (2003). The Essentials of Computer Organization and Architecture. United States: Jones and Bartlett Publishers. p.200. 27
4
ISA Level
ISA (Instruction Set Architecture)
28
m @ Feb 2019 14
SCSR2033 - Computer Architecture and Organization
Linda Null and Julia Lobur (2003). The Essentials of Computer Organization and Architecture. United States: Jones and Bartlett Publishers. p.200. 29
Module 4
Instruction Set Architecture
(ISA)
4.1 Introduction
4.2 Machine Instruction q Elements of a Machine
Characteristics Instruction
4.3 Types of Operands q Instruction Representation
4.4 Addressing Modes q Instruction Types
4.5 Instruction Formats
q Number of Addresses
4.6 Summary
q Instruction Set Design
m @ Feb 2019 15
SCSR2033 - Computer Architecture and Organization
4
Elements of a Machine Instruction
William Stallings (2013). Computer Organization and Architecture: Designing for Performance (9th Edition). United States: Pearson Education Limited, p.428. 31
4
Table: The elements of a machine instruction.
Elements Description
Operation code o Specifies the operation to be performed a
binary code (e.g., MOV, ADD, SUB).
(___________)
Source operand o The operation may involve one or more
reference source operands, that is, operands that are
inputs for the operation.
Result operand o The operation may produce a result.
reference
(___________).
Next instruction o This tells the processor where to fetch the
reference next instruction after the execution of this
instruction is complete.
William Stallings (2013). Computer Organization and Architecture: Designing for Performance (9th Edition). United States: Pearson Education Limited, p.428. 32
m @ Feb 2019 16
SCSR2033 - Computer Architecture and Organization
4
Example 1:
Destination
Operand
Source Operand
33
4
n Source and result operands (___________) can be in one
of four areas:
William Stallings (2013). Computer Organization and Architecture: Designing for Performance (9th Edition). United States: Pearson Education Limited, p.429. 34
m @ Feb 2019 17
SCSR2033 - Computer Architecture and Organization
4
Example 2:
Operand: Memory
Operand: Register
Current Ins. : 0000 0000 MOV AX,TOTAL
Next Ins. : 0001 0001 MOV BX,AX
0002 ADD AX,2 Operand:
0003 TARGET Immediate value
0004 CALL READINT
0005 MOV VAL,EAX Operand: From
0006 ADD EBX,VAL I/O
Current Ins. : 0007 0007 JMP TARGET
Next Ins. : 0003
Next instruction is
where TARGET is
located = 0003
35
4
Instruction Representation
William Stallings (2013). Computer Organization and Architecture: Designing for Performance (9th Edition). United States: Pearson Education Limited, p.429-430. 36
m @ Feb 2019 18
SCSR2033 - Computer Architecture and Organization
n Common examples:
William Stallings (2013). Computer Organization and Architecture: Designing for Performance (9th Edition). United States: Pearson Education Limited, p.430. 37
n Example: 4
William Stallings (2013). Computer Organization and Architecture: Designing for Performance (9th Edition). United States: Pearson Education Limited, p.430. 38
m @ Feb 2019 19
SCSR2033 - Computer Architecture and Organization
4
Instruction Types
n Consider a high-level
A single C instruction may require
language instruction that
3 machine instructions; This is
could be expressed in a typical of the relationship between
language such as C. a high-level language and a
n Example: machine language.
n In assembly language:
1) Load a register with the contents of memory (for Total)
2) Add the contents of memory (for stuff) to the register
3) Store the content of the register to memory location (for
Total)
William Stallings (2013). Computer Organization and Architecture: Designing for Performance (9th Edition). United States: Pearson Education Limited, p.431. 39
4
n Translating the language:
m @ Feb 2019 20
SCSR2033 - Computer Architecture and Organization
4
Instruction
Types
4
Number of Addresses
William Stallings (2013). Computer Organization and Architecture: Designing for Performance (9th Edition). United States: Pearson Education Limited, p.432. 42
m @ Feb 2019 21
SCSR2033 - Computer Architecture and Organization
William Stallings (2016). Computer Organization and Architecture: Designing for Performance (10th Edition). United States: Pearson Education Limited, p.417. 43
4
How Many Addresses?
44
m @ Feb 2019 22
SCSR2033 - Computer Architecture and Organization
4
Instruction Set Design
William Stallings (2013). Computer Organization and Architecture: Designing for Performance (9th Edition). United States: Pearson Education Limited, p.434. 45
o The mode(s)
by which the
address of an Addressing Data Types
operand is
o The various
specified.
types of data.
Instruction
Registers
Formats
m @ Feb 2019 23
SCSR2033 - Computer Architecture and Organization
Module 4
Instruction Set Architecture
(ISA)
4.1 Introduction
4.2 Machine Instruction q Overview
Characteristics
q Numbers
4.3 Types of Operands
q Characters
4.4 Addressing Modes
4.5 Instruction Formats q Logical Data
4.6 Summary
4
Overview
MOV R1, R2
___________ : ___________
What to do with the data Where to get data (R2)
(ALU operation) and put the results (R1)
48
m @ Feb 2019 24
SCSR2033 - Computer Architecture and Organization
Data
(Section 4.4)
William Stallings (2013). Computer Organization and Architecture: Designing for Performance (9th Edition). United States: Pearson Education Limited, p.435. 49
50
m @ Feb 2019 25
SCSR2033 - Computer Architecture and Organization
4
Numbers
William Stallings (2013). Computer Organization and Architecture: Designing for Performance (9th Edition). United States: Pearson Education Limited, p.435. 51
4
Example 3a: x86 numerical data types.
(Unsigned integers)
William Stallings (2016). Computer Organization and Architecture: Designing for Performance (10th Edition). United States: Pearson Education Limited, p.424. 52
m @ Feb 2019 26
SCSR2033 - Computer Architecture and Organization
4
Example 3b: x86 numerical data types.
(Signed integers)
William Stallings (2016). Computer Organization and Architecture: Designing for Performance (10th Edition). United States: Pearson Education Limited, p.424. 53
4
Example 3c: x86 numerical data types.
(Signed integers)
William Stallings (2016). Computer Organization and Architecture: Designing for Performance (10th Edition). United States: Pearson Education Limited, p.424. 54
m @ Feb 2019 27
SCSR2033 - Computer Architecture and Organization
4
Characters
William Stallings (2013). Computer Organization and Architecture: Designing for Performance (9th Edition). United States: Pearson Education Limited, p.436. 55
4
Logical Data
n
William Stallings (2013). Computer Organization and Architecture: Designing for Performance (9th Edition). United States: Pearson Education Limited, p.436. 56
m @ Feb 2019 28
SCSR2033 - Computer Architecture and Organization
Module 4
Instruction Set Architecture
(ISA)
q Overview
4.1 Introduction
4.2 Machine Instruction q Immediate Addressing
Characteristics q Direct Addressing
4.3 Types of Operands q Indirect Addressing
4.4 Addressing Modes q Register Addressing
4.5 Instruction Formats
q Register Indirect Addressing
4.6 Summary
q Displacement Addressing
4
Overview
William Stallings (2013). Computer Organization and Architecture: Designing for Performance (9th Edition). United States: Pearson Education Limited, p.474. 58
m @ Feb 2019 29
SCSR2033 - Computer Architecture and Organization
A = contents of
4
an address field
in instruction.
R = contents of
an address field
in instruction
that refers to a
register.
EA = actual
(effective)
address of the
location
containing the
referenced
operand.
(X) = contents
of memory
location X or
Figure: Addressing modes. register X.
William Stallings (2016). Computer Organization and Architecture: Designing for Performance (10th Edition). United States: Pearson Education Limited, p.458. 59
William Stallings (2016). Computer Organization and Architecture: Designing for Performance (10th Edition). United States: Pearson Education Limited, p.459. 60
m @ Feb 2019 30
SCSR2033 - Computer Architecture and Organization
4
Immediate Addressing
4
Direct Addressing
William Stallings (2013). Computer Organization and Architecture: Designing for Performance (9th Edition). United States: Pearson Education Limited, p.476. 62
m @ Feb 2019 31
SCSR2033 - Computer Architecture and Organization
4
Example 4: Direct addressing.
Address of
operand = 1011
AX = 10h
AX = 10h + 28h
= 38h
63
.data
.code
main PROC
al = __________h mov al,val1
mov bx,array1
bx = __________h
mov ecx,array2
ecx = 00000123h call dumpregs
exit
main ENDP
(DumpRegs)
EAX=7611ED10 EBX=7FFD2210 ECX=00000123 EDX=00401022
ESI=00000000 EDI=00000000 EBP=0012FF94 ESP=0012FF8C
EIP=0040102D EFL=00000246 CF=0 SF=0 ZF=1 OF=0
64
m @ Feb 2019 32
SCSR2033 - Computer Architecture and Organization
4
Indirect Addressing
William Stallings (2013). Computer Organization and Architecture: Designing for Performance (9th Edition). United States: Pearson Education Limited, p.477. 65
.data
.code
main PROC
bl = __________h
mov bl,[array1]
cx = __________h mov cx,[array2]
mov edx,[array3]
edx = 00123456h mov ax,[array2+2]
ax = __________h call dumpregs
exit
main ENDP
(DumpRegs)
EAX=00000234 EBX=00000010 ECX=00000123 EDX=00123456
ESI=00404004 EDI=00404008 EBP=0012FF94 ESP=0012FF8C
EIP=0040104C EFL=00000246 CF=0 SF=0 ZF=1 OF=0
66
m @ Feb 2019 33
SCSR2033 - Computer Architecture and Organization
4
Register Addressing
William Stallings (2013). Computer Organization and Architecture: Designing for Performance (9th Edition). United States: Pearson Education Limited, p.476. 67
.data
.code
4
Example 7: Register addressing.
main PROC
eax = 00000000h mov eax,0
ebx = 00002000h mov ebx,2000h
mov ecx,3000h
ecx = 00003000h
mov eax,ebx
eax = 00002000h add eax,ecx
eax = 00005000h call dumpregs
exit
main ENDP
(DumpRegs)
EAX=00005000 EBX=00002000 ECX=00003000 EDX=00401005
ESI=00404004 EDI=00000000 EBP=0012FF94 ESP=0012FF8C
EIP=00401028 EFL=00000206 CF=0 SF=0 ZF=0 OF=0
68
m @ Feb 2019 34
SCSR2033 - Computer Architecture and Organization
4
Register Indirect Addressing
William Stallings (2013). Computer Organization and Architecture: Designing for Performance (9th Edition). United States: Pearson Education Limited, p.478. 69
.data
array1 byte
array2 word
10h,11h,12h,13h
123h,234h
4
Example 8:
Register indirect addressing. .code Address of the data
that stored in register.
m @ Feb 2019 35
SCSR2033 - Computer Architecture and Organization
.data
array1 byte
array2 word
10h,11h,12h,13h
123h,234h
4
.code
71
.data
.code
4
Example 9:
Register indirect addressing. main PROC
mov ebx,404000h
ebx = 00404000h mov dl,[ebx]
inc ebx
dl = __________h mov cl,[ebx]
ebx = 00404001h
call dumpregs
cl = __________h exit
main ENDP
(DumpRegs)
EAX=00005000 EBX=00404001 ECX=00000055 EDX=00000024
ESI=00404000 EDI=00000000 EBP=0012FF94 ESP=0012FF8C
EIP=0040103D EFL=00000202 CF=0 SF=0 ZF=0 OF=0
72
m @ Feb 2019 36
SCSR2033 - Computer Architecture and Organization
4
Displacement Addressing
William Stallings (2013). Computer Organization and Architecture: Designing for Performance (9th Edition). United States: Pearson Education Limited, p.478. 73
4
(a) Relative Addressing
R = PC
EA = A + (PC)
William Stallings (2013). Computer Organization and Architecture: Designing for Performance (9th Edition). United States: Pearson Education Limited, p.479. 74
m @ Feb 2019 37
SCSR2033 - Computer Architecture and Organization
Example 10:
how much to jump = where is L1 – PC
how much to jump = 28 – 39
4
= – EF
Displacement Addressing.
(a) Relative addressing
–(ve) because
00000014 B9 00000000 mov ecx,0 its jumping
00000019 BA 00000000 mov edx,0 backwards
0000001E B8 00000000 mov eax,0
00000023 B9 00000004 mov eax,4
00000028 L1:
00000028 66| 8B 98 mov bx,array2[eax]
00000008 R
PC=39:
PC = 39
0000002F 83 C0 02 add eax,2
00000032 E8 00000000 E call dumpregs Need to go to
00000037 E2 EF LOOP L1 L1 which is
in 00000028
exit
00000039 6A 00 * push +000000000h
75
4
(b) Base-Register Addressing
EA = A + R
o A holds displacement.
o R holds pointer to base address.
o R may be explicit or implicit.
William Stallings (2013). Computer Organization and Architecture: Designing for Performance (9th Edition). United States: Pearson Education Limited, p.479. 76
m @ Feb 2019 38
SCSR2033 - Computer Architecture and Organization
Example 11:
.data
count
array1
dword 10h
byte 10h,11h,12h,13h
4
array2 word 123h,234h,345h,456h
Displacement Addressing.
array3 dword 123456h, 23456789h
(b) Base-register addressing Base-index
.code
addressing
main PROC
mov esi, offset array1
mov ebx,10h
mov ax, word ptr[ebx+esi]
add ebx, esi
mov cx, word ptr[ebx]
call dumpregs
exit
main ENDP Base
addressing
77
.data
count
array1
dword 10h
byte 10h,11h,12h,13h
4
array2 word 123h,234h,345h,456h
array3 dword 123456h, 23456789h
.code
esi = 00404004h main PROC
mov esi, offset array1
ebx = 00000010h mov ebx,10h
mov ax, word ptr[ebx+esi]
ax = __________h add ebx, esi
ebx = 00404014h mov cx, word ptr[ebx]
m @ Feb 2019 39
SCSR2033 - Computer Architecture and Organization
4
(c) Indexed Addressing
EA = A + R
o A = base
o R = displacement
o Good for accessing arrays
William Stallings (2013). Computer Organization and Architecture: Designing for Performance (9th Edition). United States: Pearson Education Limited, p.479. 79
4
Exercise 4.1:
.data
array1 byte 10h,11h,12h,13h
array2 word 123h,234h,345h,456h
array3 dword 123456h, 23456789h
80
m @ Feb 2019 40
SCSR2033 - Computer Architecture and Organization
4
Offset : Value: Offset : Value:
00404004:
81
Example 12:
.data
array1 byte 10h,11h,12h,13h
array2 word 123h,234h,345h,456h
4
array3 dword 123456h, 23456789h
Displacement Addressing.
(c) Indexed addressing .code
main PROC
mov eax,0 Base
mov ecx,4
L1:
mov bx, array2[eax]
add eax,2
call dumpregs
LOOP L1
exit Displacement
mov bx,[array2+eax] main ENDP
Add eax,2
82
m @ Feb 2019 41
SCSR2033 - Computer Architecture and Organization
.data
array1 byte 10h,11h,12h,13h 4
array2 word 123h,234h,345h,456h
array3 dword 123456h, 23456789h
.code
main PROC
eax = 00000000h mov eax,0
ecx = 00000004h mov ecx,4
L1:
bx = __________h mov bx, array2[eax]
eax = 00000002h add eax,2
call dumpregs
ecx = 00000003h LOOP L1
exit mov bx,[array2+eax]
main ENDP
[00404008+00000000]
dec ecx à array2[00404008]
83
.data
array1 byte 10h,11h,12h,13h 4
array2 word 123h,234h,345h,456h
array3 dword 123456h, 23456789h
2nd looping
.code
main PROC
mov eax,0
mov ecx,4
L1:
bx = __________h mov bx, array2[eax]
eax = 00000002h
00000004h add eax,2
call dumpregs
ecx = 00000003h
00000002h LOOP L1
exit mov bx,[array2+eax]
main ENDP
[00404008+00000002]
dec ecx à array2[0040400A]
84
m @ Feb 2019 42
SCSR2033 - Computer Architecture and Organization
.data
array1 byte 10h,11h,12h,13h 4
array2 word 123h,234h,345h,456h
array3 dword 123456h, 23456789h
3rd looping
.code
main PROC
mov eax,0
mov ecx,4
L1:
bx = __________h mov bx, array2[eax]
00000004h
eax = 00000006h add eax,2
call dumpregs
ecx = 00000002h
00000001h LOOP L1
exit mov bx,[array2+eax]
main ENDP
[00404008+00000004]
dec ecx à array2[0040400C]
85
.data
array1 byte 10h,11h,12h,13h 4
array2 word 123h,234h,345h,456h
array3 dword 123456h, 23456789h
4th looping
.code
main PROC
Exit looping
mov eax,0
mov ecx,4
L1:
bx = __________h mov bx, array2[eax]
eax = 00000006h
00000008h add eax,2
call dumpregs
ecx = 00000001h
00000000h LOOP L1
exit mov bx,[array2+eax]
main ENDP
[00404008+00000006]
dec ecx à array2[0040400E]
86
m @ Feb 2019 43
SCSR2033 - Computer Architecture and Organization
Module 4
Instruction Set Architecture
(ISA)
4.1 Introduction
4.2 Machine Instruction q Overview
Characteristics
q Instruction Length
4.3 Types of Operands
4.4 Addressing Modes q Allocation Bits
m @ Feb 2019 44
SCSR2033 - Computer Architecture and Organization
4
Overview
William Stallings (2016). Computer Organization and Architecture: Designing for Performance (10th Edition). United States: Pearson Education Limited, p.469. 89
4
n Four common instruction formats:
90
m @ Feb 2019 45
SCSR2033 - Computer Architecture and Organization
4
Instruction Length
4
Allocation of Bits
William Stallings (2016). Computer Organization and Architecture: Designing for Performance (10th Edition). United States: Pearson Education Limited, p.470. 92
m @ Feb 2019 46
SCSR2033 - Computer Architecture and Organization
4
n The following interrelated factors go into determining the use of
the addressing bits:
William Stallings (2016). Computer Organization and Architecture: Designing for Performance (10th Edition). United States: Pearson Education Limited, p.470. 93
4
q Number of register sets – have one set of general purpose
registers with 32 or more registers in the set – for example
sets of 8 registers only 3 bits are needed to identify the
registers, opcode will implicitly determine which register set
is being referenced.
q Address range – the range of addresses that can be
referenced related to the number of bits.
q Address granularity – an address can reference a word or
byte a the designer s choice – byte addressing is
convenient for character manipulation.
William Stallings (2016). Computer Organization and Architecture: Designing for Performance (10th Edition). United States: Pearson Education Limited, p.471. 94
m @ Feb 2019 47
SCSR2033 - Computer Architecture and Organization
4
Variable-Length Instructions
William Stallings (2016). Computer Organization and Architecture: Designing for Performance (10th Edition). United States: Pearson Education Limited, p.473. 95
4.6 Summary 4
William Stallings (2016). Computer Organization and Architecture: Designing for Performance (10th Edition). United States: Pearson Education Limited, p.413, 457. 96
m @ Feb 2019 48
SCSR2033 - Computer Architecture and Organization
Review Questions 4
4.3 List and briefly explain five important instruction set design
issues.
William Stallings (2013). Computer Organization and Architecture: Designing for Performance (9th Edition). United States: Pearson Education Limited, p.463. 97
Review Questions 4
William Stallings (2013). Computer Organization and Architecture: Designing for Performance (9th Edition). United States: Pearson Education Limited, p.501. 98
m @ Feb 2019 49