Intels 8086 instructionset A look at the main
- Slides: 19
Intel’s 8086 instruction-set A look at the main categories of processor instructions for the earliest Intel x 86 CPU
Data-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
‘mov’ • It’s the most frequently-used instruction immediate data general register or memory general register segment register
Some 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’)
Arithmetic 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
Boolean Logic Instructions • • • Bitwise AND: ‘and’ Bitwise OR: ‘or’ Bitwise XOR: ‘xor’ Bitwise TEST: ‘test’ Bitwise complement: ‘not’ • These instructions also modify FLAGS
Shift/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
Control 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
String 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’
Processor 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’
Special-purpose instruction initializations the loop body decrement RCX no RCX == 0? yes This two-step construct occurs so often within ordinary programs that a special instruction is available to do both in a single instruction
Stack operation: ‘push’ register data SS: RSP 64 -bits data data unused unused before ‘push’’ SS: RSP 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 SS: RSP
Stack operation: ‘pop’ register 64 -bits data data SS: RSP data 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 SS: RSP is copied into that register, and afterward the value in the stack-pointer register is increased by 8.
An 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 RSP buffer A B C D push A B C D buffer D C B A pop push pop pop
‘reverse. s’ • We’ve 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 x 86 ‘loop’ instruction • It also employs the ‘read’ system-call to get a string of characters typed by a user
The program’s flow Prompt the user for input INPUT Accept the user’s 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
Loops are ‘consecutive’
Loops are ‘nested’
In-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? INPUT This is our moment, this is our time. OUTPUT sih. T si rou themom, siht si rou emit. • HINT: You will need a loop-within-a-loop
- Look up, look down, look all around
- Look at activity 1 and write
- Look at the picture in activity
- Picture analysis activity 1
- Void main int main
- The will future
- Tells more about the main idea
- Khi nào hổ con có thể sống độc lập
- Thiếu nhi thế giới liên hoan
- Chúa sống lại
- điện thế nghỉ
- Một số thể thơ truyền thống
- Trời xanh đây là của chúng ta thể thơ
- Số nguyên tố là
- đặc điểm cơ thể của người tối cổ
- Tỉ lệ cơ thể trẻ em
- Vẽ hình chiếu vuông góc của vật thể sau
- Các châu lục và đại dương trên thế giới
- Thế nào là hệ số cao nhất
- Hệ hô hấp