Title: Intel
1Intels 8086 instruction-set
- A look at the main categories of processor
instructions for the earliest Intel x86 CPU
2Data-Transfer
- These instructions simply copy some data from one
place in the system to another - From one register to another register
- From a memory location to a register
- From a register to a memory location
- From within an instruction to a register
- From within an instruction to a memory cell
3mov
- Its the most frequently-used instruction
immediate data
general register
general register or memory
segment register
4Some other data-transfers
- Exchange (xchg)
- Push/Pop
- Pushf/Popf
- In/Out
- Load pointer (lds, les, lfs, lgs, lss)
- Note A distinctive feature data-transfers is
that FLAGS are unmodified (except popf)
5Arithmetic Instructions
- Addition add and adc
- Subtraction sub and sbb
- Multiplication mul and imul
- Division div and idiv
- Increment/Decrement inc and dec
- Comparison/Negation cmp and neg
- All these instructions do modify FLAGS
6Boolean Logic Instructions
- Bitwise AND and
- Bitwise OR or
- Bitwise XOR xor
- Bitwise TEST test
- Bitwise complement not
- These instructions also modify FLAGS
7Shift/Rotate Instructions
- Left-shifts shl and sal
- Right-shifts shr and sar
- Left-rotations rol and rcl
- Right-rotations ror and rcr
- These instructions affect the Carry-Flag
8Control Transfers
- These instructions modify register RIP so as to
alter the normal fetch-execute cycle - Unconditional Jumps jmp and ljmp
- Subroutine Calls call and lcall
- Subroutine Returns ret and lret
- Conditional Jumps jz, jnz, jc, jnc, etc
- These transfers do not modify the FLAGS
9String Manipulations
- This unusual group of complex instructions is for
efficient word-processing operations - Move string movs
- Compare string cmps
- Scan string scas
- Store string stos
- Load string lods
- Repeat prefixes rep, repe and repne
10Processor Control
- This group of instructions is for specialized
systems programming situations - Halt the fetch-ececute cycle hlt
- Wait for coprocessor to finish wait
- Lock the system bus temporarily lock
- Adjust the Direction Flag cld or std
- Adjust the Interrupt Flag cli or sti
- Adjust the Carry Flag cmc, clc or stc
11Special-purpose instruction
initializations
the loop body
This two-step construct occurs so often within
ordinary programs that a special instruction
is available to do both in a single
instruction
decrement RCX
RCX 0?
no
yes
12Stack operation push
register
data
64-bits
64-bits
data
data
data
data
data
data
SSRSP
data
unused
SSRSP
unused
unused
unused
unused
before push
after push
The push instruction, applied to a register,
performs a two-step operation first, the value
in the stack-pointer register is decreased by 8,
and then the value in the register operand is
copied into the stack-location at SSRSP
13Stack operation pop
register
64-bits
64-bits
data
data
data
data
data
data
SSRSP
unused
data
SSRSP
unused
unused
unused
unused
before pop
after pop
The pop instruction, applied to a register,
performs a two-step operation first, the value
in the stack-location at SSRSP is copied into
that register, and afterward the value in the
stack-pointer register is increased by 8.
14An application
- We can apply these stack-operations to a string
of characters in a memory-buffer, so as to
reverse the order of those characters
stack
A B C D
RSP
buffer
buffer
A B C D
D C B A
pop
pop
pop
pop
push
push
push
push
15reverse.s
- Weve constructed a demo-program that reverses
the order of characters which a user types in - It uses the push and pop operations, as well
as the special x86 loop instruction - It also employs the read system-call to get a
string of characters typed by a user
16The programs flow
Prompt the user for input
INPUT
Accept the users response
Loop to push each buffer character onto stack
PROCESS
Loop to pop each character to output buffer
Show rearranged characters in output buffer
OUTPUT
17Loops are consecutive
18Loops are nested
19In-class exercise
- Can you modify the reverse.s program so all
words remain in the same order, but the order of
the letters within each word do get reversed? - HINT You will need a loop-within-a-loop
This is our moment, this is our time.
INPUT
sihT si rou themom, siht si rou emit.
OUTPUT