1 / 26

8086/88 Instructions set

8086/88 Instructions set. 8086/88 Instruction Type Classifications. DATA TRANSFER General mov ax, [3000] ;ax gets contents of mem ARITHMETIC/LOGIC Arithmetic add ax, bx ;ax gets ax+bx Logical and ax, bx ;ax gets ax AND bx

Download Presentation

8086/88 Instructions set

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. 8086/88 Instructions set

  2. 8086/88 Instruction Type Classifications • DATA TRANSFER • General mov ax, [3000] ;ax gets contents of mem • ARITHMETIC/LOGIC • Arithmetic add ax, bx ;ax gets ax+bx • Logical and ax, bx ;ax gets ax AND bx • Shifting shr ax, 2 ;ax contents shifted-2 right • CONTROL TRANSFER • Conditional Jump jnz 2000 ;if ZF=0 then IP=2000 • Unconditional Jump JMP 4500 ; IP = 4500 • Subroutine call 3500 ;IP=3500 • iteration loop 4000

  3. Data Transfer Instructions • Very Common Instruction: movdesti, source • Allowed Operands Destination Source Memory Accumulator Accumulator Memory Register Register Register Memory Memory Register Register Immediate Memory Immediate Seg. Reg. Register Seg. Reg. Memory Register Seg. Reg. Memory Seg. Reg.

  4. Arithmetic/Logic Instructions

  5. Arithmetic Instruction Summary add ax, bx ;axax+bx and set flags adc ax, bx ;axax+bx+CF(lsb) and set flags inc ax ;axax+1 and set flags daa ;Decimal (BCD) Adjust after Addition sub ax, bx ;axax-bx and set flags sbb ax, bx ;ax(ax-CF)-bx and set flags dec ax ;axax-1 neg ax ;ax(-1)*(ax) -- 2’s Complement cmp ax, bx ;Flags are set according to ax-bx das ;Decimal(BCD)Adjust after Subtraction mulcx ;dx:ax ax * cx (unsigned) imulcx ;dx:ax ax * cx (2’s complement) divcl ;alax/cl Quot. AND ahax/cl Rem. idivcx ;ax(dx:ax)/cx Quot. AND dx Rem.

  6. Example for Add with Carry BX AX 1 1 DX CX 0 1 CF=1 CF BX AX add ax, cx ;axax+cx and flags set adc bx, dx ;bxbx+dx+CF(lsb) and flags set 33-bit Sum Present in CF:bx:ax

  7. Decimal Adjust after Addition • For BCD Arithmetic • “Corrects” Result • 0110 6 • +01117 • 1101 13should be 0001 0011 • (1101 is illegal BCD) • Follows add,adcto “Adjust”

  8. Decimal Adjust after Addition Example movdx, 1234h ;dx1234 BCD movbx, 3099h ;bx3099 BCD mov al, bl ;al99 BCD add al, dl ;alcdh illegal BCD, need 34+99=133 daa ;al33h (33 BCD) and CF=1 movcl, al ;cl33 BCD mov al, bh ;al30 BCD adc al, dh ;al30h+12h+1=43h daa ;al43h (43 BCD) not illegal BCD this time movch, al ;cx=4333h BCD for 1234+3099

  9. Allowable Operands for add, sub Gen Reg + - Gen Reg Mem Loc Immediate Destination Source Gen Reg + - Mem Loc Immediate

  10. Subtract with Borrow, sbb CF BX AX SI DI CF BX AX sub ax, di ;axax-di and CF gets borrow bit sbbbx, si ;bx(bx-CF(lsb))-si and flags set 32-bit Difference Present inbx:ax CF Indicates If Difference is Negative

  11. Logical Instructions

  12. Logic Instruction Types BITWISE LOGICAL not ax ;1’s Complement-Logical Invert and ax, bx ;Bitwise logical and operation or ax, bx ;Bitwise logical inclusive-or operation xor ax, bx ;Bitwise logical exclusive-or operation test ax, fffh;Bitwise and but result discarded SHIFT shl ax, 4 ;Logical shift left sal ax, 3 ;Arithmetic shift left shr ax, 4 ;Logical shift right sar ax, 3 ;Arithmetic shift right ROTATE rolbx, 3 ;Rotate left rorcx, 4 ;Rotate right rcl ax, 1 ;Rotate left through carry rcrdx, 6 ;Rotate right through carry

  13. Logic Instruction Application (Masking Operations) XXXX XXXX (unknown byte) (AND) 0000 1111 (mask byte) 0000 XXXX (result) What if we wanted 1111 XXXX instead? EXAMPLE: Convert ASCII to BCD ; change 3235h into 0025h movbx, 3235h ;bx ‘25’ and bx, 0f0fh ;bx0205h shlbh, 4 ;bh20hor bl, bh ; bl = bh or bl = 20 or 05 = 25h xorbh, bh ;zero out bh, so bx = 0025 (BCD value)

  14. Bit Test Instruction, test • Same as and But Result is Discarded • Only Affects Flags • ZF=1 if Tested Bit=0 and ZF=0 if Tested Bit=1 • Example: • test al, 1 ;XXXX XXXX (AND) 0000 0001 • test al, 128 ;XXXX XXXX (AND) 1000 0000

  15. CF REG 0 0 REG CF CF REG 0 REG CF Shifts shl - Logical Shift Left shr - Logical Shift Right sal - Arithmetic Shift Left (same as logical) sar - Arithmetic Shift Right (sign bit is preserved) MSB

  16. Simple Arithmetic Using Shifts ;Compute (-3)*VALUE Using Only Shifts and Adds mov ax, VALUE ;ax  Word from memory with label VALUE movbx, ax ;bx Word from memory with label VALUE shl ax, 2 ;ax  4*VALUE add ax, bx ;ax  5*VALUE shlbx, 3 ;bx 8*VALUE sub ax, bx ;ax  (-3)*VALUE

  17. Rotates rol - Rotate Left CF REG rcl - Rotate Through Carry Left CF REG ror - Rotate Right CF REG rcr - Rotate Through Carry Right CF REG

  18. Example Using Rotates ;Multiply a 48-bit value in dx:bx:ax by 2 shl ax, 1 ;ax  2*ax rclbx, 1 ;bx 2*bx + CF(lsb) rcldx, 1 ;dx 2*dx + CF(lsb) ;End result is dx:bx:ax 2*(dx:bx:ax) • Operand for rotates and shifts can be either: • 1) Immediate value ( for example: shl ax, 3) • 2) Quantity in cl (for example: movcl, 3 • Shl ax, cl )

  19. Program Control Instructions

  20. Program Control Instructions • Generally modify CS:IP • Causes modification in execution sequence (of instructions) • Classification • a) Jumps - Unconditional control transfers • b) Conditional Jump- Conditional control transfer • c) Iteration - More complex type of branch • d) Call Subroutine and RET (Return from Subroutine)

  21. Branches or conditional Jumps jc LABEL ;jump on carry (CF=1)jnc LABEL ;jump on no carry (CF=0) je/jz LABEL ;jump if ZF=1 - jump if equal/zero jne/jnz LABEL ;jump if ZF=0 - jump not equal/jump if zerojo LABEL ;jump if OF=1 - jump on overflow jno LABEL ;jump if OF=0 - jump if no overflowjs LABEL ;jump on sign flag set (SF=1) jns LABEL ;jump if no sign flag (SF=0) jp/jpe LABEL ;jump if PF=1 - jump on parity/parity even jnp/jpo LABEL ;jump if PF=0 - jump on no parity/parity odd

  22. Procedures • Group of instructions that perform single task • (can be used as) a SUBROUTINE • Uses MASM directives: PROC and ENDP • Must specify • FAR - intrasegment • NEAR - intersegment

  23. call Instruction • NEAR call: 3 bytes - 1 opcode and 2 for IP • FAR call: 5 bytes - 1 opcode, 2 for IP and 2 for CS ret Instruction • NEAR - pops 16-bit value places in IP • FAR - pops 32-bit value places in CS:IP

  24. String Transfer Instructions • movsb ;Copies 8 bits at DS:SI to ES:DI and • ; Inc/Dec SI and DI by 1 • ; depending on DF • movsw ;Copies 16 bits at DS:SI and DS :SI+1 to ES:DI • ;and ES:DI+1 and • ; Inc/Dec SI and DI by 2 depending • ; on DF

  25. Other String Instructions lodsb ;loads al with contents of ds:si ;Inc/Dec si by 1 depending on DF lodsw ;loads ax with ds:si ;Inc/Dec si by 2 depending on DF stosb ;loads es:di with contents of al ;Inc/Dec di by 1 depending on DF stosw ;loads es:di with contents of ax ;Inc/Dec di by 2 depending on DF

  26. Home work • فصل 2 کتاب مزیدی: برنامه نویسی به زبان اسمبلی • تمرینات: 11-12-13 • فصل 3 کتاب مزیدی: دستورات محاسباتی، منطقی و برنامه ها • تمرینات: 1-2-4-6-7-9-10-20-21 • مهلت تحویل: 3 هفته

More Related