Download Instruction Encoding

Survey
yes no Was this document useful for you?
   Thank you for your participation!

* Your assessment is very important for improving the work of artificial intelligence, which forms the content of this project

Document related concepts
no text concepts found
Transcript
Instruction Encoding
• Thorne : Chapter 13.2,
13 2 Appendix V.B
VB
• Additional notes in : Instruction Encodingg Note
SYSC3006
1
Instruction Encoding
On the Intel 8086, an instruction is a sequence of 1..6 bytes
• A simple (and incomplete) model of an instruction is as follows
:
Byte 1
Byte 2
Byte 3
Byte 4
Byte 5
Byte 6
Opcode
Operand
Operand
Operand
Operand
Operand
Tells what kind of Destination Operand, if needed Source if needed
i
instruction,
i
How many bytes…
SYSC3006
2
Number of Bytes Depends on … Number of Operands
NOP
1001 0000
0100 0001
INC BX (Thorne, p 668)
ADD BX, 1 (Thorne, p 667) 1000 0011
1100 0011
0000 0001
…
0000 0000
Immediate value: a word (little endian)
SYSC3006
3
Number of Bytes Depends on … Addressing Modes
ADD BX, AX
ADD BX, 1
ADD BL, 1
ADD BX, [1]
ADD BL, [1]
00000001
BX | AX
11000011
10000001
Register
11000011
Immediate
00000001 00000000
10000000
Register
11000011
Immediate
00000001
00000011
Register
00011110
Direct
00000001 00000000
00000010
Register
00011110
Direct
00000001 00000000
SYSC3006
4
Review Earlier Slides on Addressing Modes
1) Register mode : operand is a register
2) Immediate mode : operand is a constant
– Constant value is encoding as part of instruction
• value is hard-coded (static)
– Constant
C t t value
l is
i loaded
l d d into
i t IR during
d i fetch
f t h
– Constant value obtained from IR during execution
3) Direct memory mode : operand is address offset of memory
variable
– Constant address offset is encoded as part of instruction
• Address offset is hard-coded ((static)) although
g contents
of address may be dynamic
• During execution, the address offset is implicitly
combined with DS
SYSC3006
5
Indirect Addressing Modes
Number of Bytes Depends on … Addressing Modes
Assume : WORD PTR
ADD [BX], 1
ADD [BX+2], 1
ADD [BX+SI], 1
10000001
Indirect
00000111
Immediate
00000001 00000000
Constant
00000010
Immediate
10000001
Based
01000111
10000001
Immediate
Base Index
Base-Index
00000000 00000001 00000000
00000001
00000000
ADD [BX+SI+2], 1
Base-Index with Constant
10000001 01000000 00000010
SYSC3006
Immediate
00000001
00000000
6
Review Earlier Slides on Addressing Modes
1) Indirect : Operand is an address offset held in a register
[BX+2] 2) Based or Indexed Indirect : Operand is an address offset
held in a register and a constant offset
• During fetch, constant offset is read in as part of
instruction
• During execution,
execution CPU uses temporary register to
calculate BX + constant
• It then accesses memory addressed by BX + constant
[BX SI] 3) Base-Index
[BX+SI]
B
I d : Operand
O
d iis an address
dd
offset
ff t held
h ld in
i two
t register
it
– During execution, CPU calculates sum of 2 registers
– It then accesses memory addressed by sum
[BX+SI+2] 4) Base-Index with Displacement : Like based-indexed mode,
except includes a constant too
– Duringg execution,, CPU calculates sum of 3 values
– It then accesses memory addressed by sum
[BX]
SYSC3006
7
Instruction Encoding : J*
J
• On all jump instructions, the target must supply a value that
will be used to modify the IP
1 Absolute addressing (Assembly code): The instruction
1.
contains a 16-bit constant value to replace the IP
Execution Semantics: IP := new value
2 Relative
2.
R l ti addressing
dd
i (Machine
(M hi code):
d ) : The
Th instruction
i t ti
contains a value to be added to IP (after the fetch!)
Execution Semantics :
IP := IP + value
If the value is positive, the jump is “forward”
If the value is negative, the jump is “negative”
3. Register/memory
g
y indirect addressing:
g The instruction
specifies a register or memory location that contains the value
to be used to replace IP
Execution Semantics :
IP := mem[addrs]
[
]
IP := register
SYSC3006
8
Specifying Control Flow Targets (Intra-segment)
Question : What addressing modes is used below ?
JMP
1000h
JMP
here
SYSC3006
9
JMP target
Unconditional JUMP
• Control is always transferred to specified (relative) target.
Relative Addressing Example: .LST file fragment
address
machine instruction
ASM instruction
(memory contents)
0034H
E9 10 02 Relative
JMP here = JMP 247
addressing
Absolute
0037H
….
….
addressing
….
….
….
0247
here:
start of fetch:
after fetch:
after execute:
IP = 0034H
IP = 0037H
IP = 0247H
IR = ???????? (Little endian=0210h)
IR = E9 10 02
IR = E9 10 02
SYSC3006
10