Lecture 7
Lecture 7
Lecture 7
Instruction Sets
Part I: Instruction Formats & Instruction
Types
1
In this lecture:
Introduction
Instruction Format
Instruction Types
2
Introduction
Instructions
Specify operations to be performed by a computer
Words of a computers language
Instruction set
Collection of the instructions of a computer
Vocabulary of a computers language
Elements of an instruction
3
Introductioncntd
Addresses (operands)
Provide more information about the operation
May include:
Source operands: specify where operands come from
Destination operands: specify where results go
Next instruction reference: specifies where to fetch next instruction from
4
Introductioncntd
void main()
{ Compiler Assembler
main: 0567
int a,b,c;
ADD c,a,b
c = a+b;
}
5
Introductioncntd
We will discuss:
Instruction Formats: How long is an instruction? How many
operands?
Instruction Types: What kind of operations?
Data Types: What kind of operands?
Addressing Modes: Where are the operands?
6
Instruction Format
Common formats:
Opcode Opcode Address
(zero operand ) (one operand )
7
Instruction Formatcntd
Instruction length
How many bits for an instruction?
Affects and affected by:
Number of operations
Memory size
Memory organization
Bus structure
Processor complexity (e.g. number of registers)
8
X86 Instruction formats
8 8
Opcode Address e.g. JE address
8 16
Opcode Address e.g. JMP address
8 8 16
Opcode reg Immediate e.g. ADD reg, 500
9
Instruction Types
Common types:
Data transfer(Data movement)
Arithmetic
Logical
Input/output
Transfer of control(Program flow control)
System control
10
Data Transfer
11
Data Transfercntd
PUSH source
Used to transfer data to stack
Source: can be register or memory location
12
Data Transfercntd
POP destination
Used to retrieve data from stack
Destination: can be register or memory location
13
Arithmetic
CPU CPU
BX 96 BX 96
CX 96 CX 192
14
Arithmeticcntd
DEC destination
Destination: can be register or memory location
CPU CPU
CX 192 CX 191
15
Arithmeticcntd
MUL source
Source: can be register or memory location
Destination is an accumulator register, AX
e.g. MUL BL (AXAL x BL)
CPU
BX 96
0 96 CPU
AX 960(03C0H)
AX 10
03H C0H
0 10
16
Logical
CPU CPU
BX 96 (60H) BX 96(60H)
CX 191(BFH) CX 32(20H)
17
Input/output
18
Transfer of control
19
Transfer of controlcntd
21
Transfer of controlcntd
CX=CX-32;
e.g. SUB CX, 32
goto label;
Jmp label
label:
BX=10;
label:
MOV BX, 10
22
Transfer of controlcntd
Procedure:
Small, self-contained program within a larger program
(like function in high-level languages)
Allows same piece of code to be used many times
e.g. CALL subroutine ..RET
23
Transfer of controlcntd
CX=CX-32;
e.g. SUB CX, 32 Sub();
CALL sub
Void sub()
sub: {
BX=10;
MOV BX, 10 }
RET
24
Transfer of controlcntd
CPU Memory CPU Memory
BX 96 200 SUB CX,32 BX 96 200 SUB CX,32
CX 32 201 CALL 204 CX 0 201 CALL 204
202 202
PC (IP) 200 203 PC (IP) 201
203
204 MOV BX,10 204 MOV BX,10
205 RET 205 RET
CPU Memory CPU Memory
BX 96 200 SUB CX,32 BX 10 200 SUB CX,32
CX 0 201 CALL 204 CX 0 201 CALL 204
202 202
PC (IP) 204 203 PC (IP) 205
203
204 MOV BX,10 204 MOV BX,10
205 RET 205 RET
25
Transfer of controlcntd
CPU Memory
BX 10 200 SUB CX,32
CX 0 201 CALL sub
202
PC (IP) 202 203
204 MOV BX,10
205 RET
26
More Readings
27