Professional Documents
Culture Documents
●
8-bit processors in late 1970s
➔
4 registers for integer data: A, B, C, D
➔
4 registers for address/pointers: SP(stack pointer), BP(base pointer),
SI(source index), DI(dest. index)
●
16-bit processors extended registers to 16-bits but continued
to support 8-bit access
➔
Use prefix/suffix to indicate size: AL referenced the lower 8-bits of
register A, AH referenced the high 8-bits, AX referenced the full 16-
bit value
●
32-/64-bit processors (see next slide)
Intel x86 Register Set
Protected mode: Descriptors
Program Invisible Registers
Intel x86 Adressing Modes
Intel x86 Adressing Modes
●
Register Mode
Specifies the contents of a register as the operand
●
Immediate Mode
Specifies the a constant stored in the instruction as the operand
Immediate can be specified in hex or decimal
●
Direct Addressing Mode
Specifies a constant memory address where the true operand is located
Address can be specified in decimal or hex
●
Indirect Addressing Mode
Specifies a register whose value will be used as the effective address in
memory where the true operand is located
Similar to dereferencing a pointer
Parentheses indicate indirect addressing mode
Intel x86 Adressing Modes
●
Base/Indirect with Displacement Addressing Mode
Form: d(%reg)
Adds a constant displacement to the value in a register and uses the sum
as the effective address of the actual operand in memory
●
Scaled Index Addressing Mode
Form: (%reg1,%reg2,s) [s = 1, 2, 4, or 8]
Uses the result of %reg1 + %reg2*s as the effective address of the actual
operand in memory
Instruction Limits on Addressing Modes
●
Primary restriction is both operands cannot be memory locations
➔
mov 2000, (%eax) is not allowed since both source and destination are in memory
➔
To move mem -> mem use two move instructions with a register as the intermediate
storage location
●
Legal move combinations:
Imm -> Reg
Imm -> Mem
Reg -> Reg
Mem -> Reg
Reg -> Mem
Intel x86 Instruction Classes
● Data Transfer (movinstruction)
➔ Moves data between processor & memory (loads and saves variables between processor
and memory)
➔ One operand must be a processor register (can't move data from one memory location to
another)
➔ Specifies size via a suffix on the instruction (movb, movw, movl, movq)
● String Operations
➔ Every string instruction is tied to compulsory conventions use of index registers and the
.data
count BYTE 100
wVal WORD 2
.code
mov bl,count
mov ax,wVal
V l
mov count,al
.data
d
signedVal SWORD -16 ; FFF0h
.code
code
mov ecx, 0 ; mov ecx, 0FFFFFFFFh
mov cx,
cx signedVal
mov bl,10001111b
movzx ax,bl ; zero-extension
The
h destination
d must be
b a register.
Sign extension
The MOVSX instruction fills the upper half of the destination
with a copy of the source operand
operand'ss sign bit
bit.
10001111 Source
mov bl,10001111b
movsx ax,bl ; sign extension
.data
saveflags
fl BYTE ?
.code
lahf
mov saveflags, ah
...
mov ah,
h saveflags
fl
sahf
xchg
g var1,var2 ; error 2 memory
y operands
p
Exchange two memory locations
.data
var1
1 WORD 1000h
var2 WORD 2000h
.code
mov ax, val1
xchg ax, val2
mov val1, ax
Stack Operations
A stack is a region of memory used for temporary storage of information.
The last value placed on the stack is the 1st to be taken off. This is called
LIFO (Last In, First Out) queue. Values placed on the stack are stored
from the highest memory location down to the lowest memory location.
Addressing Modes: src & dst should be Words and cannot be immediate.
dst cannot be the ip or cs Register.
Stack Operations
push — Push on stack
The push instruction places its operand onto the top of the hardware supported stack in memory.
Specifically, push first decrements ESP by 4, then places its operand into the contents of the 32-bit location
at address (%esp). ESP (the stack pointer) is decremented by push since the x86 stack grows down — i.e.
the stack grows from high addresses to lower addresses.
Syntax
push <reg32>
push <mem>
push <con32>
Examples
push eax — push eax on the stack
push var — push the 4 bytes at address var onto the stack
The every instruction can use one prefix to repeat itself (while condition
is met):
LODSB/W/D
This instruction load one element from source into accumulator (AL, AX, EAX).
STOSB/W/D
This instruction stores content of accumulator (AL, AX, EAX) into destination.
The prefix can be used to fill a block of memory.
SCASB/W/D
This instruction compares content of accumulator (AL, AX, EAX) with
destination: null=accumulator-ES:[EDI]. The prefix can be used to search the
required value or the first difference.
String Instructions
CMPSB/W/D
This instruction compares source and destination: null=ES:[ESI]-DS:[EDI].
The prefix can be used to search consensus or difference of strings or blocks of
memory.
INSB/W/D
Instruction read data from port at address specified by DX into destination.
OUTSB/W/D
Instruction stores one element from source to port at address specified by DX.
Example: String Instructions
Example: String Instructions