AngoLinux

80386 Programmer's Reference Manual -- Opcode SUB


SUB -- Integer Subtraction

OpcodeInstructionClocks DescriptionExample
2C ibsubb imm8,al2 Subtract immediate byte from ALsubb $0x7f,%al
2D iwsubw imm16,ax2 Subtract immediate word from AXsubw $0x7fff,%ax
2D idsubl imm32,eax2 Subtract immediate dword from EAXsubl $0x7fffffff,%eax
80 /5 ibsubb imm8,r/m82/7 Subtract immediate byte from r/m bytesubb $0x7f,%dl
subb $0x7f,(%ebx,1)
subb $0x7f,m8(%ebx,1)
subb $0x7f,m8(%ebx,%ebp,1)
81 /5 iwsubw imm16,r/m162/7 Subtract immediate word from r/m wordsubw $0x7fff,%cx
subw $0x7fff,(%ebx,1)
subw $0x7fff,(%ebx,2)
subw $0x7fff,(%ebx,%ebp,1)
81 /5 idsubl imm32,r/m322/7 Subtract immediate dword from r/m dwordsubl $0x7fffffff,%ecx
subl $0x7fffffff,(%ebx,2)
subl $0x7fffffff,(%ebx,4)
subl $0x7fffffff,(%ebx,%ebp,1)
83 /5 ibsubw imm8,r/m162/7 Subtract sign-extended immediate byte from r/m wordsubw $0x7f,%cx
subw $0x7f,(%ebx,1)
subw $0x7f,(%ebx,2)
subw $0x7f,(%ebx,%ebp,1)
83 /5 ibsubl imm8,r/m322/7 Subtract sign-extended immediate byte from r/m dwordsubl $0x7f,%ecx
subl $0x7f,(%ebx,2)
subl $0x7f,(%ebx,4)
subl $0x7f,(%ebx,%ebp,1)
28 /rsubb r8,r/m82/6 Subtract byte register from r/m bytesubb %bh,%dl
subb %bh,(%ebx,1)
subb %bh,m8(%ebx,1)
subb %bh,m8(%ebx,%ebp,1)
29 /rsubw r16,r/m162/6 Subtract word register from r/m wordsubw %bx,%cx
subw %bx,(%ebx,1)
subw %bx,(%ebx,2)
subw %bx,(%ebx,%ebp,1)
29 /rsubl r32,r/m322/6 Subtract dword register from r/m dwordsubl %ebx,%ecx
subl %ebx,(%ebx,2)
subl %ebx,(%ebx,4)
subl %ebx,(%ebx,%ebp,1)
2A /rsubb r/m8,r82/7 Subtract byte register from r/m bytesubb %dl,%bh
subb (%ebx,1),%bh
subb m8(%ebx,1),%bh
subb m8(%ebx,%ebp,1),%bh
2B /rsubw r/m16,r162/7 Subtract word register from r/m wordsubw %cx,%bx
subw (%ebx,1),%bx
subw (%ebx,2),%bx
subw (%ebx,%ebp,1),%bx
2B /rsubl r/m32,r322/7 Subtract dword register from r/m dwordsubl %ecx,%ebx
subl (%ebx,2),%ebx
subl (%ebx,4),%ebx
subl (%ebx,%ebp,1),%ebx

Operation




IF SRC is a byte and DEST is a word or dword
THEN DEST := DEST - SignExtend(SRC);
ELSE DEST := DEST - SRC;
FI;

Description

SUB subtracts the second operand (SRC) from the first operand (DEST). The first operand is assigned the result of the subtraction, and the flags are set accordingly.

When an immediate byte value is subtracted from a word operand, the immediate value is first sign-extended to the size of the destination operand.

Flags Affected

OF, SF, ZF, AF, PF, and CF as described in Appendix C

Protected Mode Exceptions

#GP(0) if the result is in a nonwritable segment; #GP(0) for an illegal memory operand effective address in the CS, DS, ES, FS, or GS segments; #SS(0) for an illegal address in the SS segment; #PF(fault-code) for a page fault

Real Address Mode Exceptions

Interrupt 13 if any part of the operand would lie outside of the effective address space from 0 to 0FFFFH

Virtual 8086 Mode Exceptions

Same exceptions as in Real Address Mode; #PF(fault-code) for a page fault


[Home Page dell'ITIS "Fermi"] [80386 Programmer's Reference Manual Index] [Previous] [Next]