home *** CD-ROM | disk | FTP | other *** search
/ CD-X 1 / cdx_01.iso / demodisc / tyrant / docs / 386code / instruct.386 < prev    next >
Encoding:
Text File  |  1994-01-20  |  241.4 KB  |  7,213 lines

  1. AAA ── ASCII Adjust after Addition
  2.  
  3. Opcode    Instruction    Clocks    Description
  4.  
  5. 37        AAA            4         ASCII adjust AL after addition
  6.  
  7.  
  8. Operation
  9.  
  10. IF ((AL AND 0FH) > 9) OR (AF = 1)
  11. THEN
  12.    AL  (AL + 6) AND 0FH;
  13.    AH  AH + 1;
  14.    AF  1;
  15.    CF  1;
  16. ELSE
  17.    CF  0;
  18.    AF  0;
  19. FI;
  20.  
  21. Description
  22.  
  23. Execute AAA only following an ADD instruction that leaves a byte result
  24. in the AL register. The lower nibbles of the operands of the ADD instruction
  25. should be in the range 0 through 9 (BCD digits). In this case, AAA adjusts
  26. AL to contain the correct decimal digit result. If the addition produced a
  27. decimal carry, the AH register is incremented, and the carry and auxiliary
  28. carry flags are set to 1. If there was no decimal carry, the carry and
  29. auxiliary flags are set to 0 and AH is unchanged. In either case, AL is left
  30. with its top nibble set to 0. To convert AL to an ASCII result, follow the
  31. AAA instruction with OR AL, 30H.
  32.  
  33. Flags Affected
  34.  
  35. AF and CF as described above; OF, SF, ZF, and PF are undefined
  36.  
  37. Protected Mode Exceptions
  38.  
  39. None
  40.  
  41. Real Address Mode Exceptions
  42.  
  43. None
  44.  
  45. Virtual 8086 Mode Exceptions
  46.  
  47. None
  48.  
  49.  
  50. AAD ── ASCII Adjust AX before Division
  51.  
  52. Opcode    Instruction    Clocks    Description
  53.  
  54. D5 0A     AAD            19        ASCII adjust AX before division
  55.  
  56.  
  57. Operation
  58.  
  59. AL  AH * 10 + AL;
  60. AH  0;
  61.  
  62. Description
  63.  
  64. AAD is used to prepare two unpacked BCD digits (the least-significant
  65. digit in AL, the most-significant digit in AH) for a division operation that
  66. will yield an unpacked result. This is accomplished by setting AL to
  67. AL + (10 * AH), and then setting AH to 0. AX is then equal to the binary
  68. equivalent of the original unpacked two-digit number.
  69.  
  70. Flags Affected
  71.  
  72. SF, ZF, and PF as described in Appendix C; OF, AF, and CF are undefined
  73.  
  74. Protected Mode Exceptions
  75.  
  76. None
  77.  
  78. Real Address Mode Exceptions
  79.  
  80. None
  81.  
  82. Virtual 8086 Mode Exceptions
  83.  
  84. None
  85.  
  86.  
  87. AAM ── ASCII Adjust AX after Multiply
  88.  
  89. Opcode    Instruction    Clocks    Description
  90.  
  91. D4 0A     AAM            17        ASCII adjust AX after multiply
  92.  
  93.  
  94. Operation
  95.  
  96. AH  AL / 10;
  97. AL  AL MOD 10;
  98.  
  99. Description
  100.  
  101. Execute AAM only after executing a MUL instruction between two unpacked
  102. BCD digits that leaves the result in the AX register. Because the result is
  103. less than 100, it is contained entirely in the AL register. AAM unpacks the
  104. AL result by dividing AL by 10, leaving the quotient (most-significant
  105. digit) in AH and the remainder (least-significant digit) in AL.
  106.  
  107. Flags Affected
  108.  
  109. SF, ZF, and PF as described in Appendix C; OF, AF, and CF are undefined
  110.  
  111. Protected Mode Exceptions
  112.  
  113. None
  114.  
  115. Real Address Mode Exceptions
  116.  
  117. None
  118.  
  119. Virtual 8086 Mode Exceptions
  120.  
  121. None
  122.  
  123.  
  124. AAS ── ASCII Adjust AL after Subtraction
  125.  
  126. Opcode    Instruction    Clocks    Description
  127.  
  128. 3F        AAS            4         ASCII adjust AL after subtraction
  129.  
  130.  
  131. Operation
  132.  
  133. IF (AL AND 0FH) > 9 OR AF = 1
  134. THEN
  135.    AL  AL - 6;
  136.    AL  AL AND 0FH;
  137.    AH  AH - 1;
  138.    AF  1;
  139.    CF  1;
  140. ELSE
  141.    CF  0;
  142.    AF  0;
  143. FI;
  144.  
  145. Description
  146.  
  147. Execute AAS only after a SUB instruction that leaves the byte result in the
  148. AL register. The lower nibbles of the operands of the SUB instruction must
  149. have been in the range 0 through 9 (BCD digits). In this case, AAS adjusts
  150. AL so it contains the correct decimal digit result. If the subtraction
  151. produced a decimal carry, the AH register is decremented, and the carry and
  152. auxiliary carry flags are set to 1. If no decimal carry occurred, the carry
  153. and auxiliary carry flags are set to 0, and AH is unchanged. In either case,
  154. AL is left with its top nibble set to 0. To convert AL to an ASCII result,
  155. follow the AAS with OR AL, 30H.
  156.  
  157. Flags Affected
  158.  
  159. AF and CF as described above; OF, SF, ZF, and PF are undefined
  160.  
  161. Protected Mode Exceptions
  162.  
  163. None
  164.  
  165. Real Address Mode Exceptions
  166.  
  167. None
  168.  
  169. Virtual 8086 Mode Exceptions
  170.  
  171. None
  172.  
  173.  
  174. ADC ── Add with Carry
  175.  
  176.  
  177. Opcode    Instruction      Clocks    Description
  178.  
  179. 14 ib     ADC AL,imm8      2         Add with carry immediate byte to AL
  180. 15 iw     ADC AX,imm16     2         Add with carry immediate word to AX
  181. 15 id     ADC EAX,imm32    2         Add with carry immediate dword to EAX
  182. 80 /2 ib  ADC r/m8,imm8    2/7       Add with carry immediate byte to r/m
  183.                                      byte
  184. 81 /2 iw  ADC r/m16,imm16  2/7       Add with carry immediate word to r/m
  185.                                      word
  186. 81 /2 id  ADC r/m32,imm32  2/7       Add with CF immediate dword to r/m
  187.                                      dword
  188. 83 /2 ib  ADC r/m16,imm8   2/7       Add with CF sign-extended immediate
  189.                                      byte to r/m word
  190. 83 /2 ib  ADC r/m32,imm8   2/7       Add with CF sign-extended immediate
  191.                                      byte into r/m dword
  192. 10 /r     ADC r/m8,r8      2/7       Add with carry byte register to r/m
  193.                                      byte
  194. 11 /r     ADC r/m16,r16    2/7       Add with carry word register to r/m
  195.                                      word
  196. 11 /r     ADC r/m32,r32    2/7       Add with CF dword register to r/m dword
  197. 12 /r     ADC r8,r/m8      2/6       Add with carry r/m byte to byte
  198.                                      register
  199. 13 /r     ADC r16,r/m16    2/6       Add with carry r/m word to word
  200.                                      register
  201. 13 /r     ADC r32,r/m32    2/6       Add with CF r/m dword to dword register
  202.  
  203.  
  204. Operation
  205.  
  206. DEST  DEST + SRC + CF;
  207.  
  208. Description
  209.  
  210. ADC performs an integer addition of the two operands DEST and SRC and the
  211. carry flag, CF. The result of the addition is assigned to the first operand
  212. (DEST), and the flags are set accordingly. ADC is usually executed as part
  213. of a multi-byte or multi-word addition operation. When an immediate byte
  214. value is added to a word or doubleword operand, the immediate value is first
  215. sign-extended to the size of the word or doubleword operand.
  216.  
  217. Flags Affected
  218.  
  219. OF, SF, ZF, AF, CF, and PF as described in Appendix C
  220.  
  221. Protected Mode Exceptions
  222.  
  223. #GP(0) if the result is in a nonwritable segment; #GP(0) for an illegal
  224. memory operand effective address in the CS, DS, ES, FS, or GS segments;
  225. #SS(0) for an illegal address in the SS segment; #PF(fault-code) if page
  226. fault
  227.  
  228. Real Address Mode Exceptions
  229.  
  230. Interrupt 13 if any part of the operand would lie outside of the effective
  231. address space from 0 to 0FFFFH
  232.  
  233. Virtual 8086 Mode Exceptions
  234.  
  235. Same exceptions as in Real Address Mode; #PF(fault-code) for a page fault
  236.  
  237.  
  238. ADD ── Add
  239.  
  240. Opcode    Instruction         Clocks    Description
  241.  
  242. 04 ib     ADD AL,imm8          2        Add immediate byte to AL
  243. 05 iw     ADD AX,imm16         2        Add immediate word to AX
  244. 05 id     ADD EAX,imm32        2        Add immediate dword to EAX
  245. 80 /0 ib  ADD r/m8,imm8        2/7      Add immediate byte to r/m byte
  246. 81 /0 iw  ADD r/m16,imm16      2/7      Add immediate word to r/m word
  247. 81 /0 id  ADD r/m32,imm32      2/7      Add immediate dword to r/m dword
  248. 83 /0 ib  ADD r/m16,imm8       2/7      Add sign-extended immediate byte
  249.                                         to r/m word
  250. 83 /0 ib  ADD r/m32,imm8       2/7      Add sign-extended immediate byte
  251.                                         to r/m dword
  252. 00 /r     ADD r/m8,r8          2/7      Add byte register to r/m byte
  253. 01 /r     ADD r/m16,r16        2/7      Add word register to r/m word
  254. 01 /r     ADD r/m32,r32        2/7      Add dword register to r/m dword
  255. 02 /r     ADD r8,r/m8          2/6      Add r/m byte to byte register
  256. 03 /r     ADD r16,r/m16        2/6      Add r/m word to word register
  257. 03 /r     ADD r32,r/m32        2/6      Add r/m dword to dword register
  258.  
  259.  
  260. Operation
  261.  
  262. DEST  DEST + SRC;
  263.  
  264. Description
  265.  
  266. ADD performs an integer addition of the two operands (DEST and SRC). The
  267. result of the addition is assigned to the first operand (DEST), and the
  268. flags are set accordingly.
  269.  
  270. When an immediate byte is added to a word or doubleword operand, the
  271. immediate value is sign-extended to the size of the word or doubleword
  272. operand.
  273.  
  274. Flags Affected
  275.  
  276. OF, SF, ZF, AF, CF, and PF as described in Appendix C
  277.  
  278. Protected Mode Exceptions
  279.  
  280. #GP(0) if the result is in a nonwritable segment; #GP(0) for an illegal
  281. memory operand effective address in the CS, DS, ES, FS, or GS segments;
  282. #SS(0) for an illegal address in the SS segment; #PF(fault-code) for a page
  283. fault
  284.  
  285. Real Address Mode Exceptions
  286.  
  287. Interrupt 13 if any part of the operand would lie outside of the effective
  288. address space from 0 to 0FFFFH
  289.  
  290. Virtual 8086 Mode Exceptions
  291.  
  292. Same exceptions as in Real Address Mode; #PF(fault-code) for a page fault
  293.  
  294.  
  295. AND ── Logical AND
  296.  
  297. Opcode    Instruction          Clocks    Description
  298.  
  299. 24 ib     AND AL,imm8          2         AND immediate byte to AL
  300. 25 iw     AND AX,imm16         2         AND immediate word to AX
  301. 25 id     AND EAX,imm32        2         AND immediate dword to EAX
  302. 80 /4 ib  AND r/m8,imm8        2/7       AND immediate byte to r/m byte
  303. 81 /4 iw  AND r/m16,imm16      2/7       AND immediate word to r/m word
  304. 81 /4 id  AND r/m32,imm32      2/7       AND immediate dword to r/m dword
  305. 83 /4 ib  AND r/m16,imm8       2/7       AND sign-extended immediate byte
  306.                                          with r/m word
  307. 83 /4 ib  AND r/m32,imm8       2/7       AND sign-extended immediate byte
  308.                                          with r/m dword
  309. 20 /r     AND r/m8,r8          2/7       AND byte register to r/m byte
  310. 21 /r     AND r/m16,r16        2/7       AND word register to r/m word
  311. 21 /r     AND r/m32,r32        2/7       AND dword register to r/m dword
  312. 22 /r     AND r8,r/m8          2/6       AND r/m byte to byte register
  313. 23 /r     AND r16,r/m16        2/6       AND r/m word to word register
  314. 23 /r     AND r32,r/m32        2/6       AND r/m dword to dword register
  315.  
  316.  
  317. Operation
  318.  
  319. DEST  DEST AND SRC;
  320. CF  0;
  321. OF  0;
  322.  
  323. Description
  324.  
  325. Each bit of the result of the AND instruction is a 1 if both corresponding
  326. bits of the operands are 1; otherwise, it becomes a 0.
  327.  
  328. Flags Affected
  329.  
  330. CF = 0, OF = 0; PF, SF, and ZF as described in Appendix C
  331.  
  332. Protected Mode Exceptions
  333.  
  334. #GP(0) if the result is in a nonwritable segment; #GP(0) for an illegal
  335. memory operand effective address in the CS, DS, ES, FS, or GS segments;
  336. #SS(0) for an illegal address in the SS segment; #PF(fault-code) for a page
  337. fault
  338.  
  339. Real Address Mode Exceptions
  340.  
  341. Interrupt 13 if any part of the operand would lie outside of the effective
  342. address space from 0 to 0FFFFH
  343.  
  344. Virtual 8086 Mode Exceptions
  345.  
  346. Same exceptions as in Real Address Mode; #PF(fault-code) for a page fault
  347.  
  348.  
  349. ARPL ── Adjust RPL Field of Selector
  350.  
  351. Opcode    Instruction          Clocks    Description
  352.  
  353. 63 /r     ARPL r/m16,r16       pm=20/21  Adjust RPL of r/m16 to not
  354.                                          less than RPL of r16
  355.  
  356.  
  357. Operation
  358.  
  359. IF RPL bits(0,1) of DEST < RPL bits(0,1) of SRC
  360. THEN
  361.    ZF  1;
  362.    RPL bits(0,1) of DEST  RPL bits(0,1) of SRC;
  363. ELSE
  364.    ZF  0;
  365. FI;
  366.  
  367. Description
  368.  
  369. The ARPL instruction has two operands. The first operand is a 16-bit
  370. memory variable or word register that contains the value of a selector. The
  371. second operand is a word register. If the RPL field ("requested privilege
  372. level"──bottom two bits) of the first operand is less than the RPL field of
  373. the second operand, the zero flag is set to 1 and the RPL field of the
  374. first operand is increased to match the second operand. Otherwise, the zero
  375. flag is set to 0 and no change is made to the first operand.
  376.  
  377. ARPL appears in operating system software, not in application programs. It
  378. is used to guarantee that a selector parameter to a subroutine does not
  379. request more privilege than the caller is allowed. The second operand of
  380. ARPL is normally a register that contains the CS selector value of the
  381. caller.
  382.  
  383. Flags Affected
  384.  
  385. ZF as described above
  386.  
  387. Protected Mode Exceptions
  388.  
  389. #GP(0) if the result is in a nonwritable segment; #GP(0) for an illegal
  390. memory operand effective address in the CS, DS, ES, FS, or GS segments;
  391. #SS(0) for an illegal address in the SS segment; #PF(fault-code) for a page
  392. fault
  393.  
  394. Real Address Mode Exceptions
  395.  
  396. Interrupt 6; ARPL is not recognized in Real Address Mode
  397.  
  398. Virtual 8086 Mode Exceptions
  399.  
  400. Same exceptions as in Real Address Mode; #PF(fault-code) for a page fault
  401.  
  402.  
  403. BOUND ── Check Array Index Against Bounds
  404.  
  405. Opcode    Instruction          Clocks    Description
  406.  
  407. 62 /r     BOUND r16,m16&16     10        Check if r16 is within bounds
  408.                                          (passes test)
  409. 62 /r     BOUND r32,m32&32     10        Check if r32 is within bounds
  410.                                          (passes test)
  411.  
  412.  
  413. Operation
  414.  
  415. IF (LeftSRC < [RightSRC] OR LeftSRC > [RightSRC + OperandSize/8])
  416.    (* Under lower bound or over upper bound *)
  417. THEN Interrupt 5;
  418. FI;
  419.  
  420. Description
  421.  
  422. BOUND ensures that a signed array index is within the limits specified by a
  423. block of memory consisting of an upper and a lower bound. Each bound uses
  424. one word for an operand-size attribute of 16 bits and a doubleword for an
  425. operand-size attribute of 32 bits. The first operand (a register) must be
  426. greater than or equal to the first bound in memory (lower bound), and less
  427. than or equal to the second bound in memory (upper bound). If the register
  428. is not within bounds, an Interrupt 5 occurs; the return EIP points to the
  429. BOUND instruction.
  430.  
  431. The bounds limit data structure is usually placed just before the array
  432. itself, making the limits addressable via a constant offset from the
  433. beginning of the array.
  434.  
  435. Flags Affected
  436.  
  437. None
  438.  
  439. Protected Mode Exceptions
  440.  
  441. Interrupt 5 if the bounds test fails, as described above; #GP(0) for an
  442. illegal memory operand effective address in the CS, DS, ES, FS, or GS
  443. segments; #SS(0) for an illegal address in the SS segment; #PF(fault-code)
  444. for a page fault
  445.  
  446. The second operand must be a memory operand, not a register. If BOUND is
  447. executed with a ModRM byte representing a register as the second operand,
  448. #UD occurs.
  449.  
  450. Real Address Mode Exceptions
  451.  
  452. Interrupt 5 if the bounds test fails; Interrupt 13 if any part of the
  453. operand would lie outside of the effective address space from 0 to 0FFFFH;
  454. Interrupt 6 if the second operand is a register
  455.  
  456. Virtual 8086 Mode Exceptions
  457.  
  458. Same exceptions as in Real Address Mode; #PF(fault-code) for a page fault
  459.  
  460.  
  461. BSF ── Bit Scan Forward
  462.  
  463. Opcode    Instruction          Clocks    Description
  464.  
  465. 0F  BC    BSF r16,r/m16        10+3n     Bit scan forward on r/m word
  466. 0F  BC    BSF r32,r/m32        10+3n     Bit scan forward on r/m dword
  467.  
  468.  
  469. Notes
  470.  
  471.  is the number of leading zero bits.
  472.  
  473. Operation
  474.  
  475. IF r/m = 0
  476. THEN
  477.    ZF  1;
  478.    register  UNDEFINED;
  479. ELSE
  480.    temp  0;
  481.    ZF  0;
  482.    WHILE BIT[r/m, temp = 0]
  483.    DO
  484.       temp  temp + 1;
  485.       register  temp;
  486.    OD;
  487. FI;
  488.  
  489. Description
  490.  
  491. BSF scans the bits in the second word or doubleword operand starting with
  492. bit 0. The ZF flag is cleared if the bits are all 0; otherwise, the ZF flag
  493. is set and the destination register is loaded with the bit index of the
  494. first set bit.
  495.  
  496. Flags Affected
  497.  
  498. ZF as described above
  499.  
  500. Protected Mode Exceptions
  501.  
  502. #GP(0) for an illegal memory operand effective address in the CS, DS, ES,
  503. FS, or GS segments; #SS(0) for an illegal address in the SS segment;
  504. #PF(fault-code) for a page fault
  505.  
  506. Real Address Mode Exceptions
  507.  
  508. Interrupt 13 if any part of the operand would lie outside of the effective
  509. address space from 0 to 0FFFFH
  510.  
  511. Virtual 8086 Mode Exceptions
  512.  
  513. Same exceptions as in Real Address Mode; #PF(fault-code) for a page fault
  514.  
  515.  
  516. BSR ── Bit Scan Reverse
  517.  
  518. Opcode    Instruction          Clocks    Description
  519.  
  520. 0F  BD    BSR r16,r/m16        10+3n     Bit scan reverse on r/m word
  521. 0F  BD    BSR r32,r/m32        10+3n     Bit scan reverse on r/m dword
  522.  
  523.  
  524. Operation
  525.  
  526. IF r/m = 0
  527. THEN
  528.    ZF  1;
  529.    register  UNDEFINED;
  530. ELSE
  531.    temp  OperandSize - 1;
  532.    ZF  0;
  533.    WHILE BIT[r/m, temp] = 0
  534.    DO
  535.       temp  temp - 1;
  536.       register  temp;
  537.    OD;
  538. FI;
  539.  
  540. Description
  541.  
  542. BSR scans the bits in the second word or doubleword operand from the most
  543. significant bit to the least significant bit. The ZF flag is cleared if the
  544. bits are all 0; otherwise, ZF is set and the destination register is loaded
  545. with the bit index of the first set bit found when scanning in the reverse
  546. direction.
  547.  
  548. Flags Affected
  549.  
  550. ZF as described above
  551.  
  552. Protected Mode Exceptions
  553.  
  554. #GP(0) if the result is in a nonwritable segment; #GP(0) for an illegal
  555. memory operand effective address in the CS, DS, ES, FS, or GS segments;
  556. #SS(0) for an illegal address in the SS segment; #PF(fault-code) for a page
  557. fault
  558.  
  559. Real Address Mode Exceptions
  560.  
  561. Interrupt 13 if any part of the operand would lie outside of the effective
  562. address space from 0 to 0FFFFH
  563.  
  564. Virtual 8086 Mode Exceptions
  565.  
  566. Same exceptions as in Real Address Mode; #PF(fault-code) for a page fault
  567.  
  568.  
  569. BT ── Bit Test
  570.  
  571. Opcode         Instruction     Clocks    Description
  572.  
  573. 0F  A3         BT r/m16,r16    3/12      Save bit in carry flag
  574. 0F  A3         BT r/m32,r32    3/12      Save bit in carry flag
  575. 0F  BA /4 ib   BT r/m16,imm8   3/6       Save bit in carry flag
  576. 0F  BA /4 ib   BT r/m32,imm8   3/6       Save bit in carry flag
  577.  
  578.  
  579. Operation
  580.  
  581. CF  BIT[LeftSRC, RightSRC];
  582.  
  583. Description
  584.  
  585. BT saves the value of the bit indicated by the base (first operand) and the
  586. bit offset (second operand) into the carry flag.
  587.  
  588. Flags Affected
  589.  
  590. CF as described above
  591.  
  592. Protected Mode Exceptions
  593.  
  594. #GP(0) for an illegal memory operand effective address in the CS, DS, ES,
  595. FS, or GS segments; #SS(0) for an illegal address in the SS segment;
  596. #PF(fault-code) for a page fault
  597.  
  598. Real Address Mode Exceptions
  599.  
  600. Interrupt 13 if any part of the operand would lie outside of the effective
  601. address space from 0 to 0FFFFH
  602.  
  603. Virtual 8086 Mode Exceptions
  604.  
  605. Same exceptions as in Real Address Mode; #PF(fault-code) for a page fault
  606.  
  607. Notes
  608.  
  609. The index of the selected bit can be given by the immediate constant in the
  610. instruction or by a value in a general register. Only an 8-bit immediate
  611. value is used in the instruction. This operand is taken modulo 32, so the
  612. range of immediate bit offsets is 0..31. This allows any bit within a
  613. register to be selected. For memory bit strings, this immediate field gives
  614. only the bit offset within a word or doubleword. Immediate bit offsets
  615. larger than 31 are supported by using the immediate bit offset field in
  616. combination with the displacement field of the memory operand. The low-order
  617. 3 to 5 bits of the immediate bit offset are stored in the immediate bit
  618. offset field, and the high-order 27 to 29 bits are shifted and combined with
  619. the byte displacement in the addressing mode.
  620.  
  621. When accessing a bit in memory, the 80386 may access four bytes starting
  622. from the memory address given by:
  623.  
  624.    Effective Address + (4 * (BitOffset DIV 32))
  625.  
  626. for a 32-bit operand size, or two bytes starting from the memory address
  627. given by:
  628.  
  629.    Effective Address + (2 * (BitOffset DIV 16))
  630.  
  631. for a 16-bit operand size. It may do so even when only a single byte needs
  632. to be accessed in order to reach the given bit. You must therefore avoid
  633. referencing areas of memory close to address space holes. In particular,
  634. avoid references to memory-mapped I/O registers. Instead, use the MOV
  635. instructions to load from or store to these addresses, and use the register
  636. form of these instructions to manipulate the data.
  637.  
  638.  
  639. BTC ── Bit Test and Complement
  640.  
  641. Opcode        Instruction     Clocks  Description
  642.  
  643. 0F  BB        BTC r/m16,r16   6/13    Save bit in carry flag and complement
  644. 0F  BB        BTC r/m32,r32   6/13    Save bit in carry flag and complement
  645. 0F  BA /7 ib  BTC r/m16,imm8  6/8     Save bit in carry flag and complement
  646. 0F  BA /7 ib  BTC r/m32,imm8  6/8     Save bit in carry flag and complement
  647.  
  648.  
  649. Operation
  650.  
  651. CF  BIT[LeftSRC, RightSRC];
  652. BIT[LeftSRC, RightSRC]  NOT BIT[LeftSRC, RightSRC];
  653.  
  654. Description
  655.  
  656. BTC saves the value of the bit indicated by the base (first operand) and the
  657. bit offset (second operand) into the carry flag and then complements the
  658. bit.
  659.  
  660. Flags Affected
  661.  
  662. CF as described above
  663.  
  664. Protected Mode Exceptions
  665.  
  666. #GP(0) if the result is in a nonwritable segment; #GP(0) for an illegal
  667. memory operand effective address in the CS, DS, ES, FS, or GS segments;
  668. #SS(0) for an illegal address in the SS segment; #PF(fault-code) for a page
  669. fault
  670.  
  671. Real Address Mode Exceptions
  672.  
  673. Interrupt 13 if any part of the operand would lie outside of the effective
  674. address space from 0 to 0FFFFH
  675.  
  676. Virtual 8086 Mode Exceptions
  677.  
  678. Same exceptions as in Real Address Mode; #PF(fault-code) for a page fault
  679.  
  680. Notes
  681.  
  682. The index of the selected bit can be given by the immediate constant in the
  683. instruction or by a value in a general register. Only an 8-bit immediate
  684. value is used in the instruction. This operand is taken modulo 32, so the
  685. range of immediate bit offsets is 0..31. This allows any bit within a
  686. register to be selected. For memory bit strings, this immediate field gives
  687. only the bit offset within a word or doubleword. Immediate bit offsets
  688. larger than 31 are supported by using the immediate bit offset field in
  689. combination with the displacement field of the memory operand. The low-order
  690. 3 to 5 bits of the immediate bit offset are stored in the immediate bit
  691. offset field, and the high-order 27 to 29 bits are shifted and combined with
  692. the byte displacement in the addressing mode.
  693.  
  694. When accessing a bit in memory, the 80386 may access four bytes starting
  695. from the memory address given by:
  696.  
  697.    Effective Address + (4 * (BitOffset DIV 32))
  698.  
  699. for a 32-bit operand size, or two bytes starting from the memory address
  700. given by:
  701.  
  702.    Effective Address + (2 * (BitOffset DIV 16))
  703.  
  704. for a 16-bit operand size. It may do so even when only a single byte needs
  705. to be accessed in order to reach the given bit. You must therefore avoid
  706. referencing areas of memory close to address space holes. In particular,
  707. avoid references to memory-mapped I/O registers. Instead, use the MOV
  708. instructions to load from or store to these addresses, and use the register
  709. form of these instructions to manipulate the data.
  710.  
  711.  
  712. BTR ── Bit Test and Reset
  713.  
  714. Opcode        Instruction     Clocks  Description
  715.  
  716. 0F  B3        BTR r/m16,r16   6/13    Save bit in carry flag and reset
  717. 0F  B3        BTR r/m32,r32   6/13    Save bit in carry flag and reset
  718. 0F  BA /6 ib  BTR r/m16,imm8  6/8     Save bit in carry flag and reset
  719. 0F  BA /6 ib  BTR r/m32,imm8  6/8     Save bit in carry flag and reset
  720.  
  721.  
  722. Operation
  723.  
  724. CF  BIT[LeftSRC, RightSRC];
  725. BIT[LeftSRC, RightSRC]  0;
  726.  
  727. Description
  728.  
  729. BTR saves the value of the bit indicated by the base (first operand) and the
  730. bit offset (second operand) into the carry flag and then stores 0 in the
  731. bit.
  732.  
  733. Flags Affected
  734.  
  735. CF as described above
  736.  
  737. Protected Mode Exceptions
  738.  
  739. #GP(0) if the result is in a nonwritable segment; #GP(0) for an illegal
  740. memory operand effective address in the CS, DS, ES, FS, or GS segments;
  741. #SS(0) for an illegal address in the SS segment; #PF(fault-code) for a page
  742. fault
  743.  
  744. Real Address Mode Exceptions
  745.  
  746. Interrupt 13 if any part of the operand would lie outside of the effective
  747. address space from 0 to 0FFFFH
  748.  
  749. Virtual 8086 Mode Exceptions
  750.  
  751. Same exceptions as in Real Address Mode; #PF(fault-code) for a page fault
  752.  
  753. Notes
  754.  
  755. The index of the selected bit can be given by the immediate constant in the
  756. instruction or by a value in a general register. Only an 8-bit immediate
  757. value is used in the instruction. This operand is taken modulo 32, so the
  758. range of immediate bit offsets is 0..31. This allows any bit within a
  759. register to be selected. For memory bit strings, this immediate field gives
  760. only the bit offset within a word or doubleword. Immediate bit offsets
  761. larger than 31 (or 15) are supported by using the immediate bit offset field
  762. in combination with the displacement field of the memory operand. The
  763. low-order 3 to 5 bits of the immediate bit offset are stored in the
  764. immediate bit offset field, and the high-order 27 to 29 bits are shifted and
  765. combined with the byte displacement in the addressing mode.
  766.  
  767. When accessing a bit in memory, the 80386 may access four bytes starting
  768. from the memory address given by:
  769.  
  770.    Effective Address + 4 * (BitOffset DIV 32)
  771.  
  772. for a 32-bit operand size, or two bytes starting from the memory address
  773. given by:
  774.  
  775.    Effective Address + 2 * (BitOffset DIV 16)
  776.  
  777. for a 16-bit operand size. It may do so even when only a single byte needs
  778. to be accessed in order to reach the given bit. You must therefore avoid
  779. referencing areas of memory close to address space holes. In particular,
  780. avoid references to memory-mapped I/O registers. Instead, use the MOV
  781. instructions to load from or store to these addresses, and use the register
  782. form of these instructions to manipulate the data.
  783.  
  784.  
  785. BTS ── Bit Test and Set
  786.  
  787. Opcode        Instruction     Clocks  Description
  788.  
  789. 0F  AB        BTS r/m16,r16   6/13    Save bit in carry flag and set
  790. 0F  AB        BTS r/m32,r32   6/13    Save bit in carry flag and set
  791. 0F  BA /5 ib  BTS r/m16,imm8  6/8     Save bit in carry flag and set
  792. 0F  BA /5 ib  BTS r/m32,imm8  6/8     Save bit in carry flag and set
  793.  
  794.  
  795. Operation
  796.  
  797. CF  BIT[LeftSRC, RightSRC];
  798. BIT[LeftSRC, RightSRC]  1;
  799.  
  800. Description
  801.  
  802. BTS saves the value of the bit indicated by the base (first operand) and the
  803. bit offset (second operand) into the carry flag and then stores 1 in the
  804. bit.
  805.  
  806. Flags Affected
  807.  
  808. CF as described above
  809.  
  810. Protected Mode Exceptions
  811.  
  812. #GP(0) if the result is in a nonwritable segment; #GP(0) for an illegal
  813. memory operand effective address in the CS, DS, ES, FS, or GS segments;
  814. #SS(0) for an illegal address in the SS segment; #PF(fault-code) for a page
  815. fault
  816.  
  817. Real Address Mode Exceptions
  818.  
  819. Interrupt 13 if any part of the operand would lie outside of the effective
  820. address space from 0 to 0FFFFH
  821.  
  822. Virtual 8086 Mode Exceptions
  823.  
  824. Same exceptions as in Real Address Mode; #PF(fault-code) for a page fault
  825.  
  826. Notes
  827.  
  828. The index of the selected bit can be given by the immediate constant in the
  829. instruction or by a value in a general register. Only an 8-bit immediate
  830. value is used in the instruction. This operand is taken modulo 32, so the
  831. range of immediate bit offsets is 0..31. This allows any bit within a
  832. register to be selected. For memory bit strings, this immediate field gives
  833. only the bit offset within a word or doubleword. Immediate bit offsets
  834. larger than 31 are supported by using the immediate bit offset field in
  835. combination with the displacement field of the memory operand. The
  836. low-order 3 to 5 bits of the immediate bit offset are stored in the
  837. immediate bit offset field, and the high order 27 to 29 bits are shifted and
  838. combined with the byte displacement in the addressing mode.
  839.  
  840. When accessing a bit in memory, the processor may access four bytes starting
  841. from the memory address given by:
  842.  
  843.    Effective Address + (4 * (BitOffset DIV 32))
  844.  
  845. for a 32-bit operand size, or two bytes starting from the memory address
  846. given by:
  847.  
  848.    Effective Address + (2 * (BitOffset DIV 16))
  849.  
  850. for a 16-bit operand size. It may do this even when only a single byte needs
  851. to be accessed in order to get at the given bit. Thus the programmer must be
  852. careful to avoid referencing areas of memory close to address space holes.
  853. In particular, avoid references to memory-mapped I/O registers. Instead, use
  854. the MOV instructions to load from or store to these addresses, and use the
  855. register form of these instructions to manipulate the data.
  856.  
  857.  
  858. CALL ── Call Procedure
  859.  
  860.  
  861. Opcode    Instruction     Clocks
  862.   Values of ts are given by the following table:
  863.  
  864.                              New Task
  865.               386 TSS         386 TSS         286 TSS
  866.   Old         VM = 0          VM = 1
  867.   Task                     Via Task Gate?
  868.  
  869.               N     Y         N     Y         N     Y
  870.  
  871. 386          300   309       217   226       273   282
  872. TSS VM=0
  873.  
  874. 286          298   307       217   226       273   282
  875. TSS         Description
  876.  
  877. E8  cw    CALL rel16       7+m            Call near, displacement relative
  878.                                           to next instruction
  879. FF  /2    CALL r/m16       7+m/10+m       Call near, register
  880.                                           indirect/memory indirect
  881. 9A  cd    CALL ptr16:16    17+m,pm=34+m   Call intersegment, to full
  882.                                           pointer given
  883. 9A  cd    CALL ptr16:16    pm=52+m        Call gate, same privilege
  884. 9A  cd    CALL ptr16:16    pm=86+m        Call gate, more privilege, no
  885.                                           parameters
  886. 9A  cd    CALL ptr16:16    pm=94+4x+m     Call gate, more privilege, x
  887.                                           parameters
  888. 9A  cd    CALL ptr16:16    ts             Call to task
  889. FF  /3    CALL m16:16      22+m,pm=38+m   Call intersegment, address at
  890.                                           r/m dword
  891. FF  /3    CALL m16:16      pm=56+m        Call gate, same privilege
  892. FF  /3    CALL m16:16      pm=90+m        Call gate, more privilege, no
  893.                                           parameters
  894. FF  /3    CALL m16:16      pm=98+4x+m     Call gate, more privilege, x
  895.                                           parameters
  896. FF  /3    CALL m16:16      5 + ts         Call to task
  897. E8  cd    CALL rel32       7+m            Call near, displacement relative
  898.                                           to next instruction
  899. FF  /2    CALL r/m32       7+m/10+m       Call near, indirect
  900. 9A  cp    CALL ptr16:32    17+m,pm=34+m   Call intersegment, to full
  901.                                           pointer given
  902. 9A  cp    CALL ptr16:32    pm=52+m        Call gate, same privilege
  903. 9A  cp    CALL ptr16:32    pm=86+m        Call gate, more privilege, no
  904.                                           parameters
  905. 9A  cp    CALL ptr32:32    pm=94+4x+m     Call gate, more privilege, x
  906.                                           parameters
  907. 9A  cp    CALL ptr16:32    ts             Call to task
  908. FF  /3    CALL m16:32      22+m,pm=38+m   Call intersegment, address at
  909.                                           r/m dword
  910. FF  /3    CALL m16:32      pm=56+m        Call gate, same privilege
  911. FF  /3    CALL m16:32      pm=90+m        Call gate, more privilege, no
  912.                                           parameters
  913. FF  /3    CALL m16:32      pm=98+4x+m     Call gate, more privilege, x
  914.                                           parameters
  915. FF  /3    CALL m16:32      5 + ts         Call to task
  916.  
  917.  
  918. ───────────────────────────────────────────────────────────────────────────
  919. NOTE:
  920.   Values of ts are given by the following table:
  921.  
  922.                              New Task
  923.               386 TSS         386 TSS         286 TSS
  924.   Old         VM = 0          VM = 1
  925.   Task                     Via Task Gate?
  926.  
  927.               N     Y         N     Y         N     Y
  928.  
  929. 386          300   309       217   226       273   282
  930. TSS VM=0
  931.  
  932. 286          298   307       217   226       273   282
  933. TSS
  934. ───────────────────────────────────────────────────────────────────────────
  935.  
  936. Operation
  937.  
  938. IF rel16 or rel32 type of call
  939. THEN (* near relative call *)
  940.    IF OperandSize = 16
  941.    THEN
  942.       Push(IP);
  943.       EIP  (EIP + rel16) AND 0000FFFFH;
  944.    ELSE (* OperandSize = 32 *)
  945.       Push(EIP);
  946.       EIP  EIP + rel32;
  947.    FI;
  948. FI;
  949.  
  950. IF r/m16 or r/m32 type of call
  951. THEN (* near absolute call *)
  952.    IF OperandSize = 16
  953.    THEN
  954.       Push(IP);
  955.       EIP  [r/m16] AND 0000FFFFH;
  956.    ELSE (* OperandSize = 32 *)
  957.       Push(EIP);
  958.       EIP  [r/m32];
  959.    FI;
  960. FI;
  961.  
  962. IF (PE = 0 OR (PE = 1 AND VM = 1))
  963. (* real mode or virtual 8086 mode *)
  964.    AND instruction = far CALL
  965.    (* i.e., operand type is m16:16, m16:32, ptr16:16, ptr16:32 *)
  966. THEN
  967.    IF OperandSize = 16
  968.    THEN
  969.       Push(CS);
  970.       Push(IP); (* address of next instruction; 16 bits *)
  971.    ELSE
  972.       Push(CS); (* padded with 16 high-order bits *)
  973.       Push(EIP); (* address of next instruction; 32 bits *)
  974.    FI;
  975.    IF operand type is m16:16 or m16:32
  976.    THEN (* indirect far call *)
  977.       IF OperandSize = 16
  978.       THEN
  979.          CS:IP  [m16:16];
  980.          EIP  EIP AND 0000FFFFH; (* clear upper 16 bits *)
  981.       ELSE (* OperandSize = 32 *)
  982.          CS:EIP  [m16:32];
  983.       FI;
  984.    FI;
  985.    IF operand type is ptr16:16 or ptr16:32
  986.    THEN (* direct far call *)
  987.       IF OperandSize = 16
  988.       THEN
  989.          CS:IP  ptr16:16;
  990.          EIP  EIP AND 0000FFFFH; (* clear upper 16 bits *)
  991.       ELSE (* OperandSize = 32 *)
  992.          CS:EIP  ptr16:32;
  993.       FI;
  994.    FI;
  995. FI;
  996.  
  997. IF (PE = 1 AND VM = 0) (* Protected mode, not V86 mode *)
  998.    AND instruction = far CALL
  999. THEN
  1000.    If indirect, then check access of EA doubleword;
  1001.       #GP(0) if limit violation;
  1002.    New CS selector must not be null else #GP(0);
  1003.    Check that new CS selector index is within its
  1004.       descriptor table limits; else #GP(new CS selector);
  1005.    Examine AR byte of selected descriptor for various legal values;
  1006.       depending on value:
  1007.       go to CONFORMING-CODE-SEGMENT;
  1008.       go to NONCONFORMING-CODE-SEGMENT;
  1009.       go to CALL-GATE;
  1010.       go to TASK-GATE;
  1011.       go to TASK-STATE-SEGMENT;
  1012.    ELSE #GP(code segment selector);
  1013. FI;
  1014.  
  1015. CONFORMING-CODE-SEGMENT:
  1016.    DPL must be ≤ CPL ELSE #GP(code segment selector);
  1017.    Segment must be present ELSE #NP(code segment selector);
  1018.    Stack must be big enough for return address ELSE #SS(0);
  1019.    Instruction pointer must be in code segment limit ELSE #GP(0);
  1020.    Load code segment descriptor into CS register;
  1021.    Load CS with new code segment selector;
  1022.    Load EIP with zero-extend(new offset);
  1023.    IF OperandSize=16 THEN EIP  EIP AND 0000FFFFH; FI;
  1024.  
  1025. NONCONFORMING-CODE-SEGMENT:
  1026.    RPL must be ≤ CPL ELSE #GP(code segment selector)
  1027.    DPL must be = CPL ELSE #GP(code segment selector)
  1028.    Segment must be present ELSE #NP(code segment selector)
  1029.    Stack must be big enough for return address ELSE #SS(0)
  1030.    Instruction pointer must be in code segment limit ELSE #GP(0)
  1031.    Load code segment descriptor into CS register
  1032.    Load CS with new code segment selector
  1033.    Set RPL of CS to CPL
  1034.    Load EIP with zero-extend(new offset);
  1035.    IF OperandSize=16 THEN EIP  EIP AND 0000FFFFH; FI;
  1036.  
  1037. CALL-GATE:
  1038.    Call gate DPL must be ≥ CPL ELSE #GP(call gate selector)
  1039.    Call gate DPL must be ≥ RPL ELSE #GP(call gate selector)
  1040.    Call gate must be present ELSE #NP(call gate selector)
  1041.    Examine code segment selector in call gate descriptor:
  1042.       Selector must not be null ELSE #GP(0)
  1043.       Selector must be within its descriptor table
  1044.          limits ELSE #GP(code segment selector)
  1045.    AR byte of selected descriptor must indicate code
  1046.       segment ELSE #GP(code segment selector)
  1047.    DPL of selected descriptor must be ≤ CPL ELSE
  1048.       #GP(code segment selector)
  1049.    IF non-conforming code segment AND DPL < CPL
  1050.    THEN go to MORE-PRIVILEGE
  1051.    ELSE go to SAME-PRIVILEGE
  1052.    FI;
  1053.  
  1054. MORE-PRIVILEGE:
  1055.    Get new SS selector for new privilege level from TSS
  1056.       Check selector and descriptor for new SS:
  1057.          Selector must not be null ELSE #TS(0)
  1058.          Selector index must be within its descriptor
  1059.             table limits ELSE #TS(SS selector)
  1060.          Selector's RPL must equal DPL of code segment
  1061.             ELSE #TS(SS selector)
  1062.          Stack segment DPL must equal DPL of code
  1063.             segment ELSE #TS(SS selector)
  1064.          Descriptor must indicate writable data segment
  1065.             ELSE #TS(SS selector)
  1066.          Segment present ELSE #SS(SS selector)
  1067.       IF OperandSize=32
  1068.       THEN
  1069.          New stack must have room for parameters plus 16 bytes
  1070.             ELSE #SS(0)
  1071.          EIP must be in code segment limit ELSE #GP(0)
  1072.          Load new SS:eSP value from TSS
  1073.          Load new CS:EIP value from gate
  1074.       ELSE
  1075.          New stack must have room for parameters plus 8 bytes ELSE #SS(0)
  1076.          IP must be in code segment limit ELSE #GP(0)
  1077.          Load new SS:eSP value from TSS
  1078.          Load new CS:IP value from gate
  1079.       FI;
  1080.       Load CS descriptor
  1081.       Load SS descriptor
  1082.       Push long pointer of old stack onto new stack
  1083.       Get word count from call gate, mask to 5 bits
  1084.       Copy parameters from old stack onto new stack
  1085.       Push return address onto new stack
  1086.       Set CPL to stack segment DPL
  1087.       Set RPL of CS to CPL
  1088.  
  1089. SAME-PRIVILEGE:
  1090.    IF OperandSize=32
  1091.    THEN
  1092.       Stack must have room for 6-byte return address (padded to 8 bytes)
  1093.          ELSE #SS(0)
  1094.       EIP must be within code segment limit ELSE #GP(0)
  1095.       Load CS:EIP from gate
  1096.    ELSE
  1097.       Stack must have room for 4-byte return address ELSE #SS(0)
  1098.       IP must be within code segment limit ELSE #GP(0)
  1099.       Load CS:IP from gate
  1100.    FI;
  1101.    Push return address onto stack
  1102.    Load code segment descriptor into CS register
  1103.    Set RPL of CS to CPL
  1104.  
  1105. TASK-GATE:
  1106.    Task gate DPL must be ≥ CPL ELSE #TS(gate selector)
  1107.    Task gate DPL must be ≥ RPL ELSE #TS(gate selector)
  1108.    Task Gate must be present ELSE #NP(gate selector)
  1109.    Examine selector to TSS, given in Task Gate descriptor:
  1110.       Must specify global in the local/global bit ELSE #TS(TSS selector)
  1111.       Index must be within GDT limits ELSE #TS(TSS selector)
  1112.       TSS descriptor AR byte must specify nonbusy TSS
  1113.          ELSE #TS(TSS selector)
  1114.       Task State Segment must be present ELSE #NP(TSS selector)
  1115.    SWITCH-TASKS (with nesting) to TSS
  1116.    IP must be in code segment limit ELSE #TS(0)
  1117.  
  1118. TASK-STATE-SEGMENT:
  1119.    TSS DPL must be ≥ CPL else #TS(TSS selector)
  1120.    TSS DPL must be ≥ RPL ELSE #TS(TSS selector)
  1121.    TSS descriptor AR byte must specify available TSS
  1122.       ELSE #TS(TSS selector)
  1123.    Task State Segment must be present ELSE #NP(TSS selector)
  1124.    SWITCH-TASKS (with nesting) to TSS
  1125.    IP must be in code segment limit ELSE #TS(0)
  1126.  
  1127. Description
  1128.  
  1129. The CALL instruction causes the procedure named in the operand to be
  1130. executed. When the procedure is complete (a return instruction is executed
  1131. within the procedure), execution continues at the instruction that follows
  1132. the CALL instruction.
  1133.  
  1134. The action of the different forms of the instruction are described below.
  1135.  
  1136. Near calls are those with destinations of type r/m16, r/m32, rel16, rel32;
  1137. changing or saving the segment register value is not necessary. The CALL
  1138. rel16 and CALL rel32 forms add a signed offset to the address of the
  1139. instruction following CALL to determine the destination. The rel16 form is
  1140. used when the instruction's operand-size attribute is 16 bits; rel32 is used
  1141. when the operand-size attribute is 32 bits. The result is stored in the
  1142. 32-bit EIP register. With rel16, the upper 16 bits of EIP are cleared,
  1143. resulting in an offset whose value does not exceed 16 bits. CALL r/m16 and
  1144. CALL r/m32 specify a register or memory location from which the absolute
  1145. segment offset is fetched. The offset fetched from r/m is 32 bits for an
  1146. operand-size attribute of 32 (r/m32), or 16 bits for an operand-size of 16
  1147. (r/m16). The offset of the instruction following CALL is pushed onto the
  1148. stack. It will be popped by a near RET instruction within the procedure. The
  1149. CS register is not changed by this form of CALL.
  1150.  
  1151. The far calls, CALL ptr16:16 and CALL ptr16:32, use a four-byte or six-byte
  1152. operand as a long pointer to the procedure called. The CALL m16:16 and
  1153. m16:32 forms fetch the long pointer from the memory location
  1154. specified (indirection). In Real Address Mode or Virtual 8086 Mode, the long
  1155. pointer provides 16 bits for the CS register and 16 or 32 bits for the EIP
  1156. register (depending on the operand-size attribute). These forms of the
  1157. instruction push both CS and IP or EIP as a return address.
  1158.  
  1159. In Protected Mode, both long pointer forms consult the AR byte in the
  1160. descriptor indexed by the selector part of the long pointer. Depending on
  1161. the value of the AR byte, the call will perform one of the following types
  1162. of control transfers:
  1163.  
  1164.   ■  A far call to the same protection level
  1165.   ■  An inter-protection level far call
  1166.   ■  A task switch
  1167.  
  1168. For more information on Protected Mode control transfers, refer to
  1169. Chapter 6 and Chapter 7.
  1170.  
  1171. Flags Affected
  1172.  
  1173. All flags are affected if a task switch occurs; no flags are affected if a
  1174. task switch does not occur
  1175.  
  1176. Protected Mode Exceptions
  1177.  
  1178. For far calls: #GP, #NP, #SS, and #TS, as indicated in the list above
  1179.  
  1180. For near direct calls: #GP(0) if procedure location is beyond the code
  1181. segment limits; #SS(0) if pushing the return address exceeds the bounds of
  1182. the stack segment; #PF (fault-code) for a page fault
  1183.  
  1184. For a near indirect call: #GP(0) for an illegal memory operand effective
  1185. address in the CS, DS, ES, FS, or GS segments; #SS(0) for an illegal address
  1186. in the SS segment; #GP(0) if the indirect offset obtained is beyond the code
  1187. segment limits; #PF(fault-code) for a page fault
  1188.  
  1189. Real Address Mode Exceptions
  1190.  
  1191. Interrupt 13 if any part of the operand would lie outside of the effective
  1192. address space from 0 to 0FFFFH
  1193.  
  1194. Virtual 8086 Mode Exceptions
  1195.  
  1196. Same exceptions as in Real Address Mode; #PF(fault-code) for a page fault
  1197.  
  1198. Notes
  1199.  
  1200. Any far call from a 32-bit code segment to 16-bit code segments should be
  1201. made from the first 64K bytes of the 32-bit code segment, since the
  1202. operand-size attribute of the instruction is set to 16, thus allowing only a
  1203. 16-bit return address offset to be saved.
  1204.  
  1205.  
  1206. CBW/CWDE ── Convert Byte to Word/Convert Word to Doubleword
  1207.  
  1208. Opcode    Instruction     Clocks          Description
  1209.  
  1210. 98        CBW             3               AX  sign-extend of AL
  1211. 98        CWDE            3               EAX  sign-extend of AX
  1212.  
  1213.  
  1214. Operation
  1215.  
  1216. IF OperandSize = 16 (* instruction = CBW *)
  1217. THEN AX  SignExtend(AL);
  1218. ELSE (* OperandSize = 32, instruction = CWDE *)
  1219.    EAX  SignExtend(AX);
  1220. FI;
  1221.  
  1222. Description
  1223.  
  1224. CBW converts the signed byte in AL to a signed word in AX by extending the
  1225. most significant bit of AL (the sign bit) into all of the bits of AH. CWDE
  1226. converts the signed word in AX to a doubleword in EAX by extending the most
  1227. significant bit of AX into the two most significant bytes of EAX. Note that
  1228. CWDE is different from CWD. CWD uses DX:AX rather than EAX as a destination.
  1229.  
  1230. Flags Affected
  1231.  
  1232. None
  1233.  
  1234. Protected Mode Exceptions
  1235.  
  1236. None
  1237.  
  1238. Real Address Mode Exceptions
  1239.  
  1240. None
  1241.  
  1242. Virtual 8086 Mode Exceptions
  1243.  
  1244. None
  1245.  
  1246.  
  1247. CLC ── Clear Carry Flag
  1248.  
  1249. Opcode    Instruction     Clocks          Description
  1250.  
  1251. F8        CLC             2               Clear carry flag
  1252.  
  1253.  
  1254. Operation
  1255.  
  1256. CF  0;
  1257.  
  1258. Description
  1259.  
  1260. CLC sets the carry flag to zero. It does not affect other flags or
  1261. registers.
  1262.  
  1263. Flags Affected
  1264.  
  1265. CF = 0
  1266.  
  1267. Protected Mode Exceptions
  1268.  
  1269. None
  1270.  
  1271. Real Address Mode Exceptions
  1272.  
  1273. None
  1274.  
  1275. Virtual 8086 Mode Exceptions
  1276.  
  1277. None
  1278.  
  1279.  
  1280. CLD ── Clear Direction Flag
  1281.  
  1282. Opcode    Instruction     Clocks   Description
  1283.  
  1284. FC        CLD             2        Clear direction flag; SI and DI
  1285.                                    will increment during string
  1286.                                    instructions
  1287.  
  1288.  
  1289. Operation
  1290.  
  1291. DF  0;
  1292.  
  1293. Description
  1294.  
  1295. CLD clears the direction flag. No other flags or registers are affected.
  1296. After CLD is executed, string operations will increment the index registers
  1297. (SI and/or DI) that they use.
  1298.  
  1299. Flags Affected
  1300.  
  1301. DF = 0
  1302.  
  1303. Protected Mode Exceptions
  1304.  
  1305. None
  1306.  
  1307. Real Address Mode Exceptions
  1308.  
  1309. None
  1310.  
  1311. Virtual 8086 Mode Exceptions
  1312.  
  1313. None
  1314.  
  1315.  
  1316. CLI ── Clear Interrupt Flag
  1317.  
  1318. Opcode    Instruction    Clocks   Description
  1319.  
  1320. FA        CLI            3        Clear interrupt flag; interrupts disabled
  1321.  
  1322.  
  1323. Operation
  1324.  
  1325. IF  0;
  1326.  
  1327. Description
  1328.  
  1329. CLI clears the interrupt flag if the current privilege level is at least as
  1330. privileged as IOPL. No other flags are affected. External interrupts are not
  1331. recognized at the end of the CLI instruction or from that point on until the
  1332. interrupt flag is set.
  1333.  
  1334. Flags Affected
  1335.  
  1336. IF = 0
  1337.  
  1338. Protected Mode Exceptions
  1339.  
  1340. #GP(0) if the current privilege level is greater (has less privilege) than
  1341. the IOPL in the flags register. IOPL specifies the least privileged level at
  1342. which I/O can be performed.
  1343.  
  1344. Real Address Mode Exceptions
  1345.  
  1346. None
  1347.  
  1348. Virtual 8086 Mode Exceptions
  1349.  
  1350. #GP(0) as for Protected Mode
  1351.  
  1352.  
  1353. CLTS ── Clear Task-Switched Flag in CR0
  1354.  
  1355. Opcode    Instruction    Clocks   Description
  1356.  
  1357. OF  06    CLTS           5        Clear task-switched flag
  1358.  
  1359.  
  1360. Operation
  1361.  
  1362. TS Flag in CR0  0;
  1363.  
  1364. Description
  1365.  
  1366. CLTS clears the task-switched (TS) flag in register CR0. This flag is set by
  1367. the 80386 every time a task switch occurs. The TS flag is used to manage
  1368. processor extensions as follows:
  1369.  
  1370.   ■  Every execution of an ESC instruction is trapped if the TS flag is set.
  1371.  
  1372.   ■  Execution of a WAIT instruction is trapped if the MP flag and the TS
  1373.      flag are both set.
  1374.  
  1375. Thus, if a task switch was made after an ESC instruction was begun, the
  1376. processor extension's context may need to be saved before a new ESC
  1377. instruction can be issued. The fault handler saves the context and resets
  1378. the TS flag.
  1379.  
  1380. CLTS appears in operating system software, not in application programs. It
  1381. is a privileged instruction that can only be executed at privilege level 0.
  1382.  
  1383. Flags Affected
  1384.  
  1385. TS = 0 (TS is in CR0, not the flag register)
  1386.  
  1387. Protected Mode Exceptions
  1388.  
  1389. #GP(0) if CLTS is executed with a current privilege level other than 0
  1390.  
  1391. Real Address Mode Exceptions
  1392.  
  1393. None (valid in Real Address Mode to allow initialization for Protected
  1394. Mode)
  1395.  
  1396. Virtual 8086 Mode Exceptions
  1397.  
  1398. Same exceptions as in Real Address Mode
  1399.  
  1400.  
  1401. CMC ── Complement Carry Flag
  1402.  
  1403. Opcode    Instruction    Clocks   Description
  1404.  
  1405. F5        CMC            2        Complement carry flag
  1406.  
  1407.  
  1408. Operation
  1409.  
  1410. CF  NOT CF;
  1411.  
  1412. Description
  1413.  
  1414. CMC reverses the setting of the carry flag. No other flags are affected.
  1415.  
  1416. Flags Affected
  1417.  
  1418. CF as described above
  1419.  
  1420. Protected Mode Exceptions
  1421.  
  1422. None
  1423.  
  1424. Real Address Mode Exceptions
  1425.  
  1426. None
  1427.  
  1428. Virtual 8086 Mode Exceptions
  1429.  
  1430. None
  1431.  
  1432.  
  1433. CMP ── Compare Two Operands
  1434.  
  1435.  
  1436. Opcode          Instruction        Clocks   Description
  1437.  
  1438. 3C  ib          CMP AL,imm8        2        Compare immediate byte to AL
  1439. 3D  iw          CMP AX,imm16       2        Compare immediate word to AX
  1440. 3D  id          CMP EAX,imm32      2        Compare immediate dword to EAX
  1441. 80  /7 ib       CMP r/m8,imm8      2/5      Compare immediate byte to r/m
  1442.                                             byte
  1443. 81  /7 iw       CMP r/m16,imm16    2/5      Compare immediate word to r/m
  1444.                                             word
  1445. 81  /7 id       CMP r/m32,imm32    2/5      Compare immediate dword to r/m
  1446.                                             dword
  1447. 83  /7 ib       CMP r/m16,imm8     2/5      Compare sign extended immediate
  1448.                                             byte to r/m word
  1449. 83  /7 ib       CMP r/m32,imm8     2/5      Compare sign extended immediate
  1450.                                             byte to r/m dword
  1451. 38  /r          CMP r/m8,r8        2/5      Compare byte register to r/m
  1452.                                             byte
  1453. 39  /r          CMP r/m16,r16      2/5      Compare word register to r/m
  1454.                                             word
  1455. 39  /r          CMP r/m32,r32      2/5      Compare dword register to r/m
  1456.                                             dword
  1457. 3A  /r          CMP r8,r/m8        2/6      Compare r/m byte to byte
  1458.                                             register
  1459. 3B  /r          CMP r16,r/m16      2/6      Compare r/m word to word
  1460.                                             register
  1461. 3B  /r          CMP r32,r/m32      2/6      Compare r/m dword to dword
  1462.                                             register
  1463.  
  1464.  
  1465. Operation
  1466.  
  1467. LeftSRC - SignExtend(RightSRC);
  1468. (* CMP does not store a result; its purpose is to set the flags *)
  1469.  
  1470. Description
  1471.  
  1472. CMP subtracts the second operand from the first but, unlike the SUB
  1473. instruction, does not store the result; only the flags are changed. CMP is
  1474. typically used in conjunction with conditional jumps and the SETcc
  1475. instruction. (Refer to Appendix D for the list of signed and unsigned flag
  1476. tests provided.) If an operand greater than one byte is compared to an
  1477. immediate byte, the byte value is first sign-extended.
  1478.  
  1479. Flags Affected
  1480.  
  1481. OF, SF, ZF, AF, PF, and CF as described in Appendix C
  1482.  
  1483. Protected Mode Exceptions
  1484.  
  1485. #GP(0) for an illegal memory operand effective address in the CS, DS, ES,
  1486. FS, or GS segments; #SS(0) for an illegal address in the SS segment;
  1487. #PF(fault-code) for a page fault
  1488.  
  1489. Real Address Mode Exceptions
  1490.  
  1491. Interrupt 13 if any part of the operand would lie outside of the effective
  1492. address space from 0 to 0FFFFH
  1493.  
  1494. Virtual 8086 Mode Exceptions
  1495.  
  1496. Same exceptions as in Real Address Mode; #PF(fault-code) for a page fault
  1497.  
  1498.  
  1499. CMPS/CMPSB/CMPSW/CMPSD ── Compare String Operands
  1500.  
  1501. Opcode    Instruction        Clocks   Description
  1502.  
  1503. A6        CMPS m8,m8         10       Compare bytes ES:[(E)DI] (second
  1504.                                       operand) with   [(E)SI] (first 
  1505.                                       operand)
  1506. A7        CMPS m16,m16       10       Compare words ES:[(E)DI] (second
  1507.                                       operand) with   [(E)SI] (first 
  1508.                                       operand)
  1509. A7        CMPS m32,m32       10       Compare dwords ES:[(E)DI]
  1510.                                       (second operand) with [(E)SI] 
  1511.                                       (first operand)
  1512. A6        CMPSB              10       Compare bytes ES:[(E)DI] with
  1513.                                       DS:[SI]
  1514. A7        CMPSW              10       Compare words ES:[(E)DI] with
  1515.                                       DS:[SI]
  1516. A7        CMPSD              10       Compare dwords ES:[(E)DI] with
  1517.                                       DS:[SI]
  1518.  
  1519.  
  1520. Operation
  1521.  
  1522. IF (instruction = CMPSD) OR
  1523.    (instruction has operands of type DWORD)
  1524. THEN OperandSize  32;
  1525. ELSE OperandSize  16;
  1526. FI;
  1527. IF AddressSize = 16
  1528. THEN
  1529.    use SI for source-index and DI for destination-index
  1530. ELSE (* AddressSize = 32 *)
  1531.    use ESI for source-index and EDI for destination-index;
  1532. FI;
  1533. IF byte type of instruction
  1534. THEN
  1535.    [source-index] - [destination-index]; (* byte comparison *)
  1536.    IF DF = 0 THEN IncDec  1 ELSE IncDec  -1; FI;
  1537. ELSE
  1538.    IF OperandSize = 16
  1539.    THEN
  1540.       [source-index] - [destination-index]; (* word comparison *)
  1541.       IF DF = 0 THEN IncDec  2 ELSE IncDec  -2; FI;
  1542.    ELSE (* OperandSize = 32 *)
  1543.       [source-index] - [destination-index]; (* dword comparison *)
  1544.       IF DF = 0 THEN IncDec  4 ELSE IncDec  -4; FI;
  1545.    FI;
  1546. FI;
  1547. source-index = source-index + IncDec;
  1548. destination-index = destination-index + IncDec;
  1549.  
  1550. Description
  1551.  
  1552. CMPS compares the byte, word, or doubleword pointed to by the source-index
  1553. register with the byte, word, or doubleword pointed to by the
  1554. destination-index register.
  1555.  
  1556. If the address-size attribute of this instruction is 16 bits, SI and DI
  1557. will be used for source- and destination-index registers; otherwise ESI and
  1558. EDI will be used. Load the correct index values into SI and DI (or ESI and
  1559. EDI) before executing CMPS.
  1560.  
  1561. The comparison is done by subtracting the operand indexed by
  1562. the destination-index register from the operand indexed by the source-index
  1563. register.
  1564.  
  1565. Note that the direction of subtraction for CMPS is [SI] - [DI] or
  1566. [ESI] - [EDI]. The left operand (SI or ESI) is the source and the right
  1567. operand (DI or EDI) is the destination. This is the reverse of the usual
  1568. Intel convention in which the left operand is the destination and the right
  1569. operand is the source.
  1570.  
  1571. The result of the subtraction is not stored; only the flags reflect the
  1572. change. The types of the operands determine whether bytes, words, or
  1573. doublewords are compared. For the first operand (SI or ESI), the DS register
  1574. is used, unless a segment override byte is present. The second operand (DI
  1575. or EDI) must be addressable from the ES register; no segment override is
  1576. possible.
  1577.  
  1578. After the comparison is made, both the source-index register and
  1579. destination-index register are automatically advanced. If the direction flag
  1580. is 0 (CLD was executed), the registers increment; if the direction flag is 1
  1581. (STD was executed), the registers decrement. The registers increment or
  1582. decrement by 1 if a byte is compared, by 2 if a word is compared, or by 4 if
  1583. a doubleword is compared.
  1584.  
  1585. CMPSB, CMPSW and CMPSD are synonyms for the byte, word, and
  1586. doubleword CMPS instructions, respectively.
  1587.  
  1588. CMPS can be preceded by the REPE or REPNE prefix for block comparison of CX
  1589. or ECX bytes, words, or doublewords. Refer to the description of the REP
  1590. instruction for more information on this operation.
  1591.  
  1592. Flags Affected
  1593.  
  1594. OF, SF, ZF, AF, PF, and CF as described in Appendix C
  1595.  
  1596. Protected Mode Exceptions
  1597.  
  1598. #GP(0) for an illegal memory operand effective address in the CS, DS, ES,
  1599. FS, or GS segments; #SS(0) for an illegal address in the SS segment;
  1600. #PF(fault-code) for a page fault
  1601.  
  1602. Real Address Mode Exceptions
  1603.  
  1604. Interrupt 13 if any part of the operand would lie outside of the effective
  1605. address space from 0 to 0FFFFH
  1606.  
  1607. Virtual 8086 Mode Exceptions
  1608.  
  1609. Same exceptions as in Real Address Mode; #PF (fault-code) for a page fault
  1610.  
  1611.  
  1612. CWD/CDQ ── Convert Word to Doubleword/Convert Doubleword to
  1613.            Quadword
  1614.  
  1615. Opcode    Instruction        Clocks   Description
  1616.  
  1617. 99        CWD                2        DX:AX  sign-extend of AX
  1618. 99        CDQ                2        EDX:EAX  sign-extend of EAX
  1619.  
  1620.  
  1621. Operation
  1622.  
  1623. IF OperandSize = 16 (* CWD instruction *)
  1624. THEN
  1625.    IF AX < 0 THEN DX  0FFFFH; ELSE DX  0; FI;
  1626. ELSE (* OperandSize = 32, CDQ instruction *)
  1627.    IF EAX < 0 THEN EDX  0FFFFFFFFH; ELSE EDX  0; FI;
  1628. FI;
  1629.  
  1630. Description
  1631.  
  1632. CWD converts the signed word in AX to a signed doubleword in DX:AX
  1633. by extending the most significant bit of AX into all the bits of DX. CDQ
  1634. converts the signed doubleword in EAX to a signed 64-bit integer in the
  1635. register pair EDX:EAX by extending the most significant bit of EAX
  1636. (the sign bit) into all the bits of EDX. Note that CWD is different from
  1637. CWDE. CWDE uses EAX as a destination, instead of DX:AX.
  1638.  
  1639. Flags Affected
  1640.  
  1641. None
  1642.  
  1643. Protected Mode Exceptions
  1644.  
  1645. None
  1646.  
  1647. Real Address Mode Exceptions
  1648.  
  1649. None
  1650.  
  1651. Virtual 8086 Mode Exceptions
  1652.  
  1653. None
  1654.  
  1655.  
  1656. DAA ── Decimal Adjust AL after Addition
  1657.  
  1658. Opcode    Instruction        Clocks   Description
  1659.  
  1660. 27        DAA                4        Decimal adjust AL after addition
  1661.  
  1662.  
  1663. Operation
  1664.  
  1665. IF ((AL AND 0FH) > 9) OR (AF = 1)
  1666. THEN
  1667.    AL  AL + 6;
  1668.    AF  1;
  1669. ELSE
  1670.    AF  0;
  1671. FI;
  1672. IF (AL > 9FH) OR (CF = 1)
  1673. THEN
  1674.    AL  AL + 60H;
  1675.    CF  1;
  1676. ELSE CF  0;
  1677. FI;
  1678.  
  1679. Description
  1680.  
  1681. Execute DAA only after executing an ADD instruction that leaves a
  1682. two-BCD-digit byte result in the AL register. The ADD operands should
  1683. consist of two packed BCD digits. The DAA instruction adjusts AL to
  1684. contain the correct two-digit packed decimal result.
  1685.  
  1686. Flags Affected
  1687.  
  1688. AF and CF as described above; SF, ZF, PF, and CF as described in
  1689. Appendix C.
  1690.  
  1691. Protected Mode Exceptions
  1692.  
  1693. None
  1694.  
  1695. Real Address Mode Exceptions
  1696.  
  1697. None
  1698.  
  1699. Virtual 8086 Mode Exceptions
  1700.  
  1701. None
  1702.  
  1703.  
  1704. DAS ── Decimal Adjust AL after Subtraction
  1705.  
  1706. Opcode    Instruction        Clocks   Description
  1707.  
  1708. 2F        DAS                4        Decimal adjust AL after subtraction
  1709.  
  1710.  
  1711. Operation
  1712.  
  1713. IF (AL AND 0FH) > 9 OR AF = 1
  1714. THEN
  1715.    AL  AL - 6;
  1716.    AF  1;
  1717. ELSE
  1718.    AF  0;
  1719. FI;
  1720. IF (AL > 9FH) OR (CF = 1)
  1721. THEN
  1722.    AL  AL - 60H;
  1723.    CF  1;
  1724. ELSE CF  0;
  1725. FI;
  1726.  
  1727. Description
  1728.  
  1729. Execute DAS only after a subtraction instruction that leaves a
  1730. two-BCD-digit byte result in the AL register. The operands should consist
  1731. of two packed BCD digits. DAS adjusts AL to contain the correct packed
  1732. two-digit decimal result.
  1733.  
  1734. Flags Affected
  1735.  
  1736. AF and CF as described above; SF, ZF, and PF as described in Appendix C.
  1737.  
  1738. Protected Mode Exceptions
  1739.  
  1740. None
  1741.  
  1742. Real Address Mode Exceptions
  1743.  
  1744. None
  1745.  
  1746. Virtual 8086 Mode Exceptions
  1747.  
  1748. None
  1749.  
  1750.  
  1751. DEC ── Decrement by 1
  1752.  
  1753. Opcode    Instruction        Clocks   Description
  1754.  
  1755. FE /1     DEC r/m8           2/6      Decrement r/m byte by 1
  1756. FF /1     DEC r/m16          2/6      Decrement r/m word by 1
  1757.           DEC r/m32          2/6      Decrement r/m dword by 1
  1758. 48+rw     DEC r16            2        Decrement word register by 1
  1759. 48+rw     DEC r32            2        Decrement dword register by 1
  1760.  
  1761.  
  1762. Operation
  1763.  
  1764. DEST  DEST - 1;
  1765.  
  1766. Description
  1767.  
  1768. DEC subtracts 1 from the operand. DEC does not change the carry flag.
  1769. To affect the carry flag, use the SUB instruction with an immediate
  1770. operand of 1.
  1771.  
  1772. Flags Affected
  1773.  
  1774. OF, SF, ZF, AF, and PF as described in Appendix C.
  1775.  
  1776. Protected Mode Exceptions
  1777.  
  1778. #GP(0) if the result is a nonwritable segment; #GP(0) for an illegal
  1779. memory operand effective address in the CS, DS, ES, FS, or GS
  1780. segments; #SS(0) for an illegal address in the SS segment; #PF(fault-code)
  1781. for a page fault
  1782.  
  1783. Real Address Mode Exceptions
  1784.  
  1785. Interrupt 13 if any part of the operand would lie outside of the effective
  1786. address space from 0 to 0FFFFH
  1787.  
  1788. Virtual 8086 Mode Exceptions
  1789.  
  1790. Same exceptions as in Real Address Mode; #PF(fault-code) for a page
  1791. fault
  1792.  
  1793.  
  1794. DIV ── Unsigned Divide
  1795.  
  1796. Opcode    Instruction        Clocks   Description
  1797.  
  1798. F6 /6     DIV AL,r/m8        14/17    Unsigned divide AX by r/m byte
  1799.                                       (AL=Quo, AH=Rem)
  1800. F7 /6     DIV AX,r/m16       22/25    Unsigned divide DX:AX by r/m
  1801.                                       word (AX=Quo, DX=Rem)
  1802. F7 /6     DIV EAX,r/m32      38/41    Unsigned divide EDX:EAX by r/m
  1803.                                       dword (EAX=Quo, EDX=Rem)
  1804.  
  1805.  
  1806. Operation
  1807.  
  1808. temp  dividend / divisor;
  1809. IF temp does not fit in quotient
  1810. THEN Interrupt 0;
  1811. ELSE
  1812.    quotient  temp;
  1813.    remainder  dividend MOD (r/m);
  1814. FI;
  1815.  
  1816. ───────────────────────────────────────────────────────────────────────────
  1817. Note:
  1818.   Divisions are unsigned. The divisor is given by the r/m operand.
  1819.   The dividend, quotient, and remainder use implicit registers. Refer to
  1820.   the table under "Description."
  1821. ───────────────────────────────────────────────────────────────────────────
  1822.  
  1823. Description
  1824.  
  1825. DIV performs an unsigned division. The dividend is implicit; only the
  1826. divisor is given as an operand. The remainder is always less than the
  1827. divisor. The type of the divisor determines which registers to use as
  1828. follows:
  1829.  
  1830.     Size    Dividend     Divisor   Quotient   Remainder
  1831.     byte    AX           r/m8       AL          AH
  1832.     word    DX:AX        r/m16      AX          DX
  1833.     dword   EDX:EAX      r/m32      EAX         EDX
  1834.  
  1835. Flags Affected
  1836.  
  1837. OF, SF, ZF, AR, PF, CF are undefined.
  1838.  
  1839. Protected Mode Exceptions
  1840.  
  1841. Interrupt 0 if the quotient is too large to fit in the designated register
  1842. (AL, AX, or EAX), or if the divisor is 0; #GP(0) for an illegal memory
  1843. operand effective address in the CS, DS, ES, FS, or GS segments; #SS(0)
  1844. for an illegal address in the SS segment; #PF(fault-code) for a page fault
  1845.  
  1846. Real Address Mode Exceptions
  1847.  
  1848. Interrupt 0 if the quotient is too big to fit in the designated register
  1849. (AL, AX, or EAX), or if the divisor is 0; Interrupt 13 if any part of the
  1850. operand would lie outside of the effective address space from 0 to 0FFFFH
  1851.  
  1852. Virtual 8086 Mode Exceptions
  1853.  
  1854. Same exceptions as in Real Address Mode; #PF(fault-code) for a page
  1855. fault
  1856.  
  1857.  
  1858. ENTER ── Make Stack Frame for Procedure Parameters
  1859.  
  1860. Opcode      Instruction        Clocks     Description
  1861.  
  1862. C8 iw 00    ENTER imm16,0      10         Make procedure stack frame
  1863. C8 iw 01    ENTER imm16,1      12         Make stack frame for procedure
  1864.                                           parameters
  1865. C8 iw ib    ENTER imm16,imm8   15+4(n-1)  Make stack frame for
  1866.                                           procedure parameters
  1867.  
  1868.  
  1869. Operation
  1870.  
  1871. level  level MOD 32
  1872. IF OperandSize = 16 THEN Push(BP) ELSE Push (EBP) FI;
  1873.    (* Save stack pointer *)
  1874. frame-ptr  eSP
  1875. IF level > 0
  1876. THEN (* level is rightmost parameter *)
  1877.    FOR i  1 TO level - 1
  1878.    DO
  1879.       IF OperandSize = 16
  1880.       THEN
  1881.          BP  BP - 2;
  1882.          Push[BP]
  1883.       ELSE (* OperandSize = 32 *)
  1884.          EBP  EBP - 4;
  1885.          Push[EBP];
  1886.       FI;
  1887.    OD;
  1888.    Push(frame-ptr)
  1889. FI;
  1890. IF OperandSize = 16 THEN BP  frame-ptr ELSE EBP  frame-ptr; FI;
  1891. IF StackAddrSize = 16
  1892. THEN SP  SP - First operand;
  1893. ELSE ESP  ESP - ZeroExtend(First operand);
  1894. FI;
  1895.  
  1896. Description
  1897.  
  1898. ENTER creates the stack frame required by most block-structured
  1899. high-level languages. The first operand specifies the number of bytes of
  1900. dynamic storage allocated on the stack for the routine being entered.
  1901. The second operand gives the lexical nesting level (0 to 31) of the routine
  1902. within the high-level language source code. It determines the number of
  1903. stack frame pointers copied into the new stack frame from the preceding
  1904. frame. BP (or EBP, if the operand-size attribute is 32 bits) is the current
  1905. stack frame pointer.
  1906.  
  1907. If the operand-size attribute is 16 bits, the processor uses BP as the
  1908. frame pointer and SP as the stack pointer. If the operand-size attribute is
  1909. 32 bits, the processor uses EBP for the frame pointer and ESP for the stack
  1910. pointer.
  1911.  
  1912. If the second operand is 0, ENTER pushes the frame pointer (BP or
  1913. EBP) onto the stack; ENTER then subtracts the first operand from the
  1914. stack pointer and sets the frame pointer to the current stack-pointer
  1915. value.
  1916.  
  1917. For example, a procedure with 12 bytes of local variables would have an
  1918. ENTER 12,0 instruction at its entry point and a LEAVE instruction
  1919. before every RET. The 12 local bytes would be addressed as negative
  1920. offsets from the frame pointer.
  1921.  
  1922. Flags Affected
  1923.  
  1924. None
  1925.  
  1926. Protected Mode Exceptions
  1927.  
  1928. #SS(0) if SP or ESP would exceed the stack limit at any point during
  1929. instruction execution; #PF(fault-code) for a page fault
  1930.  
  1931. Real Address Mode Exceptions
  1932.  
  1933. None
  1934.  
  1935. Virtual 8086 Mode Exceptions
  1936.  
  1937. None
  1938.  
  1939.  
  1940. HLT ── Halt
  1941.  
  1942. Opcode      Instruction        Clocks     Description
  1943.  
  1944. F4          HLT                5          Halt
  1945.  
  1946.  
  1947. Operation
  1948.  
  1949. Enter Halt state;
  1950.  
  1951. Description
  1952.  
  1953. HALT stops instruction execution and places the 80386 in a HALT state.
  1954. An enabled interrupt, NMI, or a reset will resume execution. If an
  1955. interrupt (including NMI) is used to resume execution after HLT, the saved
  1956. CS:IP (or CS:EIP) value points to the instruction following HLT.
  1957.  
  1958. Flags Affected
  1959.  
  1960. None
  1961.  
  1962. Protected Mode Exceptions
  1963.  
  1964. HLT is a privileged instruction; #GP(0) if the current privilege level is
  1965. not 0
  1966.  
  1967. Real Address Mode Exceptions
  1968.  
  1969. None
  1970.  
  1971. Virtual 8086 Mode Exceptions
  1972.  
  1973. #GP(0); HLT is a privileged instruction
  1974.  
  1975.  
  1976. IDIV ── Signed Divide
  1977.  
  1978. Opcode      Instruction        Clocks   Description
  1979.  
  1980. F6 /7       IDIV r/m8          19       Signed divide AX by r/m byte
  1981.                                         (AL=Quo, AH=Rem)
  1982. F7 /7       IDIV AX,r/m16      27       Signed divide DX:AX by EA word
  1983.                                         (AX=Quo, DX=Rem)
  1984. F7 /7       IDIV EAX,r/m32     43       Signed divide EDX:EAX by DWORD
  1985.                                         byte (EAX=Quo, EDX=Rem)
  1986.  
  1987.  
  1988. Operation
  1989.  
  1990. temp  dividend / divisor;
  1991. IF temp does not fit in quotient
  1992. THEN Interrupt 0;
  1993. ELSE
  1994.    quotient  temp;
  1995.    remainder  dividend MOD (r/m);
  1996. FI;
  1997.  
  1998. ───────────────────────────────────────────────────────────────────────────
  1999. Notes:
  2000.   Divisions are signed. The divisor is given by the r/m operand. The
  2001.   dividend, quotient, and remainder use implicit registers. Refer to the
  2002.   table under "Description."
  2003. ───────────────────────────────────────────────────────────────────────────
  2004.  
  2005. Description
  2006.  
  2007. IDIV performs a signed division. The dividend, quotient, and remainder
  2008. are implicitly allocated to fixed registers. Only the divisor is given as
  2009. an explicit r/m operand. The type of the divisor determines which registers
  2010. to use as follows:
  2011.  
  2012. Size     Divisor    Quotient    Remainder  Dividend
  2013. byte     r/m8        AL           AH       AX
  2014. word     r/m16       AX           DX       DX:AX
  2015. dword    r/m32       EAX          EDX      EDX:EAX
  2016.  
  2017. If the resulting quotient is too large to fit in the destination, or if the
  2018. division is 0, an Interrupt 0 is generated. Nonintegral quotients are
  2019. truncated toward 0. The remainder has the same sign as the dividend
  2020. and the absolute value of the remainder is always less than the absolute
  2021. value of the divisor.
  2022.  
  2023. Flags Affected
  2024.  
  2025. OF, SF, ZF, AR, PF, CF are undefined.
  2026.  
  2027. Protected Mode Exceptions
  2028.  
  2029. Interrupt 0 if the quotient is too large to fit in the designated register
  2030. (AL or AX), or if the divisor is 0; #GP (0) for an illegal memory operand
  2031. effective address in the CS, DS, ES, FS, or GS segments; #SS(0) for an
  2032. illegal address in the SS segment; #PF(fault-code) for a page fault
  2033.  
  2034. Real Address Mode Exceptions
  2035.  
  2036. Interrupt 0 if the quotient is too large to fit in the designated register
  2037. (AL or AX), or if the divisor is 0; Interrupt 13 if any part of the operand
  2038. would lie outside of the effective address space from 0 to 0FFFFH
  2039.  
  2040. Virtual 8086 Mode Exceptions
  2041.  
  2042. Same exceptions as in Real Address Mode; #PF(fault-code) for a page
  2043. fault
  2044.  
  2045.  
  2046. IMUL ── Signed Multiply
  2047.  
  2048.  
  2049. Opcode      Instruction            Clocks      Description
  2050.  
  2051. F6  /5      IMUL r/m8              9-14/12-17  AX AL * r/m byte
  2052. F7  /5      IMUL r/m16             9-22/12-25  DX:AX  AX * r/m word
  2053. F7  /5      IMUL r/m32             9-38/12-41  EDX:EAX  EAX * r/m dword
  2054. 0F  AF /r   IMUL r16,r/m16         9-22/12-25  word register  word
  2055.                                                register * r/m word
  2056. 0F  AF /r   IMUL r32,r/m32         9-38/12-41  dword register  dword
  2057.                                                register * r/m dword
  2058. 6B  /r ib   IMUL r16,r/m16,imm8    9-14/12-17  word register  r/m16 *
  2059.                                                sign-extended immediate byte
  2060. 6B  /r ib   IMUL r32,r/m32,imm8    9-14/12-17  dword register  r/m32 *
  2061.                                                sign-extended immediate byte
  2062. 6B  /r ib   IMUL r16,imm8          9-14/12-17  word register  word
  2063.                                                register * sign-extended
  2064.                                                immediate byte
  2065. 6B  /r ib   IMUL r32,imm8          9-14/12-17  dword register  dword
  2066.                                                register * sign-extended
  2067.                                                immediate byte
  2068. 69  /r iw   IMUL r16,r/m16,imm16   9-22/12-25  word register  r/m16 *
  2069.                                                immediate word
  2070. 69  /r id   IMUL r32,r/m32,imm32   9-38/12-41  dword register  r/m32 *
  2071.                                                immediate dword
  2072. 69  /r iw   IMUL r16,imm16         9-22/12-25  word register  r/m16 *
  2073.                                                immediate word
  2074. 69  /r id   IMUL r32,imm32         9-38/12-41  dword register  r/m32 *
  2075.                                                immediate dword
  2076.  
  2077.  
  2078. ───────────────────────────────────────────────────────────────────────────
  2079. NOTES:
  2080.   The 80386 uses an early-out multiply algorithm. The actual number of
  2081.   clocks depends on the position of the most significant bit in the
  2082.   optimizing multiplier, shown underlined above. The optimization occurs for
  2083.   positive and negative values. Because of the early-out algorithm, clock
  2084.   counts given are minimum to maximum. To calculate the actual clocks, use
  2085.   the following formula:
  2086. ───────────────────────────────────────────────────────────────────────────
  2087.  
  2088.   Actual clock = if m <> 0 then max(ceiling(log{2} │m│), 3) + 6 clocks  
  2089.   Actual clock = if m = 0 then 9 clocks   
  2090.   (where m is the multiplier)
  2091.  
  2092. Add three clocks if the multiplier is a memory operand.
  2093.  
  2094. Operation
  2095.  
  2096. result  multiplicand * multiplier;
  2097.  
  2098. Description
  2099.  
  2100. IMUL performs signed multiplication. Some forms of the instruction
  2101. use implicit register operands. The operand combinations for all forms
  2102. of the instruction are shown in the "Description" column above.
  2103.  
  2104. IMUL clears the overflow and carry flags under the following conditions:
  2105.  
  2106.    Instruction Form    Condition for Clearing CF and OF
  2107.    r/m8                AL = sign-extend of AL to 16 bits
  2108.    r/m16               AX = sign-extend of AX to 32 bits
  2109.    r/m32               EDX:EAX = sign-extend of EAX to 32 bits
  2110.    r16,r/m16           Result exactly fits within r16
  2111.    r/32,r/m32          Result exactly fits within r32
  2112.    r16,r/m16,imm16     Result exactly fits within r16
  2113.    r32,r/m32,imm32     Result exactly fits within r32
  2114.  
  2115. Flags Affected
  2116.  
  2117. OF and CF as described above; SF, ZF, AF, and PF are undefined
  2118.  
  2119. Protected Mode Exceptions
  2120.  
  2121. #GP(0) for an illegal memory operand effective address in the CS, DS,
  2122. ES, FS, or GS segments; #SS(0) for an illegal address in the SS segment;
  2123. #PF(fault-code) for a page fault
  2124.  
  2125. Real Address Mode Exceptions
  2126.  
  2127. Interrupt 13 if any part of the operand would lie outside of the effective
  2128. address space from 0 to 0FFFFH
  2129.  
  2130. Virtual 8086 Mode Exceptions
  2131.  
  2132. Same exeptions as in Real Address Mode; #PF(fault-code) for a page
  2133. fault
  2134.  
  2135. Notes
  2136.  
  2137. When using the accumulator forms (IMUL r/m8, IMUL r/m16, or IMUL
  2138. r/m32), the result of the multiplication is available even if the overflow
  2139. flag is set because the result is two times the size of the multiplicand
  2140. and multiplier. This is large enough to handle any possible result.
  2141.  
  2142.  
  2143. IN ── Input from Port
  2144.  
  2145. Opcode    Instruction   Clocks            Description
  2146.  
  2147. E4  ib    IN AL,imm8    12,pm=6*/26**     Input byte from immediate port
  2148.                                           into AL
  2149. E5  ib    IN AX,imm8    12,pm=6*/26**     Input word from immediate port
  2150.                                           into AX
  2151. E5  ib    IN EAX,imm8   12,pm=6*/26**     Input dword from immediate port
  2152.                                           into EAX
  2153. EC        IN AL,DX      13,pm=7*/27**     Input byte from port DX into AL
  2154. ED        IN AX,DX      13,pm=7*/27**     Input word from port DX into AX
  2155. ED        IN EAX,DX     13,pm=7*/27**     Input dword from port DX into
  2156.                                           EAX
  2157.  
  2158.  
  2159. ───────────────────────────────────────────────────────────────────────────
  2160. NOTES:
  2161.    *If CPL ≤ IOPL
  2162.   **If CPL > IOPL or if in virtual 8086 mode
  2163. ───────────────────────────────────────────────────────────────────────────
  2164.  
  2165. Operation
  2166.  
  2167. IF (PE = 1) AND ((VM = 1) OR (CPL > IOPL))
  2168. THEN (* Virtual 8086 mode, or protected mode with CPL > IOPL *)
  2169.    IF NOT I-O-Permission (SRC, width(SRC))
  2170.    THEN #GP(0);
  2171.    FI;
  2172. FI;
  2173. DEST  [SRC]; (* Reads from I/O address space *)
  2174.  
  2175. Description
  2176.  
  2177. IN transfers a data byte or data word from the port numbered by the
  2178. second operand into the register (AL, AX, or EAX) specified by the first
  2179. operand. Access any port from 0 to 65535 by placing the port number
  2180. in the DX register and using an IN instruction with DX as the second
  2181. parameter. These I/O instructions can be shortened by using an 8-bit
  2182. port I/O in the instruction. The upper eight bits of the port address will
  2183. be 0 when 8-bit port I/O is used.
  2184.  
  2185. Flags Affected
  2186.  
  2187. None
  2188.  
  2189. Protected Mode Exceptions
  2190.  
  2191. #GP(0) if the current privilege level is larger (has less privilege) than
  2192. IOPL and any of the corresponding I/O permission bits in TSS equals 1
  2193.  
  2194. Real Address Mode Exceptions
  2195.  
  2196. None
  2197.  
  2198. Virtual 8086 Mode Exceptions
  2199.  
  2200. #GP(0) fault if any of the corresponding I/O permission bits in TSS
  2201. equals 1
  2202.  
  2203.  
  2204. INC ── Increment by 1
  2205.  
  2206. Opcode      Instruction        Clocks      Description
  2207.  
  2208. FE  /0      INC r/m8                       Increment r/m byte by 1
  2209. FF  /0      INC r/m16                      Increment r/m word by 1
  2210. FF  /6      INC r/m32                      Increment r/m dword by 1
  2211. 40 + rw     INC r16                        Increment word register by 1
  2212. 40 + rd     INC r32                        Increment dword register by 1
  2213.  
  2214.  
  2215. Operation
  2216.  
  2217. DEST  DEST + 1;
  2218.  
  2219. Description
  2220.  
  2221. INC adds 1 to the operand. It does not change the carry flag. To affect
  2222. the carry flag, use the ADD instruction with a second operand of 1.
  2223.  
  2224. Flags Affected
  2225.  
  2226. OF, SF, ZF, AF, and PF as described in Appendix C
  2227.  
  2228. Protected Mode Exceptions
  2229.  
  2230. #GP(0) if the operand is in a nonwritable segment; #GP(0) for an illegal
  2231. memory operand effective address in the CS, DS, ES, FS, or GS
  2232. segments; #SS(0) for an illegal address in the SS segment; #PF(fault-code)
  2233. for a page fault
  2234.  
  2235. Real Address Mode Exceptions
  2236.  
  2237. Interrupt 13 if any part of the operand would lie outside of the effective
  2238. address space from 0 to 0FFFFH
  2239.  
  2240. Virtual 8086 Mode Exceptions
  2241.  
  2242. Same exceptions as in Real Address Mode; #PF(fault-code) for a page
  2243. fault
  2244.  
  2245.  
  2246. INS/INSB/INSW/INSD ── Input from Port to String
  2247.  
  2248. Opcode  Instruction    Clocks         Description
  2249.  
  2250. 6C      INS r/m8,DX    15,pm=9*/29**  Input byte from port DX into ES:(E)DI
  2251. 6D      INS r/m16,DX   15,pm=9*/29**  Input word from port DX into ES:(E)DI
  2252. 6D      INS r/m32,DX   15,pm=9*/29**  Input dword from port DX into ES:(E)DI
  2253. 6C      INSB           15,pm=9*/29**  Input byte from port DX into ES:(E)DI
  2254. 6D      INSW           15,pm=9*/29**  Input word from port DX into ES:(E)DI
  2255. 6D      INSD           15,pm=9*/29**  Input dword from port DX into ES:(E)DI
  2256.  
  2257.  
  2258. ───────────────────────────────────────────────────────────────────────────
  2259. NOTES:
  2260.    *If CPL ≤ IOPL
  2261.   **If CPL > IOPL or if in virtual 8086 mode
  2262. ───────────────────────────────────────────────────────────────────────────
  2263.  
  2264. Operation
  2265.  
  2266. IF AddressSize = 16
  2267. THEN use DI for dest-index;
  2268. ELSE (* AddressSize = 32 *)
  2269.    use EDI for dest-index;
  2270. FI;
  2271. IF (PE = 1) AND ((VM = 1) OR (CPL > IOPL))
  2272. THEN (* Virtual 8086 mode, or protected mode with CPL > IOPL *)
  2273.    IF NOT I-O-Permission (SRC, width(SRC))
  2274.    THEN #GP(0);
  2275.    FI;
  2276. FI;
  2277. IF byte type of instruction
  2278. THEN
  2279.    ES:[dest-index]  [DX]; (* Reads byte at DX from I/O address space *)
  2280.    IF DF = 0 THEN IncDec  1 ELSE IncDec  -1; FI;
  2281. FI;
  2282. IF OperandSize = 16
  2283. THEN
  2284.    ES:[dest-index]  [DX]; (* Reads word at DX from I/O address space *)
  2285.    IF DF = 0 THEN IncDec  2 ELSE IncDec  -2; FI;
  2286. FI;
  2287. IF OperandSize = 32
  2288. THEN
  2289.    ES:[dest-index]  [DX]; (* Reads dword at DX from I/O address space *)
  2290.    IF DF = 0 THEN IncDec  4 ELSE IncDec  -4; FI;
  2291. FI;
  2292. dest-index  dest-index + IncDec;
  2293.  
  2294. Description
  2295.  
  2296. INS transfers data from the input port numbered by the DX register to
  2297. the memory byte or word at ES:dest-index. The memory operand must
  2298. be addressable from ES; no segment override is possible. The destination
  2299. register is DI if the address-size attribute of the instruction is 16 bits,
  2300. or EDI if the address-size attribute is 32 bits.
  2301.  
  2302. INS does not allow the specification of the port number as an immediate
  2303. value. The port must be addressed through the DX register value. Load
  2304. the correct value into DX before executing the INS instruction.
  2305.  
  2306. The destination address is determined by the contents of the destination
  2307. index register. Load the correct index into the destination index register
  2308. before executing INS.
  2309.  
  2310. After the transfer is made, DI or EDI advances automatically. If the
  2311. direction flag is 0 (CLD was executed), DI or EDI increments; if the
  2312. direction flag is 1 (STD was executed), DI or EDI decrements. DI
  2313. increments or decrements by 1 if a byte is input, by 2 if a word is input,
  2314. or by 4 if a doubleword is input.
  2315.  
  2316. INSB, INSW and INSD are synonyms of the byte, word, and doubleword
  2317. INS instructions. INS can be preceded by the REP prefix for block input of
  2318. CX bytes or words. Refer to the REP instruction for details of this
  2319. operation.
  2320.  
  2321. Flags Affected
  2322.  
  2323. None
  2324.  
  2325. Protected Mode Exceptions
  2326.  
  2327. #GP(0) if CPL is numerically greater than IOPL and any of the
  2328. corresponding I/O permission bits in TSS equals 1; #GP(0) if the
  2329. destination is in a nonwritable segment; #GP(0) for an illegal memory
  2330. operand effective address in the CS, DS, ES, FS, or GS segments; #SS(0) for
  2331. an illegal address in the SS segment; #PF(fault-code) for a page fault
  2332.  
  2333. Real Address Mode Exceptions
  2334.  
  2335. Interrupt 13 if any part of the operand would lie outside of the effective
  2336. address space from 0 to 0FFFFH
  2337.  
  2338. Virtual 8086 Mode Exceptions
  2339.  
  2340. #GP(0) fault if any of the corresponding I/O permission bits in TSS
  2341. equals 1; #PF(fault-code) for a page fault
  2342.  
  2343.  
  2344. INT/INTO ── Call to Interrupt Procedure
  2345.  
  2346.  
  2347. Opcode    Instruction  Clocks          Description
  2348.  
  2349. CC        INT 3        33              Interrupt 3--trap to debugger
  2350. CC        INT 3        pm=59           Interrupt 3--Protected Mode, same
  2351.                                        privilege
  2352. CC        INT 3        pm=99           Interrupt 3--Protected Mode, more
  2353.                                        privilege
  2354. CC        INT 3        pm=119          Interrupt 3--from V86 mode to PL 0
  2355. CC        INT 3        ts              Interrupt 3--Protected Mode, via
  2356.                                        task gate
  2357. CD ib     INT imm8     37              Interrupt numbered by immediate
  2358.                                        byte
  2359. CD ib     INT imm8     pm=59           Interrupt--Protected Mode, same
  2360.                                        privilege
  2361. CD ib     INT imm8     pm=99           Interrupt--Protected Mode, more
  2362.                                        privilege
  2363. CD ib     INT imm8     pm=119          Interrupt--from V86 mode to PL 0
  2364. CD ib     INT imm8     ts              Interrupt--Protected Mode, via task
  2365.                                        gate
  2366. CE        INTO         Fail:3,pm=3;
  2367.                        Pass:35         Interrupt 4--if overflow flag is 1
  2368. CE        INTO         pm=59           Interrupt 4--Protected Mode, same
  2369.                                        privilege
  2370. CE        INTO         pm=99           Interrupt 4--Protected Mode, more
  2371.                                        privilege
  2372. CE        INTO         pm=119          Interrupt 4--from V86 mode to PL 0
  2373. CE        INTO         ts              Interrupt 4--Protected Mode, via
  2374.                                        task gate
  2375.  
  2376.  
  2377. ───────────────────────────────────────────────────────────────────────────
  2378. NOTE:
  2379.   Approximate values of ts are given by the following table:
  2380.  
  2381.                             New Task
  2382.  
  2383. Old Task       386 TSS       386 TSS       286 TSS
  2384.                VM = 0        VM = 1
  2385.  
  2386. 386
  2387. TSS VM=0         309           226           282
  2388.  
  2389. 386
  2390. TSS VM=1         314           231           287
  2391.  
  2392. 286
  2393. TSS              307           224           280
  2394. ───────────────────────────────────────────────────────────────────────────
  2395.  
  2396. Operation
  2397.  
  2398. ───────────────────────────────────────────────────────────────────────────
  2399. NOTE:
  2400.   The following operational description applies not only to the
  2401.   above instructions but also to external interrupts and exceptions.
  2402. ───────────────────────────────────────────────────────────────────────────
  2403.  
  2404. IF PE = 0
  2405. THEN GOTO REAL-ADDRESS-MODE;
  2406. ELSE GOTO PROTECTED-MODE;
  2407. FI;
  2408.  
  2409. REAL-ADDRESS-MODE:
  2410.    Push (FLAGS);
  2411.    IF  0; (* Clear interrupt flag *)
  2412.    TF  0; (* Clear trap flag *)
  2413.    Push(CS);
  2414.    Push(IP);
  2415.    (* No error codes are pushed *)
  2416.    CS  IDT[Interrupt number * 4].selector;
  2417.    IP  IDT[Interrupt number * 4].offset;
  2418.  
  2419. PROTECTED-MODE:
  2420.    Interrupt vector must be within IDT table limits,
  2421.       else #GP(vector number * 8+2+EXT);
  2422.    Descriptor AR byte must indicate interrupt gate, trap gate, or task gate,
  2423.       else #GP(vector number * 8+2+EXT);
  2424.    IF software interrupt (* i.e. caused by INT n, INT 3, or INTO *)
  2425.    THEN
  2426.       IF gate descriptor DPL < CPL
  2427.       THEN #GP(vector number * 8+2+EXT);
  2428.       FI;
  2429.    FI;
  2430.    Gate must be present, else #NP(vector number * 8+2+EXT);
  2431.    IF trap gate OR interrupt gate
  2432.    THEN GOTO TRAP-GATE-OR-INTERRUPT-GATE;
  2433.    ELSE GOTO TASK-GATE;
  2434.    FI;
  2435.  
  2436. TRAP-GATE-OR-INTERRUPT-GATE:
  2437.    Examine CS selector and descriptor given in the gate descriptor;
  2438.    Selector must be non-null, else #GP (EXT);
  2439.    Selector must be within its descriptor table limits
  2440.       ELSE #GP(selector+EXT);
  2441.    Descriptor AR byte must indicate code segment
  2442.       ELSE #GP(selector + EXT);
  2443.    Segment must be present, else #NP(selector+EXT);
  2444.    IF code segment is non-conforming AND DPL < CPL
  2445.    THEN GOTO INTERRUPT-TO-INNER-PRIVILEGE;
  2446.    ELSE
  2447.       IF code segment is conforming OR code segment DPL = CPL
  2448.       THEN GOTO INTERRUPT-TO-SAME-PRIVILEGE-LEVEL;
  2449.       ELSE #GP(CS selector + EXT);
  2450.       FI;
  2451.    FI;
  2452.  
  2453. INTERRUPT-TO-INNER-PRIVILEGE:
  2454.    Check selector and descriptor for new stack in current TSS;
  2455.       Selector must be non-null, else #GP(EXT);
  2456.       Selector index must be within its descriptor table limits
  2457.          ELSE #TS(SS selector+EXT);
  2458.       Selector's RPL must equal DPL of code segment, else #TS(SS
  2459.          selector+EXT);
  2460.       Stack segment DPL must equal DPL of code segment, else #TS(SS
  2461.          selector+EXT);
  2462.       Descriptor must indicate writable data segment, else #TS(SS
  2463.          selector+EXT);
  2464.       Segment must be present, else #SS(SS selector+EXT);
  2465.    IF 32-bit gate
  2466.    THEN New stack must have room for 20 bytes else #SS(0)
  2467.    ELSE New stack must have room for 10 bytes else #SS(0)
  2468.    FI;
  2469.    Instruction pointer must be within CS segment boundaries else #GP(0);
  2470.    Load new SS and eSP value from TSS;
  2471.    IF 32-bit gate
  2472.    THEN CS:EIP  selector:offset from gate;
  2473.    ELSE CS:IP  selector:offset from gate;
  2474.    FI;
  2475.    Load CS descriptor into invisible portion of CS register;
  2476.    Load SS descriptor into invisible portion of SS register;
  2477.    IF 32-bit gate
  2478.    THEN
  2479.       Push (long pointer to old stack) (* 3 words padded to 4 *);
  2480.       Push (EFLAGS);
  2481.       Push (long pointer to return location) (* 3 words padded to 4*);
  2482.    ELSE
  2483.       Push (long pointer to old stack) (* 2 words *);
  2484.       Push (FLAGS);
  2485.       Push (long pointer to return location) (* 2 words *);
  2486.    FI;
  2487.    Set CPL to new code segment DPL;
  2488.    Set RPL of CS to CPL;
  2489.    IF interrupt gate THEN IF  0 (* interrupt flag to 0 (disabled) *); FI;
  2490.    TF  0;
  2491.    NT  0;
  2492.  
  2493. INTERRUPT-FROM-V86-MODE:
  2494.    TempEFlags  EFLAGS;
  2495.    VM  0;
  2496.    TF  0;
  2497.    IF service through Interrupt Gate THEN IF  0;
  2498.    TempSS  SS;
  2499.    TempESP  ESP;
  2500.    SS  TSS.SS0; (* Change to level 0 stack segment *)
  2501.    ESP  TSS.ESP0; (* Change to level 0 stack pointer *)
  2502.    Push(GS); (* padded to two words *)
  2503.    Push(FS); (* padded to two words *)
  2504.    Push(DS); (* padded to two words *)
  2505.    Push(ES); (* padded to two words *)
  2506.    GS  0;
  2507.    FS  0;
  2508.    DS  0;
  2509.    ES  0;
  2510.    Push(TempSS); (* padded to two words *)
  2511.    Push(TempESP);
  2512.    Push(TempEFlags);
  2513.    Push(CS); (* padded to two words *)
  2514.    Push(EIP);
  2515.    CS:EIP  selector:offset from interrupt gate;
  2516.    (* Starts execution of new routine in 80386 Protected Mode *)
  2517.  
  2518. INTERRUPT-TO-SAME-PRIVILEGE-LEVEL:
  2519.    IF 32-bit gate
  2520.    THEN Current stack limits must allow pushing 10 bytes, else #SS(0);
  2521.    ELSE Current stack limits must allow pushing 6 bytes, else #SS(0);
  2522.    FI;
  2523.    IF interrupt was caused by exception with error code
  2524.    THEN Stack limits must allow push of two more bytes;
  2525.    ELSE #SS(0);
  2526.    FI;
  2527.    Instruction pointer must be in CS limit, else #GP(0);
  2528.    IF 32-bit gate
  2529.    THEN
  2530.       Push (EFLAGS);
  2531.       Push (long pointer to return location); (* 3 words padded to 4 *)
  2532.       CS:EIP  selector:offset from gate;
  2533.    ELSE (* 16-bit gate *)
  2534.       Push (FLAGS);
  2535.       Push (long pointer to return location); (* 2 words *)
  2536.       CS:IP  selector:offset from gate;
  2537.    FI;
  2538.    Load CS descriptor into invisible portion of CS register;
  2539.    Set the RPL field of CS to CPL;
  2540.    Push (error code); (* if any *)
  2541.    IF interrupt gate THEN IF  0; FI;
  2542.    TF  0;
  2543.    NT  0;
  2544.  
  2545. TASK-GATE:
  2546.    Examine selector to TSS, given in task gate descriptor;
  2547.       Must specify global in the local/global bit, else #TS(TSS selector);
  2548.       Index must be within GDT limits, else #TS(TSS selector);
  2549.       AR byte must specify available TSS (bottom bits 00001),
  2550.          else #TS(TSS selector;
  2551.       TSS must be present, else #NP(TSS selector);
  2552.    SWITCH-TASKS with nesting to TSS;
  2553.    IF interrupt was caused by fault with error code
  2554.    THEN
  2555.       Stack limits must allow push of two more bytes, else #SS(0);
  2556.       Push error code onto stack;
  2557.    FI;
  2558.    Instruction pointer must be in CS limit, else #GP(0);
  2559.  
  2560. Description
  2561.  
  2562. The INT  instruction generates via software a call to an interrupt
  2563. handler. The immediate operand, from 0 to 255, gives the index number
  2564. into the Interrupt Descriptor Table (IDT) of the interrupt routine to be
  2565. called. In Protected Mode, the IDT consists of an array of eight-byte
  2566. descriptors; the descriptor for the interrupt invoked must indicate an
  2567. interrupt, trap, or task gate. In Real Address Mode, the IDT is an array
  2568. of four byte-long pointers. In Protected and Real Address Modes, the
  2569. base linear address of the IDT is defined by the contents of the IDTR.
  2570.  
  2571. The INTO conditional software instruction is identical to the INT
  2572. interrupt instruction except that the interrupt number is implicitly 4,
  2573. and the interrupt is made only if the 80386 overflow flag is set.
  2574.  
  2575. The first 32 interrupts are reserved by Intel for system use. Some of
  2576. these interrupts are use for internally generated exceptions.
  2577.  
  2578. INT n generally behaves like a far call except that the flags register is
  2579. pushed onto the stack before the return address. Interrupt procedures
  2580. return via the IRET instruction, which pops the flags and return address
  2581. from the stack.
  2582.  
  2583. In Real Address Mode, INT n pushes the flags, CS, and the return IP
  2584. onto the stack, in that order, then jumps to the long pointer indexed by
  2585. the interrupt number.
  2586.  
  2587. Flags Affected
  2588.  
  2589. None
  2590.  
  2591. Protected Mode Exceptions
  2592.  
  2593. #GP, #NP, #SS, and #TS as indicated under "Operation" above
  2594.  
  2595. Real Address Mode Exceptions
  2596.  
  2597. None; if the SP or ESP = 1, 3, or 5 before executing INT or INTO,
  2598. the 80386 will shut down due to insufficient stack space
  2599.  
  2600. Virtual 8086 Mode Exceptions
  2601.  
  2602. #GP(0) fault if IOPL is less than 3, for INT  only, to permit emulation;
  2603. Interrupt 3 (0CCH) generates Interrupt 3; INTO generates Interrupt 4
  2604. if the overflow flag equals 1
  2605.  
  2606.  
  2607. IRET/IRETD ── Interrupt Return
  2608.  
  2609. Opcode  Instruction  Clocks       Description
  2610.  
  2611. CF      IRET         22,pm=38     Interrupt return (far return and pop
  2612.                                   flags)
  2613. CF      IRET         pm=82        Interrupt return to lesser privilege
  2614. CF      IRET         ts           Interrupt return, different task (NT = 1)
  2615. CF      IRETD        22,pm=38     Interrupt return (far return and pop
  2616.                                   flags)
  2617. CF      IRETD        pm=82        Interrupt return to lesser privilege
  2618. CF      IRETD        pm=60        Interrupt return to V86 mode
  2619. CF      IRETD        ts           Interrupt return, different task (NT = 1)
  2620.  
  2621.  
  2622. ───────────────────────────────────────────────────────────────────────────
  2623. NOTE:
  2624.   Values of ts are given by the following table:
  2625.  
  2626.                             New Task
  2627.  
  2628. Old Task       386 TSS       386 TSS       286 TSS
  2629.                VM = 0        VM = 1
  2630.  
  2631. 386
  2632. TSS VM=0         275           224           271
  2633.  
  2634. 286
  2635. TSS              265           214           232
  2636. ───────────────────────────────────────────────────────────────────────────
  2637.  
  2638. Operation
  2639.  
  2640. IF PE = 0
  2641. THEN (* Real-address mode *)
  2642.    IF OperandSize = 32 (* Instruction = IRETD *)
  2643.    THEN EIP  Pop();
  2644.    ELSE (* Instruction = IRET *)
  2645.       IP  Pop();
  2646.    FI;
  2647.    CS  Pop();
  2648.    IF OperandSize = 32 (* Instruction = IRETD *)
  2649.    THEN EFLAGS  Pop();
  2650.    ELSE (* Instruction = IRET *)
  2651.       FLAGS  Pop();
  2652.    FI;
  2653. ELSE (* Protected mode *)
  2654.    IF VM = 1
  2655.    THEN #GP(0);
  2656.    ELSE
  2657.       IF NT = 1
  2658.       THEN GOTO TASK-RETURN;
  2659.       ELSE
  2660.          IF VM = 1 in flags image on stack
  2661.          THEN GO TO STACK-RETURN-TO-V86;
  2662.          ELSE GOTO STACK-RETURN;
  2663.          FI;
  2664.       FI;
  2665.    FI;
  2666. FI;STACK-RETURN-TO-V86: (* Interrupted procedure was in V86 mode *)
  2667.    IF return CS selector RPL < > 3
  2668.    THEN #GP(Return selector);
  2669.    FI;
  2670.    IF top 36 bytes of stack not within limits
  2671.    THEN #SS(0);
  2672.    FI;
  2673.    Examine return CS selector and associated descriptor:
  2674.       IF selector is null, THEN #GP(0); FI;
  2675.       IF selector index not within its descriptor table limits;
  2676.       THEN #GP(Return selector);
  2677.       FI;
  2678.       IF AR byte does not indicate code segment
  2679.       THEN #GP(Return selector);
  2680.       FI;
  2681.       IF code segment DPL not = 3;
  2682.       THEN #GP(Return selector);
  2683.       FI;
  2684.       IF code segment not present
  2685.       THEN #NP(Return selector);
  2686.       FI;
  2687.  
  2688.    Examine return SS selector and associated descriptor:
  2689.       IF selector is null THEN #GP(0); FI;
  2690.       IF selector index not within its descriptor table limits
  2691.       THEN #GP(SS selector);
  2692.       FI;
  2693.       IF selector RPL not = RPL of return CS selector
  2694.       THEN #GP(SS selector);
  2695.       FI;
  2696.       IF AR byte does not indicate a writable data segment
  2697.       THEN #GP(SS selector);
  2698.       FI;
  2699.       IF stack segment DPL not = RPL of return CS selector
  2700.       THEN #GP(SS selector);
  2701.       FI;
  2702.       IF SS not present
  2703.       THEN #NP(SS selector);
  2704.       FI;
  2705.  
  2706.    IF instruction pointer not within code segment limit  THEN #GP(0);
  2707.    FI;
  2708.    EFLAGS  SS:[eSP + 8]; (* Sets VM in interrupted routine *)
  2709.    EIP  Pop();
  2710.    CS  Pop(); (* CS behaves as in 8086, due to VM = 1 *)
  2711.    throwaway  Pop(); (* pop away EFLAGS already read *)
  2712.    ES  Pop(); (* pop 2 words; throw away high-order word *)
  2713.    DS  Pop(); (* pop 2 words; throw away high-order word *)
  2714.    FS  Pop(); (* pop 2 words; throw away high-order word *)
  2715.    GS  Pop(); (* pop 2 words; throw away high-order word *)
  2716.    IF CS.RPL > CPL
  2717.    THEN
  2718.       TempESP  Pop();
  2719.       TempSS  Pop();
  2720.       SS:ESP  TempSS:TempESP;
  2721.    FI;
  2722.  
  2723.    (* Resume execution in Virtual 8086 mode *)
  2724.  
  2725. TASK-RETURN:
  2726.    Examine Back Link Selector in TSS addressed by the current task
  2727.       register:
  2728.       Must specify global in the local/global bit, else #TS(new TSS
  2729.          selector);
  2730.       Index must be within GDT limits, else #TS(new TSS selector);
  2731.       AR byte must specify TSS, else #TS(new TSS selector);
  2732.       New TSS must be busy, else #TS(new TSS selector);
  2733.       TSS must be present, else #NP(new TSS selector);
  2734.    SWITCH-TASKS without nesting to TSS specified by back link selector;
  2735.    Mark the task just abandoned as NOT BUSY;
  2736.    Instruction pointer must be within code segment limit ELSE #GP(0);
  2737.  
  2738. STACK-RETURN:
  2739.    IF OperandSize=32
  2740.    THEN Third word on stack must be within stack limits, else #SS(0);
  2741.    ELSE Second word on stack must be within stack limits, else #SS(0);
  2742.    FI;
  2743.    Return CS selector RPL must be ≥ CPL, else #GP(Return selector);
  2744.    IF return selector RPL = CPL
  2745.    THEN GOTO RETURN-SAME-LEVEL;
  2746.    ELSE GOTO RETURN-OUTER-LEVEL;
  2747.    FI;
  2748.  
  2749. RETURN-SAME-LEVEL:
  2750.    IF OperandSize=32
  2751.    THEN
  2752.       Top 12 bytes on stack must be within limits, else #SS(0);
  2753.       Return CS selector (at eSP+4) must be non-null, else #GP(0);
  2754.    ELSE
  2755.       Top 6 bytes on stack must be within limits, else #SS(0);
  2756.       Return CS selector (at eSP+2) must be non-null, else #GP(0);
  2757.    FI;
  2758.    Selector index must be within its descriptor table limits, else #GP
  2759.       (Return selector);
  2760.    AR byte must indicate code segment, else #GP(Return selector);
  2761.    IF non-conforming
  2762.    THEN code segment DPL must = CPL;
  2763.    ELSE #GP(Return selector);
  2764.    FI;
  2765.    IF conforming
  2766.    THEN code segment DPL must be ≤ CPL, else #GP(Return selector);
  2767.    Segment must be present, else #NP(Return selector);
  2768.    Instruction pointer must be within code segment boundaries, else #GP(0);
  2769.    FI;
  2770.    IF OperandSize=32
  2771.    THEN
  2772.       Load CS:EIP from stack;
  2773.       Load CS-register with new code segment descriptor;
  2774.       Load EFLAGS with third doubleword from stack;
  2775.       Increment eSP by 12;
  2776.    ELSE
  2777.       Load CS-register with new code segment descriptor;
  2778.       Load FLAGS with third word on stack;
  2779.       Increment eSP by 6;
  2780.    FI;
  2781.  
  2782. RETURN-OUTER-LEVEL:
  2783.    IF OperandSize=32
  2784.    THEN Top 20 bytes on stack must be within limits, else #SS(0);
  2785.    ELSE Top 10 bytes on stack must be within limits, else #SS(0);
  2786.    FI;
  2787.    Examine return CS selector and associated descriptor:
  2788.       Selector must be non-null, else #GP(0);
  2789.       Selector index must be within its descriptor table limits;
  2790.          ELSE #GP(Return selector);
  2791.       AR byte must indicate code segment, else #GP(Return selector);
  2792.       IF non-conforming
  2793.       THEN code segment DPL must = CS selector RPL;
  2794.       ELSE #GP(Return selector);
  2795.       FI;
  2796.       IF conforming
  2797.       THEN code segment DPL must be > CPL;
  2798.       ELSE #GP(Return selector);
  2799.       FI;
  2800.       Segment must be present, else #NP(Return selector);
  2801.    Examine return SS selector and associated descriptor:
  2802.       Selector must be non-null, else #GP(0);
  2803.       Selector index must be within its descriptor table limits
  2804.          ELSE #GP(SS selector);
  2805.       Selector RPL must equal the RPL of the return CS selector
  2806.          ELSE #GP(SS selector);
  2807.       AR byte must indicate a writable data segment, else #GP(SS selector);
  2808.       Stack segment DPL must equal the RPL of the return CS selector
  2809.          ELSE #GP(SS selector);
  2810.       SS must be present, else #NP(SS selector);
  2811.  
  2812.    Instruction pointer must be within code segment limit ELSE #GP(0);
  2813.    IF OperandSize=32
  2814.    THEN
  2815.       Load CS:EIP from stack;
  2816.       Load EFLAGS with values at (eSP+8);
  2817.    ELSE
  2818.       Load CS:IP from stack;
  2819.       Load FLAGS with values at (eSP+4);
  2820.    FI;
  2821.    Load SS:eSP from stack;
  2822.    Set CPL to the RPL of the return CS selector;
  2823.    Load the CS register with the CS descriptor;
  2824.    Load the SS register with the SS descriptor;
  2825.    FOR each of ES, FS, GS, and DS
  2826.    DO;
  2827.       IF the current value of the register is not valid for the outer level;
  2828.       THEN zero the register and clear the valid flag;
  2829.       FI;
  2830.       To be valid, the register setting must satisfy the following
  2831.          properties:
  2832.          Selector index must be within descriptor table limits;
  2833.          AR byte must indicate data or readable code segment;
  2834.          IF segment is data or non-conforming code,
  2835.          THEN DPL must be ≥ CPL, or DPL must be ≥ RPL;
  2836.    OD;
  2837.  
  2838. Description
  2839.  
  2840. In Real Address Mode, IRET pops the instruction pointer, CS, and the
  2841. flags register from the stack and resumes the interrupted routine.
  2842.  
  2843. In Protected Mode, the action of IRET depends on the setting of the
  2844. nested task flag (NT) bit in the flag register. When popping the new
  2845. flag image from the stack, the IOPL bits in the flag register are changed
  2846. only when CPL equals 0.
  2847.  
  2848. If NT equals 0, IRET returns from an interrupt procedure without a
  2849. task switch. The code returned to must be equally or less privileged than
  2850. the interrupt routine (as indicated by the RPL bits of the CS selector
  2851. popped from the stack). If the destination code is less privileged, IRET
  2852. also pops the stack pointer and SS from the stack.
  2853.  
  2854. If NT equals 1, IRET reverses the operation of a CALL or INT that
  2855. caused a task switch. The updated state of the task executing IRET is
  2856. saved in its task state segment. If the task is reentered later, the code
  2857. that follows IRET is executed.
  2858.  
  2859. Flags Affected
  2860.  
  2861. All; the flags register is popped from stack
  2862.  
  2863. Protected Mode Exceptions
  2864.  
  2865. #GP, #NP, or #SS, as indicated under "Operation" above
  2866.  
  2867. Real Address Mode Exceptions
  2868.  
  2869. Interrupt 13 if any part of the operand being popped lies beyond address
  2870. 0FFFFH
  2871.  
  2872. Virtual 8086 Mode Exceptions
  2873.  
  2874. #GP(0) fault if IOPL is less than 3, to permit emulation
  2875.  
  2876.  
  2877. Jcc ── Jump if Condition is Met
  2878.  
  2879.  
  2880. Opcode         Instruction       Clocks   Description
  2881.  
  2882. 77  cb         JA rel8           7+m,3    Jump short if above (CF=0 and
  2883.                                           ZF=0)
  2884. 73  cb         JAE rel8          7+m,3    Jump short if above or equal
  2885.                                           (CF=0)
  2886. 72  cb         JB rel8           7+m,3    Jump short if below (CF=1)
  2887. 76  cb         JBE rel8          7+m,3    Jump short if below or equal
  2888.                                           (CF=1 or ZF=1)
  2889. 72  cb         JC rel8           7+m,3    Jump short if carry (CF=1)
  2890. E3  cb         JCXZ rel8         9+m,5    Jump short if CX register is 0
  2891. E3  cb         JECXZ rel8        9+m,5    Jump short if ECX register is 0
  2892. 74  cb         JE rel8           7+m,3    Jump short if equal (ZF=1)
  2893. 74  cb         JZ rel8           7+m,3    Jump short if 0 (ZF=1)
  2894. 7F  cb         JG rel8           7+m,3    Jump short if greater (ZF=0 and
  2895.                                           SF=OF)
  2896. 7D  cb         JGE rel8          7+m,3    Jump short if greater or equal
  2897.                                           (SF=OF)
  2898. 7C  cb         JL rel8           7+m,3    Jump short if less (SF<>OF)
  2899. 7E  cb         JLE rel8          7+m,3    Jump short if less or equal
  2900.                                           (ZF=1 and SF<>OF)
  2901. 76  cb         JNA rel8          7+m,3    Jump short if not above (CF=1 or
  2902.                                           ZF=1)
  2903. 72  cb         JNAE rel8         7+m,3    Jump short if not above or equal
  2904.                                           (CF=1)
  2905. 73  cb         JNB rel8          7+m,3    Jump short if not below (CF=0)
  2906. 77  cb         JNBE rel8         7+m,3    Jump short if not below or equal
  2907.                                           (CF=0 and ZF=0)
  2908. 73  cb         JNC rel8          7+m,3    Jump short if not carry (CF=0)
  2909. 75  cb         JNE rel8          7+m,3    Jump short if not equal (ZF=0)
  2910. 7E  cb         JNG rel8          7+m,3    Jump short if not greater (ZF=1
  2911.                                           or SF<>OF)
  2912. 7C  cb         JNGE rel8         7+m,3    Jump short if not greater or
  2913.                                           equal (SF<>OF)
  2914. 7D  cb         JNL rel8          7+m,3    Jump short if not less (SF=OF)
  2915. 7F  cb         JNLE rel8         7+m,3    Jump short if not less or equal
  2916.                                           (ZF=0 and SF=OF)
  2917. 71  cb         JNO rel8          7+m,3    Jump short if not overflow
  2918.                                           (OF=0)
  2919. 7B  cb         JNP rel8          7+m,3    Jump short if not parity (PF=0)
  2920. 79  cb         JNS rel8          7+m,3    Jump short if not sign (SF=0)
  2921. 75  cb         JNZ rel8          7+m,3    Jump short if not zero (ZF=0)
  2922. 70  cb         JO rel8           7+m,3    Jump short if overflow (OF=1)
  2923. 7A  cb         JP rel8           7+m,3    Jump short if parity (PF=1)
  2924. 7A  cb         JPE rel8          7+m,3    Jump short if parity even (PF=1)
  2925. 7B  cb         JPO rel8          7+m,3    Jump short if parity odd (PF=0)
  2926. 78  cb         JS rel8           7+m,3    Jump short if sign (SF=1)
  2927. 74  cb         JZ rel8           7+m,3    Jump short if zero (ZF = 1)
  2928. 0F  87 cw/cd   JA rel16/32       7+m,3    Jump near if above (CF=0 and
  2929.                                           ZF=0)
  2930. 0F  83 cw/cd   JAE rel16/32      7+m,3    Jump near if above or equal
  2931.                                           (CF=0)
  2932. 0F  82 cw/cd   JB rel16/32       7+m,3    Jump near if below (CF=1)
  2933. 0F  86 cw/cd   JBE rel16/32      7+m,3    Jump near if below or equal
  2934.                                           (CF=1 or ZF=1)
  2935. 0F  82 cw/cd   JC rel16/32       7+m,3    Jump near if carry (CF=1)
  2936. 0F  84 cw/cd   JE rel16/32       7+m,3    Jump near if equal (ZF=1)
  2937. 0F  84 cw/cd   JZ rel16/32       7+m,3    Jump near if 0 (ZF=1)
  2938. 0F  8F cw/cd   JG rel16/32       7+m,3    Jump near if greater (ZF=0 and
  2939.                                           SF=OF)
  2940. 0F  8D cw/cd   JGE rel16/32      7+m,3    Jump near if greater or equal
  2941.                                           (SF=OF)
  2942. 0F  8C cw/cd   JL rel16/32       7+m,3    Jump near if less (SF<>OF)
  2943. 0F  8E cw/cd   JLE rel16/32      7+m,3    Jump near if less or equal (ZF=1
  2944.                                           and SF<>OF)
  2945. 0F  86 cw/cd   JNA rel16/32      7+m,3    Jump near if not above (CF=1 or
  2946.                                           ZF=1)
  2947. 0F  82 cw/cd   JNAE rel16/32     7+m,3    Jump near if not above or equal
  2948.                                           (CF=1)
  2949. 0F  83 cw/cd   JNB rel16/32      7+m,3    Jump near if not below (CF=0)
  2950. 0F  87 cw/cd   JNBE rel16/32     7+m,3    Jump near if not below or equal
  2951.                                           (CF=0 and ZF=0)
  2952. 0F  83 cw/cd   JNC rel16/32      7+m,3    Jump near if not carry (CF=0)
  2953. 0F  85 cw/cd   JNE rel16/32      7+m,3    Jump near if not equal (ZF=0)
  2954. 0F  8E cw/cd   JNG rel16/32      7+m,3    Jump near if not greater (ZF=1
  2955.                                           or SF<>OF)
  2956. 0F  8C cw/cd   JNGE rel16/32     7+m,3    Jump near if not greater or
  2957.                                           equal (SF<>OF)
  2958. 0F  8D cw/cd   JNL rel16/32      7+m,3    Jump near if not less (SF=OF)
  2959. 0F  8F cw/cd   JNLE rel16/32     7+m,3    Jump near if not less or equal
  2960.                                           (ZF=0 and SF=OF)
  2961. 0F  81 cw/cd   JNO rel16/32      7+m,3    Jump near if not overflow (OF=0)
  2962. 0F  8B cw/cd   JNP rel16/32      7+m,3    Jump near if not parity (PF=0)
  2963. 0F  89 cw/cd   JNS rel16/32      7+m,3    Jump near if not sign (SF=0)
  2964. 0F  85 cw/cd   JNZ rel16/32      7+m,3    Jump near if not zero (ZF=0)
  2965. 0F  80 cw/cd   JO rel16/32       7+m,3    Jump near if overflow (OF=1)
  2966. 0F  8A cw/cd   JP rel16/32       7+m,3    Jump near if parity (PF=1)
  2967. 0F  8A cw/cd   JPE rel16/32      7+m,3    Jump near if parity even (PF=1)
  2968. 0F  8B cw/cd   JPO rel16/32      7+m,3    Jump near if parity odd (PF=0)
  2969. 0F  88 cw/cd   JS rel16/32       7+m,3    Jump near if sign (SF=1)
  2970. 0F  84 cw/cd   JZ rel16/32       7+m,3    Jump near if 0 (ZF=1)
  2971.  
  2972.  
  2973. ───────────────────────────────────────────────────────────────────────────
  2974. NOTES:
  2975.   The first clock count is for the true condition (branch taken); the
  2976.   second clock count is for the false condition (branch not taken). rel16/32
  2977.   indicates that these instructions map to two; one with a 16-bit relative
  2978.   displacement, the other with a 32-bit relative displacement, depending on
  2979.   the operand-size attribute of the instruction.
  2980. ───────────────────────────────────────────────────────────────────────────
  2981.  
  2982. Operation
  2983.  
  2984. IF condition
  2985. THEN
  2986.    EIP  EIP + SignExtend(rel8/16/32);
  2987.    IF OperandSize = 16
  2988.    THEN EIP  EIP AND 0000FFFFH;
  2989.    FI;
  2990. FI;
  2991.  
  2992. Description
  2993.  
  2994. Conditional jumps (except JCXZ) test the flags which have been set by
  2995. a previous instruction. The conditions for each mnemonic are given in
  2996. parentheses after each description above. The terms "less" and "greater"
  2997. are used for comparisons of signed integers; "above" and "below" are
  2998. used for unsigned integers.
  2999.  
  3000. If the given condition is true, a jump is made to the location provided as
  3001. the operand. Instruction coding is most efficient when the target for the
  3002. conditional jump is in the current code segment and within -128 to
  3003. +127 bytes of the next instruction's first byte. The jump can also target
  3004. -32768 thru +32767 (segment size attribute 16) or -2^(31) thru +2^(31) -1
  3005. (segment size attribute 32) relative to the next instruction's first byte.
  3006. When the target for the conditional jump is in a different segment, use
  3007. the opposite case of the jump instruction (i.e., JE and JNE), and then
  3008. access the target with an unconditional far jump to the other segment.
  3009. For example, you cannot code──
  3010.  
  3011. JZ FARLABEL;
  3012.  
  3013. You must instead code──
  3014.  
  3015.    JNZ BEYOND;
  3016.    JMP FARLABEL;
  3017. BEYOND:
  3018.  
  3019. Because there can be several ways to interpret a particular state of the
  3020. flags, ASM386 provides more than one mnemonic for most of the
  3021. conditional jump opcodes. For example, if you compared two characters in
  3022. AX and want to jump if they are equal, use JE; or, if you ANDed AX
  3023. with a bit field mask and only want to jump if the result is 0, use JZ, a
  3024. synonym for JE.
  3025.  
  3026. JCXZ differs from other conditional jumps because it tests the contents of
  3027. the CX or ECX register for 0, not the flags. JCXZ is useful at the beginning
  3028. of a conditional loop that terminates with a conditional loop instruction
  3029. (such as LOOPNE TARGET LABEL. The JCXZ prevents entering the loop with CX or
  3030. ECX equal to zero, which would cause the loop to execute 64K or 32G times
  3031. instead of zero times.
  3032.  
  3033. Flags Affected
  3034.  
  3035. None
  3036.  
  3037. Protected Mode Exceptions
  3038.  
  3039. #GP(0) if the offset jumped to is beyond the limits of the code segment
  3040.  
  3041. Real Address Mode Exceptions
  3042.  
  3043. None
  3044.  
  3045. Virtual 8086 Mode Exceptions
  3046.  
  3047. None
  3048.  
  3049.  
  3050. JMP ── Jump
  3051.  
  3052.  
  3053. Opcode    Instruction     Clocks          Description
  3054.  
  3055. EB  cb    JMP rel8        7+m             Jump short
  3056. E9  cw    JMP rel16       7+m             Jump near, displacement relative
  3057.                                           to next instruction
  3058. FF  /4    JMP r/m16       7+m/10+m        Jump near indirect
  3059. EA  cd    JMP ptr16:16    12+m,pm=27+m    Jump intersegment, 4-byte
  3060.                                           immediate address
  3061. EA  cd    JMP ptr16:16    pm=45+m         Jump to call gate, same
  3062.                                           privilege
  3063. EA  cd    JMP ptr16:16    ts              Jump via task state segment
  3064. EA  cd    JMP ptr16:16    ts              Jump via task gate
  3065. FF  /5    JMP m16:16      43+m,pm=31+m    Jump r/m16:16 indirect and
  3066.                                           intersegment
  3067. FF  /5    JMP m16:16      pm=49+m         Jump to call gate, same
  3068.                                           privilege
  3069. FF  /5    JMP m16:16      5 + ts          Jump via task state segment
  3070. FF  /5    JMP m16:16      5 + ts          Jump via task gate
  3071. E9  cd    JMP rel32       7+m             Jump near, displacement relative
  3072.                                           to next instruction
  3073. FF  /4    JMP r/m32       7+m,10+m        Jump near, indirect
  3074. EA  cp    JMP ptr16:32    12+m,pm=27+m    Jump intersegment, 6-byte
  3075.                                           immediate address
  3076. EA  cp    JMP ptr16:32    pm=45+m         Jump to call gate, same
  3077.                                           privilege
  3078. EA  cp    JMP ptr16:32    ts              Jump via task state segment
  3079. EA  cp    JMP ptr16:32    ts              Jump via task gate
  3080. FF  /5    JMP m16:32      43+m,pm=31+m    Jump intersegment, address at
  3081.                                           r/m dword
  3082. FF  /5    JMP m16:32      pm=49+m         Jump to call gate, same
  3083.                                           privilege
  3084. FF  /5    JMP m16:32      5 + ts          Jump via task state segment
  3085. FF  /5    JMP m16:32      5 + ts          Jump via task gate
  3086.  
  3087.  
  3088. ───────────────────────────────────────────────────────────────────────────
  3089. NOTE:
  3090. Values of ts are given by the following table:
  3091.  
  3092.                                New Task
  3093.  
  3094.                 386 TSS       386 TASK       286 TSS
  3095.                 VM = 0        VM = 1
  3096.  
  3097. Old Task                   Via Task Gate?
  3098.  
  3099.                 N     Y       N      Y       N     Y
  3100. 386
  3101. TSS VM=0       303   312     220    229     276   285
  3102.  
  3103. 286
  3104. TSS            301   310     218    227     274   283
  3105. ───────────────────────────────────────────────────────────────────────────
  3106.  
  3107. Operation
  3108.  
  3109. IF instruction = relative JMP
  3110.    (* i.e. operand is rel8, rel16, or rel32 *)
  3111. THEN
  3112.    EIP  EIP + rel8/16/32;
  3113.    IF OperandSize = 16
  3114.    THEN EIP  EIP AND 0000FFFFH;
  3115.    FI;
  3116. FI;
  3117. IF instruction = near indirect JMP
  3118.    (* i.e. operand is r/m16 or r/m32 *)
  3119. THEN
  3120.    IF OperandSize = 16
  3121.    THEN
  3122.       EIP  [r/m16] AND 0000FFFFH;
  3123.    ELSE (* OperandSize = 32 *)
  3124.       EIP  [r/m32];
  3125.    FI;
  3126. FI;
  3127.  
  3128. IF (PE = 0 OR (PE = 1 AND VM = 1)) (* real mode or V86 mode *)
  3129.    AND instruction = far JMP
  3130.    (* i.e., operand type is m16:16, m16:32, ptr16:16, ptr16:32 *)
  3131. THEN GOTO REAL-OR-V86-MODE;
  3132.    IF operand type = m16:16 or m16:32
  3133.    THEN (* indirect *)
  3134.       IF OperandSize = 16
  3135.       THEN
  3136.          CS:IP  [m16:16];
  3137.          EIP  EIP AND 0000FFFFH; (* clear upper 16 bits *)
  3138.       ELSE (* OperandSize = 32 *)
  3139.          CS:EIP  [m16:32];
  3140.       FI;
  3141.    FI;
  3142.    IF operand type = ptr16:16 or ptr16:32
  3143.    THEN
  3144.       IF OperandSize = 16
  3145.       THEN
  3146.          CS:IP  ptr16:16;
  3147.          EIP  EIP AND 0000FFFFH; (* clear upper 16 bits *)
  3148.       ELSE (* OperandSize = 32 *)
  3149.          CS:EIP  ptr16:32;
  3150.       FI;
  3151.    FI;
  3152. FI;
  3153.  
  3154. IF (PE = 1 AND VM = 0) (* Protected mode, not V86 mode *)
  3155.    AND instruction = far JMP
  3156. THEN
  3157.    IF operand type = m16:16 or m16:32
  3158.    THEN (* indirect *)
  3159.       check access of EA dword;
  3160.       #GP(0) or #SS(0) IF limit violation;
  3161.    FI;
  3162.    Destination selector is not null ELSE #GP(0)
  3163.    Destination selector index is within its descriptor table limits ELSE
  3164. #GP(selector)
  3165.    Depending on AR byte of destination descriptor:
  3166.       GOTO CONFORMING-CODE-SEGMENT;
  3167.       GOTO NONCONFORMING-CODE-SEGMENT;
  3168.       GOTO CALL-GATE;
  3169.       GOTO TASK-GATE;
  3170.       GOTO TASK-STATE-SEGMENT;
  3171.    ELSE #GP(selector); (* illegal AR byte in descriptor *)
  3172. FI;
  3173.  
  3174. CONFORMING-CODE-SEGMENT:
  3175.    Descriptor DPL must be ≤ CPL ELSE #GP(selector);
  3176.    Segment must be present ELSE #NP(selector);
  3177.    Instruction pointer must be within code-segment limit ELSE #GP(0);
  3178.    IF OperandSize = 32
  3179.    THEN Load CS:EIP from destination pointer;
  3180.    ELSE Load CS:IP from destination pointer;
  3181.    FI;
  3182.    Load CS register with new segment descriptor;
  3183.  
  3184. NONCONFORMING-CODE-SEGMENT:
  3185.    RPL of destination selector must be ≤ CPL ELSE #GP(selector);
  3186.    Descriptor DPL must be = CPL ELSE #GP(selector);
  3187.    Segment must be present ELSE # NP(selector);
  3188.    Instruction pointer must be within code-segment limit ELSE #GP(0);
  3189.    IF OperandSize = 32
  3190.    THEN Load CS:EIP from destination pointer;
  3191.    ELSE Load CS:IP from destination pointer;
  3192.    FI;
  3193.    Load CS register with new segment descriptor;
  3194.    Set RPL field of CS register to CPL;
  3195.  
  3196. CALL-GATE:
  3197.    Descriptor DPL must be ≥ CPL ELSE #GP(gate selector);
  3198.    Descriptor DPL must be ≥ gate selector RPL ELSE #GP(gate selector);
  3199.    Gate must be present ELSE #NP(gate selector);
  3200.    Examine selector to code segment given in call gate descriptor:
  3201.       Selector must not be null ELSE #GP(0);
  3202.       Selector must be within its descriptor table limits ELSE
  3203.          #GP(CS selector);
  3204.       Descriptor AR byte must indicate code segment
  3205.          ELSE #GP(CS selector);
  3206.       IF non-conforming
  3207.       THEN code-segment descriptor, DPL must = CPL
  3208.       ELSE #GP(CS selector);
  3209.       FI;
  3210.       IF conforming
  3211.       THEN code-segment descriptor DPL must be ≤ CPL;
  3212.       ELSE #GP(CS selector);
  3213.       Code segment must be present ELSE #NP(CS selector);
  3214.       Instruction pointer must be within code-segment limit ELSE #GP(0);
  3215.       IF OperandSize = 32
  3216.       THEN Load CS:EIP from call gate;
  3217.       ELSE Load CS:IP from call gate;
  3218.       FI;
  3219.    Load CS register with new code-segment descriptor;
  3220.    Set RPL of CS to CPL
  3221.  
  3222. TASK-GATE:
  3223.    Gate descriptor DPL must be ≥ CPL ELSE #GP(gate selector);
  3224.    Gate descriptor DPL must be ≥ gate selector RPL ELSE #GP(gate
  3225.      selector);
  3226.    Task Gate must be present ELSE #NP(gate selector);
  3227.    Examine selector to TSS, given in Task Gate descriptor:
  3228.    Must specify global in the local/global bit ELSE #GP(TSS selector);
  3229.    Index must be within GDT limits ELSE #GP(TSS selector);
  3230.    Descriptor AR byte must specify available TSS (bottom bits 00001);
  3231.       ELSE #GP(TSS selector);
  3232.    Task State Segment must be present ELSE #NP(TSS selector);
  3233. SWITCH-TASKS (without nesting) to TSS;
  3234. Instruction pointer must be within code-segment limit ELSE #GP(0);
  3235.  
  3236. TASK-STATE-SEGMENT:
  3237.    TSS DPL must be ≥ CPL ELSE #GP(TSS selector);
  3238.    TSS DPL must be ≥ TSS selector RPL ELSE #GP(TSS selector);
  3239.    Descriptor AR byte must specify available TSS (bottom bits 00001)
  3240.       ELSE #GP(TSS selector);
  3241.    Task State Segment must be present ELSE #NP(TSS selector);
  3242.    SWITCH-TASKS (without nesting) to TSS;
  3243.    Instruction pointer must be within code-segment limit ELSE #GP(0);
  3244.  
  3245. Description
  3246.  
  3247. The JMP instruction transfers control to a different point in the
  3248. instruction stream without recording return information.
  3249.  
  3250. The action of the various forms of the instruction are shown below.
  3251.  
  3252. Jumps with destinations of type r/m16, r/m32, rel16, and rel32 are near
  3253. jumps and do not involve changing the segment register value.
  3254.  
  3255. The JMP rel16 and JMP rel32 forms of the instruction add an offset to
  3256. the address of the instruction following the JMP to determine the
  3257. destination. The rel16 form is used when the instruction's operand-size
  3258. attribute is 16 bits (segment size attribute 16 only); rel32 is used when
  3259. the operand-size attribute is 32 bits (segment size attribute 32 only). The
  3260. result is stored in the 32-bit EIP register. With rel16, the upper 16 bits
  3261. of EIP are cleared, which results in an offset whose value does not exceed
  3262. 16 bits.
  3263.  
  3264. JMP r/m16 and JMP r/m32 specifies a register or memory location from which
  3265. the absolute offset from the procedure is fetched. The offset fetched from
  3266. r/m is 32 bits for an operand-size attribute of 32 bits (r/m32), or 16 bits
  3267. for an operand-size attribute of 16 bits (r/m16).
  3268.  
  3269. The JMP ptr16:16 and ptr16:32 forms of the instruction use a four-byte
  3270. or six-byte operand as a long pointer to the destination. The JMP
  3271. and  forms fetch the long pointer from the memory location
  3272. specified (indirection). In Real Address Mode or Virtual 8086 Mode,
  3273. the long pointer provides 16 bits for the CS register and 16 or 32 bits
  3274. for the EIP register (depending on the operand-size attribute). In
  3275. Protected Mode, both long pointer forms consult the Access Rights (AR)
  3276. byte in the descriptor indexed by the selector part of the long pointer.
  3277.  
  3278. Depending on the value of the AR byte, the jump will perform one of
  3279. the following types of control transfers:
  3280.  
  3281.   ■  A jump to a code segment at the same privilege level
  3282.   ■  A task switch
  3283.  
  3284. For more information on protected mode control transfers, refer to
  3285. Chapter 6 and Chapter 7.
  3286.  
  3287. Flags Affected
  3288.  
  3289. All if a task switch takes place; none if no task switch occurs
  3290.  
  3291. Protected Mode Exceptions
  3292.  
  3293. Far jumps: #GP, #NP, #SS, and #TS, as indicated in the list above.
  3294.  
  3295. Near direct jumps: #GP(0) if procedure location is beyond the code
  3296. segment limits.
  3297.  
  3298. Near indirect jumps: #GP(0) for an illegal memory operand effective
  3299. address in the CS, DS, ES, FS, or GS segments: #SS(0) for an illegal
  3300. address in the SS segment; #GP if the indirect offset obtained is beyond
  3301. the code segment limits; #PF(fault-code) for a page fault.
  3302.  
  3303. Real Address Mode Exceptions
  3304.  
  3305. Interrupt 13 if any part of the operand would be outside of the effective
  3306. address space from 0 to 0FFFFH
  3307.  
  3308. Virtual 8086 Mode Exceptions
  3309.  
  3310. Same exceptions as under Real Address Mode; #PF(fault-code) for a
  3311. page fault
  3312.  
  3313.  
  3314. LAHF ── Load Flags into AH Register
  3315.  
  3316. Opcode  Instruction   Clocks   Description
  3317.  
  3318. 9F      LAHF          2        Load: AH = flags SF ZF xx AF xx PF xx CF
  3319.  
  3320.  
  3321. Operation
  3322.  
  3323. AH  SF:ZF:xx:AF:xx:PF:xx:CF;
  3324.  
  3325. Description
  3326.  
  3327. LAHF transfers the low byte of the flags word to AH. The bits, from
  3328. MSB to LSB, are sign, zero, indeterminate, auxiliary, carry,
  3329. indeterminate, parity, indeterminate, and carry.
  3330.  
  3331. Flags Affected
  3332.  
  3333. None
  3334.  
  3335. Protected Mode Exceptions
  3336.  
  3337. None
  3338.  
  3339. Real Address Mode Exceptions
  3340.  
  3341. None
  3342.  
  3343. Virtual 8086 Mode Exceptions
  3344.  
  3345. None
  3346.  
  3347.  
  3348. LAR ── Load Access Rights Byte
  3349.  
  3350. Opcode        Instruction      Clocks      Description
  3351.  
  3352. 0F  02 /r     LAR r16,r/m16    pm=15/16    r16  r/m16 masked by FF00
  3353. 0F  02 /r     LAR r32,r/m32    pm=15/16    r32  r/m32 masked by 00FxFF00
  3354.  
  3355.  
  3356. Description
  3357.  
  3358. The LAR instruction stores a marked form of the second doubleword of
  3359. the descriptor for the source selector if the selector is visible at the
  3360. CPL (modified by the selector's RPL) and is a valid descriptor type. The
  3361. destination register is loaded with the high-order doubleword of the
  3362. descriptor masked by 00FxFF00, and ZF is set to 1. The x indicates that the
  3363. four bits corresponding to the upper four bits of the limit are undefined in
  3364. the value loaded by LAR. If the selector is invisible or of the wrong type,
  3365. ZF is cleared.
  3366.  
  3367. If the 32-bit operand size is specified, the entire 32-bit value is loaded
  3368. into the 32-bit destination register. If the 16-bit operand size is
  3369. specified, the lower 16-bits of this value are stored in the 16-bit
  3370. destination register.
  3371.  
  3372. All code and data segment descriptors are valid for LAR.
  3373.  
  3374. The valid special segment and gate descriptor types for LAR are given
  3375. in the following table:
  3376.  
  3377. Type   Name                     Valid/Invalid
  3378.  
  3379.   0    Invalid                  Invalid
  3380.   1    Available 80286 TSS      Valid
  3381.   2    LDT                      Valid
  3382.   3    Busy 80286 TSS           Valid
  3383.   4    80286 call gate          Valid
  3384.   5    80286/80386 task gate    Valid
  3385.   6    80286 trap gate          Valid
  3386.   7    80286 interrupt gate     Valid
  3387.   8    Invalid                  Invalid
  3388.   9    Available 80386 TSS      Valid
  3389.   A    Invalid                  Invalid
  3390.   B    Busy 80386 TSS           Valid
  3391.   C    80386 call gate          Valid
  3392.   D    Invalid                  Invalid
  3393.   E    80386 trap gate          Valid
  3394.   F    80386 interrupt gate     Valid
  3395.  
  3396. Flags Affected
  3397.  
  3398. ZF as described above
  3399.  
  3400. Protected Mode Exceptions
  3401.  
  3402. #GP(0) for an illegal memory operand effective address in the CS, DS,
  3403. ES, FS, or GS segments; #SS(0) for an illegal address in the SS segment;
  3404. #PF(fault-code) for a page fault
  3405.  
  3406. Real Address Mode Exceptions
  3407.  
  3408. Interrupt 6; LAR is unrecognized in Real Address Mode
  3409.  
  3410. Virtual 8086 Mode Exceptions
  3411.  
  3412. Same exceptions as in Real Address Mode
  3413.  
  3414.  
  3415. LEA ── Load Effective Address
  3416.  
  3417. Opcode  Instruction  Clocks  Description
  3418.  
  3419. 8D  /r  LEA r16,m    2       Store effective address for m in register r16
  3420. 8D  /r  LEA r32,m    2       Store effective address for m in register r32
  3421. 8D  /r  LEA r16,m    2       Store effective address for m in register r16
  3422. 8D  /r  LEA r32,m    2       Store effective address for m in register r32
  3423.  
  3424.  
  3425. Operation
  3426.  
  3427. IF OperandSize = 16 AND AddressSize = 16
  3428. THEN r16  Addr(m);
  3429. ELSE
  3430.    IF OperandSize = 16 AND AddressSize = 32
  3431.    THEN
  3432.       r16  Truncate_to_16bits(Addr(m));   (* 32-bit address *)
  3433.    ELSE
  3434.       IF OperandSize = 32 AND AddressSize = 16
  3435.       THEN
  3436.          r32  Truncate_to_16bits(Addr(m));
  3437.       ELSE
  3438.          IF OperandSize = 32 AND AddressSize = 32
  3439.          THEN  r32  Addr(m);
  3440.          FI;
  3441.       FI;
  3442.    FI;
  3443. FI;
  3444.  
  3445. Description
  3446.  
  3447. LEA calculates the effective address (offset part) and stores it in the
  3448. specified register. The operand-size attribute of the instruction
  3449. (represented by OperandSize in the algorithm under "Operation" above) is
  3450. determined by the chosen register. The address-size attribute (represented
  3451. by AddressSize) is determined by the USE attribute of the segment containing
  3452. the second operand. The address-size and operand-size attributes affect the
  3453. action performed by LEA, as follows:
  3454.  
  3455. Operand Size  Address Size  Action Performed
  3456.  
  3457.     16            16        16-bit effective address is calculated and
  3458.                             stored in requested 16-bit register
  3459.                             destination.
  3460.  
  3461.     16            32        32-bit effective address is calculated. The
  3462.                             lower 16 bits of the address are stored in
  3463.                             the requested 16-bit register destination.
  3464.  
  3465.     32            16        16-bit effective address is calculated. The
  3466.                             16-bit address is zero-extended and stored
  3467.                             in the requested 32-bit register destination.
  3468.  
  3469.     32            32        32-bit effective address is calculated and
  3470.                             stored in the requested 32-bit register
  3471.                             destination.
  3472.  
  3473. Flags Affected
  3474.  
  3475. None
  3476.  
  3477. Protected Mode Exceptions
  3478.  
  3479. #UD if the second operand is a register
  3480.  
  3481. Real Address Mode Exceptions
  3482.  
  3483. Interrupt 6 if the second operand is a register
  3484.  
  3485. Virtual 8086 Mode Exceptions
  3486.  
  3487. Same exceptions as in Real Address Mode
  3488.  
  3489.  
  3490. LEAVE ── High Level Procedure Exit
  3491.  
  3492. Opcode  Instruction  Clocks  Description
  3493.  
  3494. C9      LEAVE        4       Set SP to BP, then pop BP
  3495. C9      LEAVE        4       Set ESP to EBP, then pop EBP
  3496.  
  3497.  
  3498. Operation
  3499.  
  3500. IF StackAddrSize = 16
  3501. THEN
  3502.    SP  BP;
  3503. ELSE (* StackAddrSize = 32 *)
  3504.    ESP  EBP;
  3505. FI;
  3506. IF OperandSize = 16
  3507. THEN
  3508.    BP  Pop();
  3509. ELSE (* OperandSize = 32 *)
  3510.    EBP  Pop();
  3511. FI;
  3512.  
  3513. Description
  3514.  
  3515. LEAVE reverses the actions of the ENTER instruction. By copying the
  3516. frame pointer to the stack pointer, LEAVE releases the stack space used
  3517. by a procedure for its local variables. The old frame pointer is popped
  3518. into BP or EBP, restoring the caller's frame. A subsequent RET
  3519. instruction removes any arguments pushed onto the stack of the exiting
  3520. procedure.
  3521.  
  3522. Flags Affected
  3523.  
  3524. None
  3525.  
  3526. Protected Mode Exceptions
  3527.  
  3528. #SS(0) if BP does not point to a location within the limits of the current
  3529. stack segment
  3530.  
  3531. Real Address Mode Exceptions
  3532.  
  3533. Interrupt 13 if any part of the operand would lie outside of the effective
  3534. address space from 0 to 0FFFFH
  3535.  
  3536. Virtual 8086 Mode Exceptions
  3537.  
  3538. Same exceptions as in Real Address Mode
  3539.  
  3540.  
  3541. LGDT/LIDT ── Load Global/Interrupt Descriptor Table Register
  3542.  
  3543. Opcode       Instruction      Clocks        Description
  3544.  
  3545. 0F  01 /2    LGDT m16&32      11            Load m into GDTR
  3546. 0F  01 /3    LIDT m16&32      11            Load m into IDTR
  3547.  
  3548.  
  3549. Operation
  3550.  
  3551. IF instruction = LIDT
  3552. THEN
  3553.    IF OperandSize = 16
  3554.    THEN IDTR.Limit:Base  m16:24 (* 24 bits of base loaded *)
  3555.    ELSE IDTR.Limit:Base  m16:32
  3556.    FI;
  3557. ELSE (* instruction = LGDT *)
  3558.    IF OperandSize = 16
  3559.    THEN GDTR.Limit:Base  m16:24 (* 24 bits of base loaded *)
  3560.    ELSE GDTR.Limit:Base  m16:32;
  3561.    FI;
  3562. FI;
  3563.  
  3564. Description
  3565.  
  3566. The LGDT and LIDT instructions load a linear base address and limit
  3567. value from a six-byte data operand in memory into the GDTR or IDTR,
  3568. respectively. If a 16-bit operand is used with LGDT or LIDT, the
  3569. register is loaded with a 16-bit limit and a 24-bit base, and the
  3570. high-order eight bits of the six-byte data operand are not used. If a 32-bit
  3571. operand is used, a 16-bit limit and a 32-bit base is loaded; the high-order
  3572. eight bits of the six-byte operand are used as high-order base address bits.
  3573.  
  3574. The SGDT and SIDT instructions always store into all 48 bits of the
  3575. six-byte data operand. With the 80286, the upper eight bits are undefined
  3576. after SGDT or SIDT is executed. With the 80386, the upper eight bits
  3577. are written with the high-order eight address bits, for both a 16-bit
  3578. operand and a 32-bit operand. If LGDT or LIDT is used with a 16-bit
  3579. operand to load the register stored by SGDT or SIDT, the upper eight
  3580. bits are stored as zeros.
  3581.  
  3582. LGDT and LIDT appear in operating system software; they are not used
  3583. in application programs. They are the only instructions that directly load
  3584. a linear address (i.e., not a segment relative address) in 80386 Protected
  3585. Mode.
  3586.  
  3587. Flags Affected
  3588.  
  3589. None
  3590.  
  3591. Protected Mode Exceptions
  3592.  
  3593. #GP(0) if the current privilege level is not 0; #UD if the source operand
  3594. is a register; #GP(0) for an illegal memory operand effective address in
  3595. the CS, DS, ES, FS, or GS segments; #SS(0) for an illegal address in
  3596. the SS segment; #PF(fault-code) for a page fault
  3597.  
  3598. Real Address Mode Exceptions
  3599.  
  3600. Interrupt 13 if any part of the operand would lie outside of the effective
  3601. address space from 0 to 0FFFFH; Interrupt 6 if the source operand is a
  3602. register
  3603.  
  3604. ───────────────────────────────────────────────────────────────────────────
  3605. Note:
  3606.   These instructions are valid in Real Address Mode to allow
  3607.   power-up initialization for Protected Mode
  3608. ───────────────────────────────────────────────────────────────────────────
  3609.  
  3610. Virtual 8086 Mode Exceptions
  3611.  
  3612. Same exceptions as in Real Address Mode; #PF(fault-code) for a page
  3613. fault
  3614.  
  3615.  
  3616. LGS/LSS/LDS/LES/LFS ── Load Full Pointer
  3617.  
  3618. Opcode      Instruction      Clocks   Description
  3619.  
  3620. C5  /r      LDS r16,m16:16   7,p=22   Load DS:r16 with pointer from memory
  3621. C5  /r      LDS r32,m16:32   7,p=22   Load DS:r32 with pointer from memory
  3622. 0F  B2 /r   LSS r16,m16:16   7,p=22   Load SS:r16 with pointer from memory
  3623. 0F  B2 /r   LSS r32,m16:32   7,p=22   Load SS:r32 with pointer from memory
  3624. C4  /r      LES r16,m16:16   7,p=22   Load ES:r16 with pointer from memory
  3625. C4  /r      LES r32,m16:32   7,p=22   Load ES:r32 with pointer from memory
  3626. 0F  B4 /r   LFS r16,m16:16   7,p=25   Load FS:r16 with pointer from memory
  3627. 0F  B4 /r   LFS r32,m16:32   7,p=25   Load FS:r32 with pointer from memory
  3628. 0F  B5 /r   LGS r16,m16:16   7,p=25   Load GS:r16 with pointer from memory
  3629. 0F  B5 /r   LGS r32,m16:32   7,p=25   Load GS:r32 with pointer from memory
  3630.  
  3631.  
  3632. Operation
  3633.  
  3634. CASE instruction OF
  3635.    LSS: Sreg is SS; (* Load SS register *)
  3636.    LDS: Sreg is DS; (* Load DS register *)
  3637.    LES: Sreg is ES; (* Load ES register *)
  3638.    LFS: Sreg is FS; (* Load FS register *)
  3639.    LGS: Sreg is DS; (* Load GS register *)
  3640. ESAC;
  3641. IF (OperandSize = 16)
  3642. THEN
  3643.    r16  [Effective Address]; (* 16-bit transfer *)
  3644.    Sreg  [Effective Address + 2]; (* 16-bit transfer *)
  3645.    (* In Protected Mode, load the descriptor into the segment register *)
  3646. ELSE (* OperandSize = 32 *)
  3647.    r32  [Effective Address]; (* 32-bit transfer *)
  3648.    Sreg  [Effective Address + 4]; (* 16-bit transfer *)
  3649.    (* In Protected Mode, load the descriptor into the segment register *)
  3650. FI;
  3651.  
  3652. Description
  3653.  
  3654. These instructions read a full pointer from memory and store it in the
  3655. selected segment register:register pair. The full pointer loads 16 bits
  3656. into the segment register SS, DS, ES, FS, or GS. The other register loads 32
  3657. bits if the operand-size attribute is 32 bits, or loads 16 bits if the
  3658. operand-size attribute is 16 bits. The other 16- or 32-bit register to be
  3659. loaded is determined by the r16 or r32 register operand specified.
  3660.  
  3661. When an assignment is made to one of the segment registers, the
  3662. descriptor is also loaded into the segment register. The data for the
  3663. register is obtained from the descriptor table entry for the selector
  3664. given.
  3665.  
  3666. A null selector (values 0000-0003) can be loaded into DS, ES, FS, or
  3667. GS registers without causing a protection exception. (Any subsequent
  3668. reference to a segment whose corresponding segment register is loaded
  3669. with a null selector to address memory causes a #GP(0) exception. No
  3670. memory reference to the segment occurs.)
  3671.  
  3672. The following is a listing of the Protected Mode checks and actions taken in
  3673. the loading of a segment register:
  3674.  
  3675. IF SS is loaded:
  3676.    IF selector is null THEN #GP(0); FI;
  3677.    Selector index must be within its descriptor table limits ELSE
  3678.       #GP(selector);
  3679.    Selector's RPL must equal CPL ELSE #GP(selector);
  3680.    AR byte must indicate a writable data segment ELSE #GP(selector);
  3681.    DPL in the AR byte must equal CPL ELSE #GP(selector);
  3682.    Segment must be marked present ELSE #SS(selector);
  3683.    Load SS with selector;
  3684.    Load SS with descriptor;
  3685. IF DS, ES, FS, or GS is loaded with non-null selector:
  3686.    Selector index must be within its descriptor table limits ELSE
  3687.       #GP(selector);
  3688.    AR byte must indicate data or readable code segment ELSE
  3689.       #GP(selector);
  3690.    IF data or nonconforming code
  3691.    THEN both the RPL and the CPL must be less than or equal to DPL in
  3692.       AR byte;
  3693.    ELSE #GP(selector);
  3694.    Segment must be marked present ELSE #NP(selector);
  3695. Load segment register with selector and RPL bits;
  3696. Load segment register with descriptor;
  3697. IF DS, ES, FS or GS is loaded with a null selector:
  3698.    Clear descriptor valid bit;
  3699.  
  3700. Flags Affected
  3701.  
  3702. None
  3703.  
  3704. Protected Mode Exceptions
  3705.  
  3706. #GP(0) for an illegal memory operand effective address in the CS, DS,
  3707. ES, FS, or GS segments; #SS(0) for an illegal address in the SS segment;
  3708. the second operand must be a memory operand, not a register; #GP(0)
  3709. if a null selector is loaded into SS; #PF(fault-code) for a page fault
  3710.  
  3711. Real Address Mode Exceptions
  3712.  
  3713. The second operand must be a memory operand, not a register; Interrupt
  3714. 13 if any part of the operand would lie outside of the effective address
  3715. space from 0 to 0FFFFH
  3716.  
  3717. Virtual 8086 Mode Exceptions
  3718.  
  3719. Same exceptions as in Real Address Mode; #PF(fault-code) for a page
  3720. fault
  3721.  
  3722.  
  3723. LLDT ── Load Local Descriptor Table Register
  3724.  
  3725. Opcode      Instruction      Clocks   Description
  3726.  
  3727. 0F  00 /2   LLDT r/m16       20       Load selector r/m16 into LDTR
  3728.  
  3729.  
  3730. Operation
  3731.  
  3732. LDTR  SRC;
  3733.  
  3734. Description
  3735.  
  3736. LLDT loads the Local Descriptor Table register (LDTR). The word
  3737. operand (memory or register) to LLDT should contain a selector to the
  3738. Global Descriptor Table (GDT). The GDT entry should be a Local Descriptor
  3739. Table. If so, then the LDTR is loaded from the entry. The descriptor
  3740. registers DS, ES, SS, FS, GS, and CS are not affected. The LDT field in the
  3741. task state segment does not change.
  3742.  
  3743. The selector operand can be 0; if so, the LDTR is marked invalid. All
  3744. descriptor references (except by the LAR, VERR, VERW or LSL
  3745. instructions) cause a #GP fault.
  3746.  
  3747. LLDT is used in operating system software; it is not used in application
  3748. programs.
  3749.  
  3750. Flags Affected
  3751.  
  3752. None
  3753.  
  3754. Protected Mode Exceptions
  3755.  
  3756. #GP(0) if the current privilege level is not 0; #GP(selector) if the
  3757. selector operand does not point into the Global Descriptor Table, or if the
  3758. entry in the GDT is not a Local Descriptor Table; #NP(selector) if the
  3759. LDT descriptor is not present; #GP(0) for an illegal memory operand
  3760. effective address in the CS, DS, ES, FS, or GS segments; #SS(0) for an
  3761. illegal address in the SS segment; #PF(fault-code) for a page fault
  3762.  
  3763. Real Address Mode Exceptions
  3764.  
  3765. Interrupt 6; LLDT is not recognized in Real Address Mode
  3766.  
  3767. Virtual 8086 Mode Exceptions
  3768.  
  3769. Same exceptions as in Real Address Mode (because the instruction is
  3770. not recognized, it will not execute or perform a memory reference)
  3771.  
  3772. Note
  3773.  
  3774. The operand-size attribute has no effect on this instruction.
  3775.  
  3776.  
  3777. LMSW ── Load Machine Status Word
  3778.  
  3779. Opcode      Instruction      Clocks   Description
  3780.  
  3781. 0F  01 /6   LMSW r/m16       10/13    Load r/m16 in machine status word
  3782.  
  3783.  
  3784. Operation
  3785.  
  3786. MSW  r/m16; (* 16 bits is stored in the machine status word *)
  3787.  
  3788. Description
  3789.  
  3790. LMSW loads the machine status word (part of CR0) from the source
  3791. operand. This instruction can be used to switch to Protected Mode; if so,
  3792. it must be followed by an intrasegment jump to flush the instruction
  3793. queue. LMSW will not switch back to Real Address Mode.
  3794.  
  3795. LMSW is used only in operating system software. It is not used in
  3796. application programs.
  3797.  
  3798. Flags Affected
  3799.  
  3800. None
  3801.  
  3802. Protected Mode Exceptions
  3803.  
  3804. #GP(0) if the current privilege level is not 0; #GP(0) for an illegal
  3805. memory operand effective address in the CS, DS, ES, FS, or GS
  3806. segments; #SS(0) for an illegal address in the SS segment; #PF(fault-code)
  3807. for a page fault
  3808.  
  3809. Real Address Mode Exceptions
  3810.  
  3811. Interrupt 13 if any part of the operand would lie outside of the effective
  3812. address space from 0 to 0FFFFH
  3813.  
  3814. Virtual 8086 Mode Exceptions
  3815.  
  3816. Same exceptions as in Real Address Mode; #PF(fault-code) for a page
  3817. fault
  3818.  
  3819. Notes
  3820.  
  3821. The operand-size attribute has no effect on this instruction. This
  3822. instruction is provided for compatibility with the 80286; 80386 programs
  3823. should use MOV CR0, ... instead.
  3824.  
  3825.  
  3826. LOCK ── Assert LOCK# Signal Prefix
  3827.  
  3828. Opcode  Instruction  Clocks  Description
  3829.  
  3830. F0      LOCK         0       Assert LOCK# signal for the next instruction
  3831.  
  3832.  
  3833. Description
  3834.  
  3835. The LOCK prefix causes the LOCK# signal of the 80386 to be asserted
  3836. during execution of the instruction that follows it. In a multiprocessor
  3837. environment, this signal can be used to ensure that the 80386 has
  3838. exclusive use of any shared memory while LOCK# is asserted. The
  3839. read-modify-write sequence typically used to implement test-and-set on the
  3840. 80386 is the BTS instruction.
  3841.  
  3842. The LOCK prefix functions only with the following instructions:
  3843.  
  3844. BT, BTS, BTR, BTC                   mem, reg/imm
  3845. XCHG                                reg, mem
  3846. XCHG                                mem, reg
  3847. ADD, OR, ADC, SBB, AND, SUB, XOR    mem, reg/imm
  3848. NOT, NEG, INC, DEC                  mem
  3849.  
  3850. An undefined opcode trap will be generated if a LOCK prefix is used
  3851. with any instruction not listed above.
  3852.  
  3853. XCHG always asserts LOCK# regardless of the presence or absence of
  3854. the LOCK prefix.
  3855.  
  3856. The integrity of the LOCK is not affected by the alignment of the
  3857. memory field. Memory locking is observed for arbitrarily misaligned
  3858. fields.
  3859.  
  3860. Locked access is not assured if another 80386 processor is executing an
  3861. instruction concurrently that has one of the following characteristics:
  3862.  
  3863.   ■  Is not preceded by a LOCK prefix
  3864.  
  3865.   ■  Is not one of the instructions in the preceding list
  3866.  
  3867.   ■  Specifies a memory operand that does not exactly overlap the
  3868.      destination operand. Locking is not guaranteed for partial overlap,
  3869.      even if one memory operand is wholly contained within another.
  3870.  
  3871. Flags Affected
  3872.  
  3873. None
  3874.  
  3875. Protected Mode Exceptions
  3876.  
  3877. #UD if LOCK is used with an instruction not listed in the "Description"
  3878. section above; other exceptions can be generated by the subsequent
  3879. (locked) instruction
  3880.  
  3881. Real Address Mode Exceptions
  3882.  
  3883. Interrupt 6 if LOCK is used with an instruction not listed in the
  3884. "Description" section above; exceptions can still be generated by the
  3885. subsequent (locked) instruction
  3886.  
  3887. Virtual 8086 Mode Exceptions
  3888.  
  3889. #UD if LOCK is used with an instruction not listed in the "Description"
  3890. section above; exceptions can still be generated by the subsequent (locked)
  3891. instruction
  3892.  
  3893.  
  3894. LODS/LODSB/LODSW/LODSD ── Load String Operand
  3895.  
  3896. Opcode  Instruction   Clocks   Description
  3897.  
  3898. AC      LODS m8       5        Load byte [(E)SI] into AL
  3899. AD      LODS m16      5        Load word [(E)SI] into AX
  3900. AD      LODS m32      5        Load dword [(E)SI] into EAX
  3901. AC      LODSB         5        Load byte DS:[(E)SI] into AL
  3902. AD      LODSW         5        Load word DS:[(E)SI] into AX
  3903. AD      LODSD         5        Load dword DS:[(E)SI] into EAX
  3904.  
  3905.  
  3906. Operation
  3907.  
  3908. IF AddressSize = 16
  3909. THEN use SI for source-index
  3910. ELSE (* AddressSize = 32 *)
  3911.    use ESI for source-index;
  3912. FI;
  3913. IF byte type of instruction
  3914. THEN
  3915.    AL  [source-index]; (* byte load *)
  3916.    IF DF = 0 THEN IncDec  1 ELSE IncDec  -1; FI;
  3917. ELSE
  3918.    IF OperandSize = 16
  3919.    THEN
  3920.       AX  [source-index]; (* word load *)
  3921.       IF DF = 0 THEN IncDec  2 ELSE IncDec  -2; FI;
  3922.    ELSE (* OperandSize = 32 *)
  3923.       EAX  [source-index]; (* dword load *)
  3924.       IF DF = 0 THEN IncDec  4 ELSE IncDec  -4; FI;
  3925.    FI;
  3926. FI;
  3927. source-index  source-index + IncDec
  3928.  
  3929. Description
  3930.  
  3931. LODS loads the AL, AX, or EAX register with the memory byte, word,
  3932. or doubleword at the location pointed to by the source-index register.
  3933. After the transfer is made, the source-index register is automatically
  3934. advanced. If the direction flag is 0 (CLD was executed), the source index
  3935. increments; if the direction flag is 1 (STD was executed), it decrements.
  3936. The increment or decrement is 1 if a byte is loaded, 2 if a word is loaded,
  3937. or 4 if a doubleword is loaded.
  3938.  
  3939. If the address-size attribute for this instruction is 16 bits, SI is used
  3940. for the source-index register; otherwise the address-size attribute is 32
  3941. bits, and the ESI register is used. The address of the source data is
  3942. determined solely by the contents of ESI/SI. Load the correct index value
  3943. into SI before executing the LODS instruction. LODSB, LODSW, LODSD are
  3944. synonyms for the byte, word, and doubleword LODS instructions.
  3945.  
  3946. LODS can be preceded by the REP prefix; however, LODS is used more typically
  3947. within a LOOP construct, because further processing of the data moved into
  3948. EAX, AX, or AL is usually necessary.
  3949.  
  3950. Flags Affected
  3951.  
  3952. None
  3953.  
  3954. Protected Mode Exceptions
  3955.  
  3956. #GP(0) for an illegal memory operand effective address in the CS, DS,
  3957. ES, FS, or GS segments; #SS(0) for an illegal address in the SS segment;
  3958. #PF(fault-code) for a page fault
  3959.  
  3960. Real Address Mode Exceptions
  3961.  
  3962. Interrupt 13 if any part of the operand would lie outside of the effective
  3963. address space from 0 to 0FFFFH
  3964.  
  3965. Virtual 8086 Mode Exceptions
  3966.  
  3967. Same exceptions as in Real Address Mode; #PF(fault-code) for a page
  3968. fault
  3969.  
  3970.  
  3971. LOOP/LOOPcond ── Loop Control with CX Counter
  3972.  
  3973. Opcode   Instruction  Clocks  Description
  3974.  
  3975. E2  cb   LOOP rel8    11+m    DEC count; jump short if count <> 0
  3976. E1  cb   LOOPE rel8   11+m    DEC count; jump short if count <> 0 and ZF=1
  3977. E1  cb   LOOPZ rel8   11+m    DEC count; jump short if count <> 0 and ZF=1
  3978. E0  cb   LOOPNE rel8  11+m    DEC count; jump short if count <> 0 and ZF=0
  3979. E0  cb   LOOPNZ rel8  11+m    DEC count; jump short if count <> 0 and ZF=0
  3980.  
  3981.  
  3982. Operation
  3983.  
  3984. IF AddressSize = 16 THEN CountReg is CX ELSE CountReg is ECX; FI;
  3985. CountReg  CountReg - 1;
  3986. IF instruction <> LOOP
  3987. THEN
  3988.    IF (instruction = LOOPE) OR (instruction = LOOPZ)
  3989.    THEN BranchCond  (ZF = 1) AND (CountReg <> 0);
  3990.    FI;
  3991.    IF (instruction = LOOPNE) OR (instruction = LOOPNZ)
  3992.    THEN BranchCond  (ZF = 0) AND (CountReg <> 0);
  3993.    FI;
  3994. FI;
  3995.  
  3996. IF BranchCond
  3997. THEN
  3998.    IF OperandSize = 16
  3999.    THEN
  4000.       IP  IP + SignExtend(rel8);
  4001.    ELSE (* OperandSize = 32 *)
  4002.       EIP  EIP + SignExtend(rel8);
  4003.    FI;
  4004. FI;
  4005.  
  4006. Description
  4007.  
  4008. LOOP decrements the count register without changing any of the flags.
  4009. Conditions are then checked for the form of LOOP being used. If the
  4010. conditions are met, a short jump is made to the label given by the operand
  4011. to LOOP. If the address-size attribute is 16 bits, the CX register is used
  4012. as the count register; otherwise the ECX register is used. The operand
  4013. of LOOP must be in the range from 128 (decimal) bytes before the
  4014. instruction to 127 bytes ahead of the instruction.
  4015.  
  4016. The LOOP instructions provide iteration control and combine loop index
  4017. management with conditional branching. Use the LOOP instruction by
  4018. loading an unsigned iteration count into the count register, then code the
  4019. LOOP at the end of a series of instructions to be iterated. The
  4020. destination of LOOP is a label that points to the beginning of the
  4021. iteration.
  4022.  
  4023. Flags Affected
  4024.  
  4025. None
  4026.  
  4027. Protected Mode Exceptions
  4028.  
  4029. #GP(0) if the offset jumped to is beyond the limits of the current code
  4030. segment
  4031.  
  4032. Real Address Mode Exceptions
  4033.  
  4034. None
  4035.  
  4036. Virtual 8086 Mode Exceptions
  4037.  
  4038. None
  4039.  
  4040.  
  4041. LSL ── Load Segment Limit
  4042.  
  4043. Opcode       Instruction      Clocks      Description
  4044.  
  4045. 0F  03 /r    LSL r16,r/m16    pm=20/21    Load: r16  segment limit,
  4046.                                           selector r/m16 (byte granular)
  4047. 0F  03 /r    LSL r32,r/m32    pm=20/21    Load: r32  segment limit,
  4048.                                           selector r/m32 (byte granular)
  4049. 0F  03 /r    LSL r16,r/m16    pm=25/26    Load: r16  segment limit,
  4050.                                           selector r/m16 (page granular)
  4051. 0F  03 /r    LSL r32,r/m32    pm=25/26    Load: r32  segment limit,
  4052.                                           selector r/m32 (page granular)
  4053.  
  4054.  
  4055. Description
  4056.  
  4057. The LSL instruction loads a register with an unscrambled segment limit,
  4058. and sets ZF to 1, provided that the source selector is visible at the CPL
  4059. weakened by RPL, and that the descriptor is a type accepted by LSL.
  4060. Otherwise, ZF is cleared to 0, and the destination register is unchanged.
  4061. The segment limit is loaded as a byte granular value. If the descriptor
  4062. has a page granular segment limit, LSL will translate it to a byte limit
  4063. before loading it in the destination register (shift left 12 the 20-bit
  4064. "raw" limit from descriptor, then OR with 00000FFFH).
  4065.  
  4066. The 32-bit forms of this instruction store the 32-bit byte granular limit
  4067. in the 16-bit destination register.
  4068.  
  4069. Code and data segment descriptors are valid for LSL.
  4070.  
  4071. The valid special segment and gate descriptor types for LSL are given
  4072. in the following table:
  4073.  
  4074. Type   Name                      Valid/Invalid
  4075.  
  4076.   0    Invalid                   Invalid
  4077.   1    Available 80286 TSS       Valid
  4078.   2    LDT                       Valid
  4079.   3    Busy 80286 TSS            Valid
  4080.   4    80286 call gate           Invalid
  4081.   5    80286/80386 task gate     Invalid
  4082.   6    80286 trap gate           Invalid
  4083.   7    80286 interrupt gate      Invalid
  4084.   8    Invalid                   Valid
  4085.   9    Available 80386 TSS       Valid
  4086.   A    Invalid                   Invalid
  4087.   B    Busy 80386 TSS            Valid
  4088.   C    80386 call gate           Invalid
  4089.   D    Invalid                   Invalid
  4090.   E    80386 trap gate           Invalid
  4091.   F    80386 interrupt gate      Invalid
  4092.  
  4093. Flags Affected
  4094.  
  4095. ZF as described above
  4096.  
  4097. Protected Mode Exceptions
  4098.  
  4099. #GP(0) for an illegal memory operand effective address in the CS, DS,
  4100. ES, FS, or GS segments; #SS(0) for an illegal address in the SS segment;
  4101. #PF(fault-code) for a page fault
  4102.  
  4103. Real Address Mode Exceptions
  4104.  
  4105. Interrupt 6; LSL is not recognized in Real Address Mode
  4106.  
  4107. Virtual 8086 Mode Exceptions
  4108.  
  4109. Same exceptions as in Real Address Mode
  4110.  
  4111.  
  4112. LTR ── Load Task Register
  4113.  
  4114. Opcode       Instruction    Clocks    Description
  4115.  
  4116. 0F  00 /3    LTR r/m16      pm=23/27  Load EA word into task register
  4117.  
  4118.  
  4119. Description
  4120.  
  4121. LTR loads the task register from the source register or memory location
  4122. specified by the operand. The loaded task state segment is marked busy.
  4123. A task switch does not occur.
  4124.  
  4125. LTR is used only in operating system software; it is not used in
  4126. application programs.
  4127.  
  4128. Flags Affected
  4129.  
  4130. None
  4131.  
  4132. Protected Mode Exceptions
  4133.  
  4134. #GP(0) for an illegal memory operand effective address in the CS, DS,
  4135. ES, FS, or GS segments; #SS(0) for an illegal address in the SS segment;
  4136. #GP(0) if the current privilege level is not 0; #GP(selector) if the object
  4137. named by the source selector is not a TSS or is already busy;
  4138. #NP(selector) if the TSS is marked "not present"; #PF(fault-code) for
  4139. a page fault
  4140.  
  4141. Real Address Mode Exceptions
  4142.  
  4143. Interrupt 6; LTR is not recognized in Real Address Mode
  4144.  
  4145. Virtual 8086 Mode Exceptions
  4146.  
  4147. Same exceptions as in Real Address Mode
  4148.  
  4149. Notes
  4150.  
  4151. The operand-size attribute has no effect on this instruction.
  4152.  
  4153.  
  4154. MOV ── Move Data
  4155.  
  4156.  
  4157. Opcode   Instruction       Clocks        Description
  4158.  
  4159. 88  /r   MOV r/m8,r8       2/2           Move byte register to r/m byte
  4160. 89  /r   MOV r/m16,r16     2/2           Move word register to r/m word
  4161. 89  /r   MOV r/m32,r32     2/2           Move dword register to r/m dword
  4162. 8A  /r   MOV r8,r/m8       2/4           Move r/m byte to byte register
  4163. 8B  /r   MOV r16,r/m16     2/4           Move r/m word to word register
  4164. 8B  /r   MOV r32,r/m32     2/4           Move r/m dword to dword register
  4165. 8C  /r   MOV r/m16,Sreg    2/2           Move segment register to r/m word
  4166. 8D  /r   MOV Sreg,r/m16    2/5,pm=18/19  Move r/m word to segment register
  4167. A0       MOV AL,moffs8     4             Move byte at (seg:offset) to AL
  4168. A1       MOV AX,moffs16    4             Move word at (seg:offset) to AX
  4169. A1       MOV EAX,moffs32   4             Move dword at (seg:offset) to EAX
  4170. A2       MOV moffs8,AL     2             Move AL to (seg:offset)
  4171. A3       MOV moffs16,AX    2             Move AX to (seg:offset)
  4172. A3       MOV moffs32,EAX   2             Move EAX to (seg:offset)
  4173. B0 + rb  MOV reg8,imm8     2             Move immediate byte to register
  4174. B8 + rw  MOV reg16,imm16   2             Move immediate word to register
  4175. B8 + rd  MOV reg32,imm32   2             Move immediate dword to register
  4176. C6       MOV r/m8,imm8     2/2           Move immediate byte to r/m byte
  4177. C7       MOV r/m16,imm16   2/2           Move immediate word to r/m word
  4178. C7       MOV r/m32,imm32   2/2           Move immediate dword to r/m dword
  4179.  
  4180.  
  4181. ───────────────────────────────────────────────────────────────────────────
  4182. NOTES:
  4183.   moffs8, moffs16, and moffs32 all consist of a simple offset relative
  4184.   to the segment base. The 8, 16, and 32 refer to the size of the data. The
  4185.   address-size attribute of the instruction determines the size of the
  4186.   offset, either 16 or 32 bits.
  4187. ───────────────────────────────────────────────────────────────────────────
  4188.  
  4189. Operation
  4190.  
  4191. DEST  SRC;
  4192.  
  4193. Description
  4194.  
  4195. MOV copies the second operand to the first operand.
  4196.  
  4197. If the destination operand is a segment register (DS, ES, SS, etc.), then
  4198. data from a descriptor is also loaded into the register. The data for the
  4199. register is obtained from the descriptor table entry for the selector
  4200. given. A null selector (values 0000-0003) can be loaded into DS and ES
  4201. registers without causing an exception; however, use of DS or ES causes a
  4202. #GP(0), and no memory reference occurs.
  4203.  
  4204. A MOV into SS inhibits all interrupts until after the execution of the
  4205. next instruction (which is presumably a MOV into eSP).
  4206.  
  4207. Loading a segment register under 80386 Protected Mode results in special
  4208. checks and actions, as described in the following listing:
  4209.  
  4210. IF SS is loaded;
  4211. THEN
  4212.    IF selector is null THEN #GP(0);
  4213. FI;
  4214.    Selector index must be within its descriptor table limits else
  4215.       #GP(selector);
  4216.    Selector's RPL must equal CPL else #GP(selector);
  4217. AR byte must indicate a writable data segment else #GP(selector);
  4218.    DPL in the AR byte must equal CPL else #GP(selector);
  4219.    Segment must be marked present else #SS(selector);
  4220.    Load SS with selector;
  4221.    Load SS with descriptor.
  4222. FI;
  4223. IF DS, ES, FS or GS is loaded with non-null selector;
  4224. THEN
  4225.    Selector index must be within its descriptor table limits
  4226.       else #GP(selector);
  4227.    AR byte must indicate data or readable code segment else
  4228.       #GP(selector);
  4229.    IF data or nonconforming code segment
  4230.    THEN both the RPL and the CPL must be less than or equal to DPL in
  4231.       AR byte;
  4232.    ELSE #GP(selector);
  4233.    FI;
  4234.    Segment must be marked present else #NP(selector);
  4235.    Load segment register with selector;
  4236.    Load segment register with descriptor;
  4237. FI;
  4238. IF DS, ES, FS or GS is loaded with a null selector;
  4239. THEN
  4240.    Load segment register with selector;
  4241.    Clear descriptor valid bit;
  4242. FI;
  4243.  
  4244. Flags Affected
  4245.  
  4246. None
  4247.  
  4248. Protected Mode Exceptions
  4249.  
  4250. #GP, #SS, and #NP if a segment register is being loaded; otherwise,
  4251. #GP(0) if the destination is in a nonwritable segment; #GP(0) for an
  4252. illegal memory operand effective address in the CS, DS, ES, FS, or GS
  4253. segments; #SS(0) for an illegal address in the SS segment; #PF(fault-code)
  4254. for a page fault
  4255.  
  4256. Real Address Mode Exceptions
  4257.  
  4258. Interrupt 13 if any part of the operand would lie outside of the effective
  4259. address space from 0 to 0FFFFH
  4260.  
  4261. Virtual 8086 Mode Exceptions
  4262.  
  4263. Same exceptions as in Real Address Mode; #PF(fault-code) for a page
  4264. fault
  4265.  
  4266.  
  4267. MOV ── Move to/from Special Registers
  4268.  
  4269. Opcode      Instruction           Clocks   Description
  4270.  
  4271. 0F  20 /r   MOV r32,CR0/CR2/CR3   6        Move (control register) to
  4272.                                            (register)
  4273. 0F  22 /r   MOV CR0/CR2/CR3,r32   10/4/5   Move (register) to (control
  4274.                                            register)
  4275. 0F  21 /r   MOV r32,DR0 -- 3      22       Move (debug register) to
  4276.                                            (register)
  4277. 0F  21 /r   MOV r32,DR6/DR7       14       Move (debug register) to
  4278.                                            (register)
  4279. 0F  23 /r   MOV DR0 -- 3,r32      22       Move (register) to (debug
  4280.                                            register)
  4281. 0F  23 /r   MOV DR6/DR7,r32       16       Move (register) to (debug
  4282.                                            register)
  4283. 0F  24 /r   MOV r32,TR6/TR7       12       Move (test register) to
  4284.                                            (register)
  4285. 0F  26 /r   MOV TR6/TR7,r32       12       Move (register) to (test
  4286.                                            register)
  4287.  
  4288.  
  4289. Operation
  4290.  
  4291. DEST  SRC;
  4292.  
  4293. Description
  4294.  
  4295. The above forms of MOV store or load the following special registers in
  4296. or from a general purpose register:
  4297.  
  4298.   ■  Control registers CR0, CR2, and CR3
  4299.   ■  Debug Registers DR0, DR1, DR2, DR3, DR6, and DR7
  4300.   ■  Test Registers TR6 and TR7
  4301.  
  4302. 32-bit operands are always used with these instructions, regardless of the
  4303. operand-size attribute.
  4304.  
  4305. Flags Affected
  4306.  
  4307. OF, SF, ZF, AF, PF, and CF are undefined
  4308.  
  4309. Protected Mode Exceptions
  4310.  
  4311. #GP(0) if the current privilege level is not 0
  4312.  
  4313. Real Address Mode Exceptions
  4314.  
  4315. None
  4316.  
  4317. Virtual 8086 Mode Exceptions
  4318.  
  4319. #GP(0) if instruction execution is attempted
  4320.  
  4321. Notes
  4322.  
  4323. The instructions must be executed at privilege level 0 or in real-address
  4324. mode; otherwise, a protection exception will be raised.
  4325.  
  4326. The reg field within the ModRM byte specifies which of the special
  4327. registers in each category is involved. The two bits in the  field are
  4328. always 11. The r/m field specifies the general register involved.
  4329.  
  4330.  
  4331. MOVS/MOVSB/MOVSW/MOVSD ── Move Data from String to String
  4332.  
  4333. Opcode  Instruction      Clocks   Description
  4334.  
  4335. A4      MOVS m8,m8       7        Move byte [(E)SI] to ES:[(E)DI]
  4336. A5      MOVS m16,m16     7        Move word [(E)SI] to ES:[(E)DI]
  4337. A5      MOVS m32,m32     7        Move dword [(E)SI] to ES:[(E)DI]
  4338. A4      MOVSB            7        Move byte DS:[(E)SI] to ES:[(E)DI]
  4339. A5      MOVSW            7        Move word DS:[(E)SI] to ES:[(E)DI]
  4340. A5      MOVSD            7        Move dword DS:[(E)SI] to ES:[(E)DI]
  4341.  
  4342.  
  4343. Operation
  4344.  
  4345. IF (instruction = MOVSD) OR (instruction has doubleword operands)
  4346. THEN OperandSize  32;
  4347. ELSE OperandSize  16;
  4348. IF AddressSize = 16
  4349. THEN use SI for source-index and DI for destination-index;
  4350. ELSE (* AddressSize = 32 *)
  4351.    use ESI for source-index and EDI for destination-index;
  4352. FI;
  4353. IF byte type of instruction
  4354. THEN
  4355.    [destination-index]  [source-index]; (* byte assignment *)
  4356.    IF DF = 0 THEN IncDec  1 ELSE IncDec  -1; FI;
  4357. ELSE
  4358.    IF OperandSize = 16
  4359.    THEN
  4360.       [destination-index]  [source-index]; (* word assignment *)
  4361.       IF DF = 0 THEN IncDec  2 ELSE IncDec  -2; FI;
  4362.    ELSE (* OperandSize = 32 *)
  4363.       [destination-index]  [source-index]; (* doubleword assignment *)
  4364.       IF DF = 0 THEN IncDec  4 ELSE IncDec  -4; FI;
  4365.    FI;
  4366. FI;
  4367. source-index  source-index + IncDec;
  4368. destination-index  destination-index + IncDec;
  4369.  
  4370. Description
  4371.  
  4372. MOVS copies the byte or word at [(E)SI] to the byte or word at
  4373. ES:[(E)DI]. The destination operand must be addressable from the ES
  4374. register; no segment override is possible for the destination. A segment
  4375. override can be used for the source operand; the default is DS.
  4376.  
  4377. The addresses of the source and destination are determined solely by the
  4378. contents of (E)SI and (E)DI. Load the correct index values into (E)SI
  4379. and (E)DI before executing the MOVS instruction. MOVSB, MOVSW,
  4380. and MOVSD are synonyms for the byte, word, and doubleword MOVS
  4381. instructions.
  4382.  
  4383. After the data is moved, both (E)SI and (E)DI are advanced
  4384. automatically. If the direction flag is 0 (CLD was executed), the registers
  4385. are incremented; if the direction flag is 1 (STD was executed), the
  4386. registers are decremented. The registers are incremented or decremented by 1
  4387. if a byte was moved, 2 if a word was moved, or 4 if a doubleword was moved.
  4388.  
  4389. MOVS can be preceded by the REP prefix for block movement of CX
  4390. bytes or words. Refer to the REP instruction for details of this operation.
  4391.  
  4392. Flags Affected
  4393.  
  4394. None
  4395.  
  4396. Protected Mode Exceptions
  4397.  
  4398. #GP(0) if the result is in a nonwritable segment; #GP(0) for an illegal
  4399. memory operand effective address in the CS, DS, ES, FS, or GS
  4400. segments; #SS(0) for an illegal address in the SS segment; #PF(fault-code)
  4401. for a page fault
  4402.  
  4403. Real Address Mode Exceptions
  4404.  
  4405. Interrupt 13 if any part of the operand would lie outside of the effective
  4406. address space from 0 to 0FFFFH
  4407.  
  4408. Virtual 8086 Mode Exceptions
  4409.  
  4410. Same exceptions as in Real Address Mode; #PF(fault-code) for a page
  4411. fault
  4412.  
  4413.  
  4414. MOVSX ── Move with Sign-Extend
  4415.  
  4416. Opcode     Instruction        Clocks   Description
  4417.  
  4418. 0F  BE /r  MOVSX r16,r/m8     3/6      Move byte to word with sign-extend
  4419. 0F  BE /r  MOVSX r32,r/m8     3/6      Move byte to dword, sign-extend
  4420. 0F  BF /r  MOVSX r32,r/m16    3/6      Move word to dword, sign-extend
  4421.  
  4422.  
  4423. Operation
  4424.  
  4425. DEST  SignExtend(SRC);
  4426.  
  4427. Description
  4428.  
  4429. MOVSX reads the contents of the effective address or register as a byte
  4430. or a word, sign-extends the value to the operand-size attribute of the
  4431. instruction (16 or 32 bits), and stores the result in the destination
  4432. register.
  4433.  
  4434. Flags Affected
  4435.  
  4436. None
  4437.  
  4438. Protected Mode Exceptions
  4439.  
  4440. #GP(0) for an illegal memory operand effective address in the CS, DS,
  4441. ES, FS or GS segments; #SS(0) for an illegal address in the SS segment;
  4442. #PF(fault-code) for a page fault
  4443.  
  4444. Real Address Mode Exceptions
  4445.  
  4446. Interrupt 13 if any part of the operand would lie outside of the effective
  4447. address space from 0 to 0FFFFH
  4448.  
  4449. Virtual 8086 Mode Exceptions
  4450.  
  4451. Same exceptions as in Real Address Mode; #PF(fault-code) for a page
  4452. fault
  4453.  
  4454.  
  4455. MOVZX ── Move with Zero-Extend
  4456.  
  4457. Opcode      Instruction        Clocks   Description
  4458.  
  4459. 0F  B6 /r   MOVZX r16,r/m8     3/6      Move byte to word with zero-extend
  4460. 0F  B6 /r   MOVZX r32,r/m8     3/6      Move byte to dword, zero-extend
  4461. 0F  B7 /r   MOVZX r32,r/m16    3/6      Move word to dword, zero-extend
  4462.  
  4463.  
  4464. Operation
  4465.  
  4466. DEST  ZeroExtend(SRC);
  4467.  
  4468. Description
  4469.  
  4470. MOVZX reads the contents of the effective address or register as a byte
  4471. or a word, zero extends the value to the operand-size attribute of the
  4472. instruction (16 or 32 bits), and stores the result in the destination
  4473. register.
  4474.  
  4475. Flags Affected
  4476.  
  4477. None
  4478.  
  4479. Protected Mode Exceptions
  4480.  
  4481. #GP(0) for an illegal memory operand effective address in the CS, DS,
  4482. ES, FS, or GS segments; #SS(0) for an illegal address in the SS segment;
  4483. #PF(fault-code) for a page fault
  4484.  
  4485. Real Address Mode Exceptions
  4486.  
  4487. Interrupt 13 if any part of the operand would lie outside of the effective
  4488. address space from 0 to 0FFFFH
  4489.  
  4490. Virtual 8086 Mode Exceptions
  4491.  
  4492. Same exceptions as in Real Address Mode; #PF(fault-code) for a page
  4493. fault
  4494.  
  4495.  
  4496. MUL ── Unsigned Multiplication of AL or AX
  4497.  
  4498. Opcode  Instruction     Clocks       Description
  4499.  
  4500. F6  /4  MUL AL,r/m8     9-14/12-17   Unsigned multiply (AX  AL * r/m byte)
  4501. F7  /4  MUL AX,r/m16    9-22/12-25   Unsigned multiply (DX:AX  AX * r/m
  4502.                                      word)
  4503. F7  /4  MUL EAX,r/m32   9-38/12-41   Unsigned multiply (EDX:EAX  EAX * r/m
  4504.                                      dword)
  4505.  
  4506.  
  4507. ───────────────────────────────────────────────────────────────────────────
  4508. NOTES:
  4509.   The 80386 uses an early-out multiply algorithm. The actual number of
  4510.   clocks depends on the position of the most significant bit in the 
  4511.   optimizing multiplier, shown underlined above. The optimization occurs
  4512.   for positive and negative multiplier values. Because of the early-out
  4513.   algorithm, clock counts given are minimum to maximum. To calculate the
  4514.   actual clocks, use the following formula:
  4515.  
  4516.     Actual clock = if  <> 0 then max(ceiling(log{2} │m│), 3) + 6 clocks;
  4517.  
  4518.     Actual clock = if  = 0 then 9 clocks
  4519.  
  4520.   where m is the multiplier.
  4521. ───────────────────────────────────────────────────────────────────────────
  4522.  
  4523. Operation
  4524.  
  4525. IF byte-size operation
  4526. THEN AX  AL * r/m8
  4527. ELSE (* word or doubleword operation *)
  4528.    IF OperandSize = 16
  4529.    THEN DX:AX  AX * r/m16
  4530.    ELSE (* OperandSize = 32 *)
  4531.       EDX:EAX  EAX * r/m32
  4532.    FI;
  4533. FI;
  4534.  
  4535. Description
  4536.  
  4537. MUL performs unsigned multiplication. Its actions depend on the size
  4538. of its operand, as follows:
  4539.  
  4540.   ■  A byte operand is multiplied by AL; the result is left in AX. The
  4541.      carry and overflow flags are set to 0 if AH is 0; otherwise, they are
  4542.      set to 1.
  4543.  
  4544.   ■  A word operand is multiplied by AX; the result is left in DX:AX.
  4545.      DX contains the high-order 16 bits of the product. The carry and
  4546.      overflow flags are set to 0 if DX is 0; otherwise, they are set to 1.
  4547.  
  4548.   ■  A doubleword operand is multiplied by EAX and the result is left in
  4549.      EDX:EAX. EDX contains the high-order 32 bits of the product. The
  4550.      carry and overflow flags are set to 0 if EDX is 0; otherwise, they are
  4551.      set to 1.
  4552.  
  4553. Flags Affected
  4554.  
  4555. OF and CF as described above; SF, ZF, AF, PF, and CF are undefined
  4556.  
  4557. Protected Mode Exceptions
  4558.  
  4559. #GP(0) for an illegal memory operand effective address in the CS, DS,
  4560. ES, FS, or GS segments; #SS(0) for an illegal address in the SS segment;
  4561. #PF(fault-code) for a page fault
  4562.  
  4563. Real Address Mode Exceptions
  4564.  
  4565. Interrupt 13 if any part of the operand would lie outside of the effective
  4566. address space from 0 to 0FFFFH
  4567.  
  4568. Virtual 8086 Mode Exceptions
  4569.  
  4570. Same exceptions as in Real Address Mode; #PF(fault-code) for a page
  4571. fault
  4572.  
  4573.  
  4574. NEG ── Two's Complement Negation
  4575.  
  4576. Opcode  Instruction   Clocks    Description
  4577.  
  4578. F6  /3  NEG r/m8      2/6       Two's complement negate r/m byte
  4579. F7  /3  NEG r/m16     2/6       Two's complement negate r/m word
  4580. F7  /3  NEG r/m32     2/6       Two's complement negate r/m dword
  4581.  
  4582.  
  4583. Operation
  4584.  
  4585. IF r/m = 0 THEN CF  0 ELSE CF  1; FI;
  4586. r/m  - r/m;
  4587.  
  4588. Description
  4589.  
  4590. NEG replaces the value of a register or memory operand with its two's
  4591. complement. The operand is subtracted from zero, and the result is placed
  4592. in the operand.
  4593.  
  4594. The carry flag is set to 1, unless the operand is zero, in which case the
  4595. carry flag is cleared to 0.
  4596.  
  4597. Flags Affected
  4598.  
  4599. CF as described above; OF, SF, ZF, and PF as described in Appendix C
  4600.  
  4601. Protected Mode Exceptions
  4602.  
  4603. #GP(0) if the result is in a nonwritable segment; #GP(0) for an illegal
  4604. memory operand effective address in the CS, DS, ES, FS, or GS
  4605. segments; #SS(0) for an illegal address in the SS segment; #PF(fault-code)
  4606. for a page fault
  4607.  
  4608. Real Address Mode Exceptions
  4609.  
  4610. Interrupt 13 if any part of the operand would lie outside of the effective
  4611. address space from 0 to 0FFFFH
  4612.  
  4613. Virtual 8086 Mode Exceptions
  4614.  
  4615. Same exceptions as in real-address mode; #PF(fault-code) for a page
  4616. fault
  4617.  
  4618.  
  4619. NOP ── No Operation
  4620.  
  4621. Opcode  Instruction   Clocks    Description
  4622.  
  4623. 90      NOP           3         No operation
  4624.  
  4625.  
  4626. Description
  4627.  
  4628. NOP performs no operation. NOP is a one-byte instruction that takes
  4629. up space but affects none of the machine context except (E)IP.
  4630.  
  4631. NOP is an alias mnemonic for the XCHG (E)AX, (E)AX instruction.
  4632.  
  4633. Flags Affected
  4634.  
  4635. None
  4636.  
  4637. Protected Mode Exceptions
  4638.  
  4639. None
  4640.  
  4641. Real Address Mode Exceptions
  4642.  
  4643. None
  4644.  
  4645. Virtual 8086 Mode Exceptions
  4646.  
  4647. None
  4648.  
  4649.  
  4650. NOT ── One's Complement Negation
  4651.  
  4652. Opcode    Instruction   Clocks    Description
  4653.  
  4654. F6   /2   NOT r/m8       2/6      Reverse each bit of r/m byte
  4655. F7   /2   NOT r/m16      2/6      Reverse each bit of r/m word
  4656. F7   /2   NOT r/m32      2/6      Reverse each bit of r/m dword
  4657.  
  4658.  
  4659. Operation
  4660.  
  4661. r/m  NOT r/m;
  4662.  
  4663. Description
  4664.  
  4665. NOT inverts the operand; every 1 becomes a 0, and vice versa.
  4666.  
  4667. Flags Affected
  4668.  
  4669. None
  4670.  
  4671. Protected Mode Exceptions
  4672.  
  4673. #GP(0) if the result is in a nonwritable segment; #GP(0) for an illegal
  4674. memory operand effective address in the CS, DS, ES, FS, or GS
  4675. segments; #SS(0) for an illegal address in the SS segment; #PF(fault-code)
  4676. for a page fault
  4677.  
  4678. Real Address Mode Exceptions
  4679.  
  4680. Interrupt 13 if any part of the operand would lie outside of the effective
  4681. address space from 0 to 0FFFFH
  4682.  
  4683. Virtual 8086 Mode Exceptions
  4684.  
  4685. Same exceptions as in real-address mode; #PF(fault-code) for a page
  4686. fault
  4687.  
  4688.  
  4689. OR ── Logical Inclusive OR
  4690.  
  4691. Opcode       Instruction       Clocks    Description
  4692.  
  4693. 0C  ib       OR AL,imm8        2         OR immediate byte to AL
  4694. 0D  iw       OR AX,imm16       2         OR immediate word to AX
  4695. 0D  id       OR EAX,imm32      2         OR immediate dword to EAX
  4696. 80  /1 ib    OR r/m8,imm8      2/7       OR immediate byte to r/m byte
  4697. 81  /1 iw    OR r/m16,imm16    2/7       OR immediate word to r/m word
  4698. 81  /1 id    OR r/m32,imm32    2/7       OR immediate dword to r/m dword
  4699. 83  /1 ib    OR r/m16,imm8     2/7       OR sign-extended immediate byte
  4700.                                          with r/m word
  4701. 83  /1 ib    OR r/m32,imm8     2/7       OR sign-extended immediate byte
  4702.                                          with r/m dword
  4703. 08  /r       OR r/m8,r8        2/6       OR byte register to r/m byte
  4704. 09  /r       OR r/m16,r16      2/6       OR word register to r/m word
  4705. 09  /r       OR r/m32,r32      2/6       OR dword register to r/m dword
  4706. 0A  /r       OR r8,r/m8        2/7       OR byte register to r/m byte
  4707. 0B  /r       OR r16,r/m16      2/7       OR word register to r/m word
  4708. 0B  /r       OR r32,r/m32      2/7       OR dword register to r/m dword
  4709.  
  4710.  
  4711. Operation
  4712.  
  4713. DEST  DEST OR SRC;
  4714. CF  0;
  4715. OF  0
  4716.  
  4717. Description
  4718.  
  4719. OR computes the inclusive OR of its two operands and places the result
  4720. in the first operand. Each bit of the result is 0 if both corresponding
  4721. bits of the operands are 0; otherwise, each bit is 1.
  4722.  
  4723. Flags Affected
  4724.  
  4725. OF  0, CF  0; SF, ZF, and PF as described in Appendix C; AF is
  4726. undefined
  4727.  
  4728. Protected Mode Exceptions
  4729.  
  4730. #GP(0) if the result is in a nonwritable segment; #GP(0) for an illegal
  4731. memory operand effective address in the CS, DS, ES, FS, or GS
  4732. segments; #SS(0) for an illegal address in the SS segment; #PF(fault-code)
  4733. for a page fault
  4734.  
  4735. Real Address Mode Exceptions
  4736.  
  4737. Interrupt 13 if any part of the operand would lie outside of the effective
  4738. address space from 0 to 0FFFFH
  4739.  
  4740. Virtual 8086 Mode Exceptions
  4741.  
  4742. Same exceptions as in real-address mode; #PF(fault-code) for a page
  4743. fault
  4744.  
  4745.  
  4746. OUT ── Output to Port
  4747.  
  4748. Opcode    Instruction     Clocks          Description
  4749.  
  4750. E6  ib    OUT imm8,AL     10,pm=4*/24**   Output byte AL to immediate port
  4751.                                           number
  4752. E7  ib    OUT imm8,AX     10,pm=4*/24**   Output word AL to immediate port
  4753.                                           number
  4754. E7  ib    OUT imm8,EAX    10,pm=4*/24**   Output dword AL to immediate
  4755.                                           port number
  4756. EE        OUT DX,AL       11,pm=5*/25**   Output byte AL to port number in
  4757. DX
  4758. EF        OUT DX,AX       11,pm=5*/25**   Output word AL to port number in
  4759. DX
  4760. EF        OUT DX,EAX      11,pm=5*/25**   Output dword AL to port number
  4761.                                           in DX
  4762.  
  4763.  
  4764. ───────────────────────────────────────────────────────────────────────────
  4765. NOTES:
  4766.    *If CPL ≤ IOPL
  4767.   **If CPL > IOPL or if in virtual 8086 mode
  4768. ───────────────────────────────────────────────────────────────────────────
  4769.  
  4770. Operation
  4771.  
  4772. IF (PE = 1) AND ((VM = 1) OR (CPL > IOPL))
  4773. THEN (* Virtual 8086 mode, or protected mode with CPL > IOPL *)
  4774.    IF NOT I-O-Permission (DEST, width(DEST))
  4775.    THEN #GP(0);
  4776.    FI;
  4777. FI;
  4778. [DEST]  SRC; (* I/O address space used *)
  4779.  
  4780. Description
  4781.  
  4782. OUT transfers a data byte or data word from the register (AL, AX, or
  4783. EAX) given as the second operand to the output port numbered by the
  4784. first operand. Output to any port from 0 to 65535 is performed by placing
  4785. the port number in the DX register and then using an OUT instruction
  4786. with DX as the first operand. If the instruction contains an eight-bit port
  4787. ID, that value is zero-extended to 16 bits.
  4788.  
  4789. Flags Affected
  4790.  
  4791. None
  4792.  
  4793. Protected Mode Exceptions
  4794.  
  4795. #GP(0) if the current privilege level is higher (has less privilege) than
  4796. IOPL and any of the corresponding I/O permission bits in TSS equals 1
  4797.  
  4798. Real Address Mode Exceptions
  4799.  
  4800. None
  4801.  
  4802. Virtual 8086 Mode Exceptions
  4803.  
  4804. #GP(0) fault if any of the corresponding I/O permission bits in TSS
  4805. equals 1
  4806.  
  4807.  
  4808. OUTS/OUTSB/OUTSW/OUTSD ── Output String to Port
  4809.  
  4810. Opcode   Instruction     Clocks          Description
  4811.  
  4812. 6E       OUTS DX,r/m8    14,pm=8*/28**   Output byte [(E)SI] to port in DX
  4813. 6F       OUTS DX,r/m16   14,pm=8*/28**   Output word [(E)SI] to port in DX
  4814. 6F       OUTS DX,r/m32   14,pm=8*/28**   Output dword [(E)SI] to port in DX
  4815. 6E       OUTSB           14,pm=8*/28**   Output byte DS:[(E)SI] to port in
  4816.                                          DX
  4817. 6F       OUTSW           14,pm=8*/28**   Output word DS:[(E)SI] to port in
  4818.                                          DX
  4819. 6F       OUTSD           14,pm=8*/28**   Output dword DS:[(E)SI] to port in
  4820.                                          DX
  4821.  
  4822.  
  4823. ───────────────────────────────────────────────────────────────────────────
  4824. NOTES:
  4825.    *If CPL ≤ IOPL
  4826.   **If CPL > IOPL or if in virtual 8086 mode
  4827. ───────────────────────────────────────────────────────────────────────────
  4828.  
  4829. Operation
  4830.  
  4831. IF AddressSize = 16
  4832. THEN use SI for source-index;
  4833. ELSE (* AddressSize = 32 *)
  4834.    use ESI for source-index;
  4835. FI;
  4836.  
  4837. IF (PE = 1) AND ((VM = 1) OR (CPL > IOPL))
  4838. THEN (* Virtual 8086 mode, or protected mode with CPL > IOPL *)
  4839.    IF NOT I-O-Permission (DEST, width(DEST))
  4840.    THEN #GP(0);
  4841.    FI;
  4842. FI;
  4843. IF byte type of instruction
  4844. THEN
  4845.    [DX]  [source-index]; (* Write byte at DX I/O address *)
  4846.    IF DF = 0 THEN IncDec  1 ELSE IncDec  -1; FI;
  4847. FI;
  4848. IF OperandSize = 16
  4849. THEN
  4850.    [DX]  [source-index]; (* Write word at DX I/O address *)
  4851.    IF DF = 0 THEN IncDec  2 ELSE IncDec  -2; FI;
  4852. FI;
  4853. IF OperandSize = 32
  4854. THEN
  4855.    [DX]  [source-index]; (* Write dword at DX I/O address *)
  4856.    IF DF = 0 THEN IncDec  4 ELSE IncDec  -4; FI;
  4857.    FI;
  4858. FI;
  4859. source-index  source-index + IncDec;
  4860.  
  4861. Description
  4862.  
  4863. OUTS transfers data from the memory byte, word, or doubleword at the
  4864. source-index register to the output port addressed by the DX register. If
  4865. the address-size attribute for this instruction is 16 bits, SI is used for
  4866. the source-index register; otherwise, the address-size attribute is 32 bits,
  4867. and ESI is used for the source-index register.
  4868.  
  4869. OUTS does not allow specification of the port number as an immediate value.
  4870. The port must be addressed through the DX register value. Load the correct
  4871. value into DX before executing the OUTS instruction.
  4872.  
  4873. The address of the source data is determined by the contents of
  4874. source-index register. Load the correct index value into SI or ESI before
  4875. executing the OUTS instruction.
  4876.  
  4877. After the transfer, source-index register is advanced automatically. If
  4878. the direction flag is 0 (CLD was executed), the source-index register is
  4879. incremented; if the direction flag is 1 (STD was executed), it is
  4880. decremented. The amount of the increment or decrement is 1 if a byte is
  4881. output, 2 if a word is output, or 4 if a doubleword is output.
  4882.  
  4883. OUTSB, OUTSW, and OUTSD are synonyms for the byte, word, and
  4884. doubleword OUTS instructions. OUTS can be preceded by the REP
  4885. prefix for block output of CX bytes or words. Refer to the REP
  4886. instruction for details on this operation.
  4887.  
  4888. Flags Affected
  4889.  
  4890. None
  4891.  
  4892. Protected Mode Exceptions
  4893.  
  4894. #GP(0) if CPL is greater than IOPL and any of the corresponding I/O
  4895. permission bits in TSS equals 1; #GP(0) for an illegal memory operand
  4896. effective address in the CS, DS, or ES segments; #SS(0) for an illegal
  4897. address in the SS segment; #PF(fault-code) for a page fault
  4898.  
  4899. Real Address Mode Exceptions
  4900.  
  4901. Interrupt 13 if any part of the operand would lie outside of the effective
  4902. address space from 0 to 0FFFFH
  4903.  
  4904. Virtual 8086 Mode Exceptions
  4905.  
  4906. #GP(0) fault if any of the corresponding I/O permission bits in TSS
  4907. equals 1; #PF(fault-code) for a page fault
  4908.  
  4909.  
  4910. POP ── Pop a Word from the Stack
  4911.  
  4912. Opcode      Instruction   Clocks     Description
  4913.  
  4914. 8F   /0     POP m16       5          Pop top of stack into memory word
  4915. 8F   /0     POP m32       5          Pop top of stack into memory dword
  4916. 58 + rw     POP r16       4          Pop top of stack into word register
  4917. 58 + rd     POP r32       4          Pop top of stack into dword register
  4918. 1F          POP DS        7,pm=21    Pop top of stack into DS
  4919. 07          POP ES        7,pm=21    Pop top of stack into ES
  4920. 17          POP SS        7,pm=21    Pop top of stack into SS
  4921. 0F   A1     POP FS        7,pm=21    Pop top of stack into FS
  4922. 0F   A9     POP GS        7,pm=21    Pop top of stack into GS
  4923.  
  4924.  
  4925. Operation
  4926.  
  4927. IF StackAddrSize = 16
  4928. THEN
  4929.    IF OperandSize = 16
  4930.    THEN
  4931.       DEST  (SS:SP); (* copy a word *)
  4932.       SP  SP + 2;
  4933.    ELSE (* OperandSize = 32 *)
  4934.       DEST  (SS:SP); (* copy a dword *)
  4935.       SP  SP + 4;
  4936.    FI;
  4937. ELSE (* StackAddrSize = 32 * )
  4938.    IF OperandSize = 16
  4939.    THEN
  4940.       DEST  (SS:ESP); (* copy a word *)
  4941.       ESP  ESP + 2;
  4942.    ELSE (* OperandSize = 32 *)
  4943.       DEST  (SS:ESP); (* copy a dword *)
  4944.       ESP  ESP + 4;
  4945.    FI;
  4946. FI;
  4947.  
  4948. Description
  4949.  
  4950. POP replaces the previous contents of the memory, the register, or the
  4951. segment register operand with the word on the top of the 80386 stack,
  4952. addressed by SS:SP (address-size attribute of 16 bits) or SS:ESP
  4953. (addresssize attribute of 32 bits). The stack pointer SP is incremented
  4954. by 2 for an operand-size of 16 bits or by 4 for an operand-size of 32 bits.
  4955. It then points to the new top of stack.
  4956.  
  4957. POP CS is not an 80386 instruction. Popping from the stack into the CS
  4958. register is accomplished with a RET instruction.
  4959.  
  4960. If the destination operand is a segment register (DS, ES, FS, GS, or
  4961. SS), the value popped must be a selector. In protected mode, loading the
  4962. selector initiates automatic loading of the descriptor information
  4963. associated with that selector into the hidden part of the segment register;
  4964. loading also initiates validation of both the selector and the descriptor
  4965. information.
  4966.  
  4967. A null value (0000-0003) may be popped into the DS, ES, FS, or GS
  4968. register without causing a protection exception. An attempt to reference
  4969. a segment whose corresponding segment register is loaded with a null
  4970. value causes a #GP(0) exception. No memory reference occurs. The saved
  4971. value of the segment register is null.
  4972.  
  4973. A POP SS instruction inhibits all interrupts, including NMI, until after
  4974. execution of the next instruction. This allows sequential execution of POP
  4975. SS and POP eSP instructions without danger of having an invalid stack
  4976. during an interrupt. However, use of the LSS instruction is the preferred
  4977. method of loading the SS and eSP registers.
  4978.  
  4979. Loading a segment register while in protected mode results in special
  4980. checks and actions, as described in the following listing:
  4981.  
  4982. IF SS is loaded:
  4983.    IF selector is null THEN #GP(0);
  4984.    Selector index must be within its descriptor table limits ELSE
  4985.       #GP(selector);
  4986.    Selector's RPL must equal CPL ELSE #GP(selector);
  4987.    AR byte must indicate a writable data segment ELSE #GP(selector);
  4988.    DPL in the AR byte must equal CPL ELSE #GP(selector);
  4989.    Segment must be marked present ELSE #SS(selector);
  4990.    Load SS register with selector;
  4991.    Load SS register with descriptor;
  4992.  
  4993. IF DS, ES, FS or GS is loaded with non-null selector:
  4994.    AR byte must indicate data or readable code segment ELSE
  4995.       #GP(selector);
  4996.    IF data or nonconforming code
  4997.    THEN both the RPL and the CPL must be less than or equal to DPL in
  4998.       AR byte
  4999.    ELSE #GP(selector);
  5000.    FI;
  5001.    Segment must be marked present ELSE #NP(selector);
  5002.    Load segment register with selector;
  5003.    Load segment register with descriptor;
  5004.  
  5005. IF DS, ES, FS, or GS is loaded with a null selector:
  5006.    Load segment register with selector
  5007.    Clear valid bit in invisible portion of register
  5008.  
  5009. Flags Affected
  5010.  
  5011. None
  5012.  
  5013. Protected Mode Exceptions
  5014.  
  5015. #GP, #SS, and #NP if a segment register is being loaded; #SS(0) if the
  5016. current top of stack is not within the stack segment; #GP(0) if the result
  5017. is in a nonwritable segment; #GP(0) for an illegal memory operand
  5018. effective address in the CS, DS, ES, FS, or GS segments; #SS(0) for an
  5019. illegal address in the SS segment; #PF(fault-code) for a page fault
  5020.  
  5021. Real Address Mode Exceptions
  5022.  
  5023. Interrupt 13 if any part of the operand would lie outside of the effective
  5024. address space from 0 to 0FFFFH
  5025.  
  5026. Virtual 8086 Mode Exceptions
  5027.  
  5028. Same exceptions as in real-address mode; #PF(fault-code) for a page
  5029. fault
  5030.  
  5031.  
  5032. POPA/POPAD ── Pop all General Registers
  5033.  
  5034. Opcode   Instruction   Clocks   Description
  5035.  
  5036. 61       POPA          24       Pop DI, SI, BP, SP, BX, DX, CX, and AX
  5037. 61       POPAD         24       Pop EDI, ESI, EBP, ESP, EDX, ECX, and EAX
  5038.  
  5039.  
  5040. Operation
  5041.  
  5042. IF OperandSize = 16 (* instruction = POPA *)
  5043. THEN
  5044.    DI  Pop();
  5045.    SI  Pop();
  5046.    BP  Pop();
  5047.    throwaway  Pop (); (* Skip SP *)
  5048.    BX  Pop();
  5049.    DX  Pop();
  5050.    CX  Pop();
  5051.    AX  Pop();
  5052. ELSE (* OperandSize = 32, instruction = POPAD *)
  5053.    EDI  Pop();
  5054.    ESI  Pop();
  5055.    EBP  Pop();
  5056.    throwaway  Pop (); (* Skip ESP *)
  5057.    EBX  Pop();
  5058.    EDX  Pop();
  5059.    ECX  Pop();
  5060.    EAX  Pop();
  5061. FI;
  5062.  
  5063. Description
  5064.  
  5065. POPA pops the eight 16-bit general registers. However, the SP value is
  5066. discarded instead of loaded into SP. POPA reverses a previous PUSHA,
  5067. restoring the general registers to their values before PUSHA was
  5068. executed. The first register popped is DI.
  5069.  
  5070. POPAD pops the eight 32-bit general registers. The ESP value is
  5071. discarded instead of loaded into ESP. POPAD reverses the previous
  5072. PUSHAD, restoring the general registers to their values before PUSHAD
  5073. was executed. The first register popped is EDI.
  5074.  
  5075. Flags Affected
  5076.  
  5077. None
  5078.  
  5079. Protected Mode Exceptions
  5080.  
  5081. #SS(0) if the starting or ending stack address is not within the stack
  5082. segment; #PF(fault-code) for a page fault
  5083.  
  5084. Real Address Mode Exceptions
  5085.  
  5086. Interrupt 13 if any part of the operand would lie outside of the effective
  5087. address space from 0 to 0FFFFH
  5088.  
  5089. Virtual 8086 Mode Exceptions
  5090.  
  5091. Same exceptions as in real-address mode; #PF(fault-code) for a page
  5092. fault
  5093.  
  5094.  
  5095. POPF/POPFD ── Pop Stack into FLAGS or EFLAGS Register
  5096.  
  5097. Opcode   Instruction   Clocks   Description
  5098.  
  5099. 9D       POPF          5        Pop top of stack FLAGS
  5100. 9D       POPFD         5        Pop top of stack into EFLAGS
  5101.  
  5102.  
  5103. Operation
  5104.  
  5105. Flags  Pop();
  5106.  
  5107. Description
  5108.  
  5109. POPF/POPFD pops the word or doubleword on the top of the stack and
  5110. stores the value in the flags register. If the operand-size attribute of
  5111. the instruction is 16 bits, then a word is popped and the value is stored in
  5112. FLAGS. If the operand-size attribute is 32 bits, then a doubleword is popped
  5113. and the value is stored in EFLAGS.
  5114.  
  5115. Refer to Chapter 2 and Chapter 4 for information about the FLAGS
  5116. and EFLAGS registers. Note that bits 16 and 17 of EFLAGS, called
  5117. VM and RF, respectively, are not affected by POPF or POPFD.
  5118.  
  5119. The I/O privilege level is altered only when executing at privilege level
  5120. 0. The interrupt flag is altered only when executing at a level at least as
  5121. privileged as the I/O privilege level. (Real-address mode is equivalent to
  5122. privilege level 0.) If a POPF instruction is executed with insufficient
  5123. privilege, an exception does not occur, but the privileged bits do not
  5124. change.
  5125.  
  5126. Flags Affected
  5127.  
  5128. All flags except VM and RF
  5129.  
  5130. Protected Mode Exceptions
  5131.  
  5132. #SS(0) if the top of stack is not within the stack segment
  5133.  
  5134. Real Address Mode Exceptions
  5135.  
  5136. Interrupt 13 if any part of the operand would lie outside of the effective
  5137. address space from 0 to 0FFFFH
  5138.  
  5139. Virtual 8086 Mode Exceptions
  5140.  
  5141. #GP(0) fault if IOPL is less than 3, to permit emulation
  5142.  
  5143.  
  5144. PUSH ── Push Operand onto the Stack
  5145.  
  5146. Opcode     Instruction   Clocks   Description
  5147.  
  5148. FF   /6    PUSH m16      5        Push memory word
  5149. FF   /6    PUSH m32      5        Push memory dword
  5150. 50 + /r    PUSH r16      2        Push register word
  5151. 50 + /r    PUSH r32      2        Push register dword
  5152. 6A         PUSH imm8     2        Push immediate byte
  5153. 68         PUSH imm16    2        Push immediate word
  5154. 68         PUSH imm32    2        Push immediate dword
  5155. 0E         PUSH CS       2        Push CS
  5156. 16         PUSH SS       2        Push SS
  5157. 1E         PUSH DS       2        Push DS
  5158. 06         PUSH ES       2        Push ES
  5159. 0F   A0    PUSH FS       2        Push FS
  5160. OF   A8    PUSH GS       2        Push GS
  5161.  
  5162.  
  5163. Operation
  5164.  
  5165. IF StackAddrSize = 16
  5166. THEN
  5167.    IF OperandSize = 16 THEN
  5168.       SP  SP - 2;
  5169.       (SS:SP)  (SOURCE); (* word assignment *)
  5170.    ELSE
  5171.       SP  SP - 4;
  5172.       (SS:SP)  (SOURCE); (* dword assignment *)
  5173.    FI;
  5174. ELSE (* StackAddrSize = 32 *)
  5175.    IF OperandSize = 16
  5176.    THEN
  5177.       ESP  ESP - 2;
  5178.       (SS:ESP)  (SOURCE); (* word assignment *)
  5179.    ELSE
  5180.       ESP  ESP - 4;
  5181.       (SS:ESP)  (SOURCE); (* dword assignment *)
  5182.    FI;
  5183. FI;
  5184.  
  5185. Description
  5186.  
  5187. PUSH decrements the stack pointer by 2 if the operand-size attribute of
  5188. the instruction is 16 bits; otherwise, it decrements the stack pointer by
  5189. 4. PUSH then places the operand on the new top of stack, which is
  5190. pointed to by the stack pointer.
  5191.  
  5192. The 80386 PUSH eSP instruction pushes the value of eSP as it existed
  5193. before the instruction. This differs from the 8086, where PUSH SP
  5194. pushes the new value (decremented by 2).
  5195.  
  5196. Flags Affected
  5197.  
  5198. None
  5199.  
  5200. Protected Mode Exceptions
  5201.  
  5202. #SS(0) if the new value of SP or ESP is outside the stack segment limit;
  5203. #GP(0) for an illegal memory operand effective address in the CS, DS,
  5204. ES, FS, or GS segments; #SS(0) for an illegal address in the SS segment;
  5205. #PF(fault-code) for a page fault
  5206.  
  5207. Real Address Mode Exceptions
  5208.  
  5209. None; if SP or ESP is 1, the 80386 shuts down due to a lack of stack
  5210. space
  5211.  
  5212. Virtual 8086 Mode Exceptions
  5213.  
  5214. Same exceptions as in real-address mode; #PF(fault-code) for a page
  5215. fault
  5216.  
  5217.  
  5218. PUSHA/PUSHAD ── Push all General Registers
  5219.  
  5220. Opcode  Instruction  Clocks   Description
  5221.  
  5222. 60      PUSHA        18       Push AX, CX, DX, BX, original SP, BP, SI, and
  5223.                               DI
  5224. 60      PUSHAD       18       Push EAX, ECX, EDX, EBX, original ESP, EBP,
  5225.                               ESI, and EDI
  5226.  
  5227.  
  5228. Operation
  5229.  
  5230. IF OperandSize = 16 (* PUSHA instruction *)
  5231. THEN
  5232.    Temp  (SP);
  5233.    Push(AX);
  5234.    Push(CX);
  5235.    Push(DX);
  5236.    Push(BX);
  5237.    Push(Temp);
  5238.    Push(BP);
  5239.    Push(SI);
  5240.    Push(DI);
  5241. ELSE (* OperandSize = 32, PUSHAD instruction *)
  5242.    Temp  (ESP);
  5243.    Push(EAX);
  5244.    Push(ECX);
  5245.    Push(EDX);
  5246.    Push(EBX);
  5247.    Push(Temp);
  5248.    Push(EBP);
  5249.    Push(ESI);
  5250.    Push(EDI);
  5251. FI;
  5252.  
  5253. Description
  5254.  
  5255. PUSHA and PUSHAD save the 16-bit or 32-bit general registers,
  5256. respectively, on the 80386 stack. PUSHA decrements the stack pointer
  5257. (SP) by 16 to hold the eight word values. PUSHAD decrements the
  5258. stack pointer (ESP) by 32 to hold the eight doubleword values. Because
  5259. the registers are pushed onto the stack in the order in which they were
  5260. given, they appear in the 16 or 32 new stack bytes in reverse order. The
  5261. last register pushed is DI or EDI.
  5262.  
  5263. Flags Affected
  5264.  
  5265. None
  5266.  
  5267. Protected Mode Exceptions
  5268.  
  5269. #SS(0) if the starting or ending stack address is outside the stack segment
  5270. limit; #PF(fault-code) for a page fault
  5271.  
  5272. Real Address Mode Exceptions
  5273.  
  5274. Before executing PUSHA or PUSHAD, the 80386 shuts down if SP or
  5275. ESP equals 1, 3, or 5; if SP or ESP equals 7, 9, 11, 13, or 15, exception
  5276. 13 occurs
  5277.  
  5278. Virtual 8086 Mode Exceptions
  5279.  
  5280. Same exceptions as in real-address mode; #PF(fault-code) for a page
  5281. fault
  5282.  
  5283.  
  5284. PUSHF/PUSHFD ── Push Flags Register onto the Stack
  5285.  
  5286. Opcode  Instruction  Clocks   Description
  5287.  
  5288. 9C      PUSHF        4        Push FLAGS
  5289. 9C      PUSHFD       4        Push EFLAGS
  5290.  
  5291.  
  5292. Operation
  5293.  
  5294. IF OperandSize = 32
  5295. THEN push(EFLAGS);
  5296. ELSE push(FLAGS);
  5297. FI;
  5298.  
  5299. Description
  5300.  
  5301. PUSHF decrements the stack pointer by 2 and copies the FLAGS
  5302. register to the new top of stack; PUSHFD decrements the stack pointer by
  5303. 4, and the 80386 EFLAGS register is copied to the new top of stack
  5304. which is pointed to by SS:eSP. Refer to Chapter 2 and Chapter 4 for
  5305. information on the EFLAGS register.
  5306.  
  5307. Flags Affected
  5308.  
  5309. None
  5310.  
  5311. Protected Mode Exceptions
  5312.  
  5313. #SS(0) if the new value of eSP is outside the stack segment boundaries
  5314.  
  5315. Real Address Mode Exceptions
  5316.  
  5317. None; the 80386 shuts down due to a lack of stack space
  5318.  
  5319. Virtual 8086 Mode Exceptions
  5320.  
  5321. #GP(0) fault if IOPL is less than 3, to permit emulation
  5322.  
  5323.  
  5324. RCL/RCR/ROL/ROR ── Rotate
  5325.  
  5326.  
  5327. Opcode       Instruction       Clocks  Description
  5328.  
  5329. D0  /2       RCL r/m8,1        9/10    Rotate 9 bits (CF,r/m byte) left
  5330.                                        once
  5331. D2  /2       RCL r/m8,CL       9/10    Rotate 9 bits (CF,r/m byte) left CL
  5332.                                        times
  5333. C0  /2 ib    RCL r/m8,imm8     9/10    Rotate 9 bits (CF,r/m byte) left
  5334.                                        imm8 times
  5335. D1  /2       RCL r/m16,1       9/10    Rotate 17 bits (CF,r/m word) left
  5336.                                        once
  5337. D3  /2       RCL r/m16,CL      9/10    Rotate 17 bits (CF,r/m word) left
  5338.                                        CL times
  5339. C1  /2 ib    RCL r/m16,imm8    9/10    Rotate 17 bits (CF,r/m word) left
  5340.                                        imm8 times
  5341. D1  /2       RCL r/m32,1       9/10    Rotate 33 bits (CF,r/m dword) left
  5342.                                        once
  5343. D3  /2       RCL r/m32,CL      9/10    Rotate 33 bits (CF,r/m dword) left
  5344.                                        CL times
  5345. C1  /2 ib    RCL r/m32,imm8    9/10    Rotate 33 bits (CF,r/m dword) left
  5346.                                        imm8 times
  5347. D0  /3       RCR r/m8,1        9/10    Rotate 9 bits (CF,r/m byte) right
  5348.                                        once
  5349. D2  /3       RCR r/m8,CL       9/10    Rotate 9 bits (CF,r/m byte) right
  5350.                                        CL times
  5351. C0  /3 ib    RCR r/m8,imm8     9/10    Rotate 9 bits (CF,r/m byte) right
  5352.                                        imm8 times
  5353. D1  /3       RCR r/m16,1       9/10    Rotate 17 bits (CF,r/m word) right
  5354.                                        once
  5355. D3  /3       RCR r/m16,CL      9/10    Rotate 17 bits (CF,r/m word) right
  5356.                                        CL times
  5357. C1  /3 ib    RCR r/m16,imm8    9/10    Rotate 17 bits (CF,r/m word) right
  5358.                                        imm8 times
  5359. D1  /3       RCR r/m32,1       9/10    Rotate 33 bits (CF,r/m dword) right
  5360.                                        once
  5361. D3  /3       RCR r/m32,CL      9/10    Rotate 33 bits (CF,r/m dword) right
  5362.                                        CL times
  5363. C1  /3 ib    RCR r/m32,imm8    9/10    Rotate 33 bits (CF,r/m dword) right
  5364.                                        imm8 times
  5365. D0  /0       ROL r/m8,1        3/7     Rotate 8 bits r/m byte left once
  5366. D2  /0       ROL r/m8,CL       3/7     Rotate 8 bits r/m byte left CL
  5367.                                        times
  5368. C0  /0 ib    ROL r/m8,imm8     3/7     Rotate 8 bits r/m byte left imm8
  5369.                                        times
  5370. D1  /0       ROL r/m16,1       3/7     Rotate 16 bits r/m word left once
  5371. D3  /0       ROL r/m16,CL      3/7     Rotate 16 bits r/m word left CL
  5372.                                        times
  5373. C1  /0 ib    ROL r/m16,imm8    3/7     Rotate 16 bits r/m word left imm8
  5374.                                        times
  5375. D1  /0       ROL r/m32,1       3/7     Rotate 32 bits r/m dword left once
  5376. D3  /0       ROL r/m32,CL      3/7     Rotate 32 bits r/m dword left CL
  5377.                                        times
  5378. C1  /0 ib    ROL r/m32,imm8    3/7     Rotate 32 bits r/m dword left imm8
  5379.                                        times
  5380. D0  /1       ROR r/m8,1        3/7     Rotate 8 bits r/m byte right once
  5381. D2  /1       ROR r/m8,CL       3/7     Rotate 8 bits r/m byte right CL
  5382.                                        times
  5383. C0  /1 ib    ROR r/m8,imm8     3/7     Rotate 8 bits r/m word right imm8
  5384.                                        times
  5385. D1  /1       ROR r/m16,1       3/7     Rotate 16 bits r/m word right once
  5386. D3  /1       ROR r/m16,CL      3/7     Rotate 16 bits r/m word right CL
  5387.                                        times
  5388. C1  /1 ib    ROR r/m16,imm8    3/7     Rotate 16 bits r/m word right imm8
  5389.                                        times
  5390. D1  /1       ROR r/m32,1       3/7     Rotate 32 bits r/m dword right once
  5391. D3  /1       ROR r/m32,CL      3/7     Rotate 32 bits r/m dword right CL
  5392.                                        times
  5393. C1  /1 ib    ROR r/m32,imm8    3/7     Rotate 32 bits r/m dword right imm8
  5394.                                        times
  5395.  
  5396.  
  5397. Operation
  5398.  
  5399. (* ROL - Rotate Left *)
  5400. temp  COUNT;
  5401. WHILE (temp <> 0)
  5402. DO
  5403.    tmpcf  high-order bit of (r/m);
  5404.    r/m  r/m * 2 + (tmpcf);
  5405.    temp  temp - 1;
  5406. OD;
  5407. IF COUNT = 1
  5408. THEN
  5409.    IF high-order bit of r/m <> CF
  5410.    THEN OF  1;
  5411.    ELSE OF  0;
  5412.    FI;
  5413. ELSE OF  undefined;
  5414. FI;
  5415. (* ROR - Rotate Right *)
  5416. temp  COUNT;
  5417. WHILE (temp <> 0 )
  5418. DO
  5419.    tmpcf  low-order bit of (r/m);
  5420.    r/m  r/m / 2 + (tmpcf * 2^(width(r/m)));
  5421.    temp  temp - 1;
  5422. DO;
  5423. IF COUNT = 1
  5424. THEN
  5425.    IF (high-order bit of r/m) <> (bit next to high-order bit of r/m)
  5426.    THEN OF  1;
  5427.    ELSE OF  0;
  5428.    FI;
  5429. ELSE OF  undefined;
  5430. FI;
  5431.  
  5432. Description
  5433.  
  5434. Each rotate instruction shifts the bits of the register or memory operand
  5435. given. The left rotate instructions shift all the bits upward, except for
  5436. the top bit, which is returned to the bottom. The right rotate instructions
  5437. do the reverse: the bits shift downward until the bottom bit arrives at
  5438. the top.
  5439.  
  5440. For the RCL and RCR instructions, the carry flag is part of the rotated
  5441. quantity. RCL shifts the carry flag into the bottom bit and shifts the top
  5442. bit into the carry flag; RCR shifts the carry flag into the top bit and
  5443. shifts the bottom bit into the carry flag. For the ROL and ROR
  5444. instructions, the original value of the carry flag is not a part of the
  5445. result, but the carry flag receives a copy of the bit that was shifted from
  5446. one end to the other.
  5447.  
  5448. The rotate is repeated the number of times indicated by the second
  5449. operand, which is either an immediate number or the contents of the CL
  5450. register. To reduce the maximum instruction execution time, the 80386
  5451. does not allow rotation counts greater than 31. If a rotation count greater
  5452. than 31 is attempted, only the bottom five bits of the rotation are used.
  5453. The 8086 does not mask rotation counts. The 80386 in Virtual 8086 Mode does
  5454. mask rotation counts.
  5455.  
  5456. The overflow flag is defined only for the single-rotate forms of the
  5457. instructions (second operand = 1). It is undefined in all other cases. For
  5458. left shifts/rotates, the CF bit after the shift is XORed with the
  5459. high-order result bit. For right shifts/rotates, the high-order two bits of
  5460. the result are XORed to get OF.
  5461.  
  5462. Flags Affected
  5463.  
  5464. OF only for single rotates; OF is undefined for multi-bit rotates; CF as
  5465. described above
  5466.  
  5467. Protected Mode Exceptions
  5468.  
  5469. #GP(0) if the result is in a nonwritable segment; #GP(0) for an illegal
  5470. memory operand effective address in the CS, DS, ES, FS, or GS
  5471. segments; #SS(0) for an illegal address in the SS segment; #PF(fault-code)
  5472. for a page fault
  5473.  
  5474. Real Address Mode Exceptions
  5475.  
  5476. Interrupt 13 if any part of the operand would lie outside of the effective
  5477. address space from 0 to 0FFFFH
  5478.  
  5479. Virtual 8086 Mode Exceptions
  5480.  
  5481. Same exceptions as in Real Address Mode; #PF(fault-code) for a page
  5482. fault
  5483.  
  5484.  
  5485. REP/REPE/REPZ/REPNE/REPNZ ── Repeat Following String Operation
  5486.  
  5487.  
  5488. Opcode    Instruction         Clocks           Description
  5489.  
  5490. F3  6C    REP INS r/m8, DX    13+6*(E)CX,
  5491.                               pm=7+6*(E)CX
  5492. If CPL ≤ IOPL/
  5493.                               27+6*(E)CX
  5494. If CPL > IOPL or if in virtual 8086 mode      Input (E)CX bytes from port
  5495.                                                DX into ES:[(E)DI]
  5496. F3  6D    REP INS r/m16,DX    13+6*(E)CX,
  5497.                               pm=7+6*(E)CX
  5498. If CPL ≤ IOPL/
  5499.                               27+6*(E)CX
  5500. If CPL > IOPL or if in virtual 8086 mode      Input (E)CX words from port
  5501.                                                DX into ES:[(E)DI]
  5502. F3  6D    REP INS r/m32,DX    13+6*(E)CX,
  5503.                               pm=7+6*(E)CX
  5504. If CPL ≤ IOPL/
  5505.                               27+6*(E)CX
  5506. If CPL > IOPL or if in virtual 8086 mode      Input (E)CX dwords from port
  5507.                                                DX into ES:[(E)DI]
  5508. F3  A4    REP MOVS m8,m8      5+4*(E)CX        Move (E)CX bytes from
  5509.                                                [(E)SI] to ES:[(E)DI]
  5510. F3  A5    REP MOVS m16,m16    5+4*(E)CX        Move (E)CX words from
  5511.                                                [(E)SI] to ES:[(E)DI]
  5512. F3  A5    REP MOVS m32,m32    5+4*(E)CX        Move (E)CX dwords from
  5513.                                                [(E)SI] to ES:[(E)DI]
  5514. F3  6E    REP OUTS DX,r/m8    5+12*(E)CX,
  5515.                               pm=6+5*(E)CX
  5516. If CPL ≤ IOPL/
  5517.                               26+5*(E)CX
  5518. If CPL > IOPL or if in virtual 8086 mode      Output (E)CX bytes from
  5519.                                                [(E)SI] to port DX
  5520. F3  6F    REP OUTS DX,r/m16   5+12*(E)CX,
  5521.                               pm=6+5*(E)CX
  5522. If CPL ≤ IOPL/
  5523.                               26+5*(E)CX
  5524. If CPL > IOPL or if in virtual 8086 mode      Output (E)CX words from
  5525.                                                [(E)SI] to port DX
  5526. F3  6F    REP OUTS DX,r/m32   5+12*(E)CX,
  5527.                               pm=6+5*(E)CX
  5528. If CPL ≤ IOPL/
  5529.                               26+5*(E)CX
  5530. If CPL > IOPL or if in virtual 8086 mode      Output (E)CX dwords from
  5531.                                                [(E)SI] to port DX
  5532. F3  AA    REP STOS m8         5+5*(E)CX        Fill (E)CX bytes at
  5533.                                                ES:[(E)DI] with AL
  5534. F3  AB    REP STOS m16        5+5*(E)CX        Fill (E)CX words at
  5535.                                                ES:[(E)DI] with AX
  5536. F3  AB    REP STOS m32        5+5*(E)CX        Fill (E)CX dwords at
  5537.                                                ES:[(E)DI] with EAX
  5538. F3  A6    REPE CMPS m8,m8     5+9*N            Find nonmatching bytes in
  5539.                                                ES:[(E)DI] and [(E)SI]
  5540. F3  A7    REPE CMPS m16,m16   5+9*N            Find nonmatching words in
  5541.                                                ES:[(E)DI] and [(E)SI]
  5542. F3  A7    REPE CMPS m32,m32   5+9*N            Find nonmatching dwords in
  5543.                                                ES:[(E)DI] and [(E)SI]
  5544. F3  AE    REPE SCAS m8        5+8*N            Find non-AL byte starting
  5545.                                                at ES:[(E)DI]
  5546. F3  AF    REPE SCAS m16       5+8*N            Find non-AX word starting
  5547.                                                at ES:[(E)DI]
  5548. F3  AF    REPE SCAS m32       5+8*N            Find non-EAX dword starting
  5549.                                                at ES:[(E)DI]
  5550. F2  A6    REPNE CMPS m8,m8    5+9*N            Find matching bytes in
  5551.                                                ES:[(E)DI] and [(E)SI]
  5552. F2  A7    REPNE CMPS m16,m16  5+9*N            Find matching words in
  5553.                                                ES:[(E)DI] and [(E)SI]
  5554. F2  A7    REPNE CMPS m32,m32  5+9*N            Find matching dwords in
  5555.                                                ES:[(E)DI] and [(E)SI]
  5556. F2  AE    REPNE SCAS m8       5+8*N            Find AL, starting at
  5557.                                                ES:[(E)DI]
  5558. F2  AF    REPNE SCAS m16      5+8*N            Find AX, starting at
  5559.                                                ES:[(E)DI]
  5560. F2  AF    REPNE SCAS m32      5+8*N            Find EAX, starting at
  5561.                                                ES:[(E)DI]
  5562.  
  5563.  
  5564. Operation
  5565.  
  5566. IF AddressSize = 16
  5567. THEN use CX for CountReg;
  5568. ELSE (* AddressSize = 32 *) use ECX for CountReg;
  5569. FI;
  5570. WHILE CountReg <> 0
  5571. DO
  5572.    service pending interrupts (if any);
  5573.    perform primitive string instruction;
  5574.    CountReg  CountReg - 1;
  5575.    IF primitive operation is CMPB, CMPW, SCAB, or SCAW
  5576.    THEN
  5577.       IF (instruction is REP/REPE/REPZ) AND (ZF=1)
  5578.       THEN exit WHILE loop
  5579.       ELSE
  5580.          IF (instruction is REPNZ or REPNE) AND (ZF=0)
  5581.          THEN exit WHILE loop;
  5582.          FI;
  5583.       FI;
  5584.    FI;
  5585. OD;
  5586.  
  5587. Description
  5588.  
  5589. REP, REPE (repeat while equal), and REPNE (repeat while not equal)
  5590. are prefix that are applied to string operation. Each prefix cause the
  5591. string instruction that follows to be repeated the number of times
  5592. indicated in the count register or (for REPE and REPNE) until the
  5593. indicated condition in the zero flag is no longer met.
  5594.  
  5595. Synonymous forms of REPE and REPNE are REPZ and REPNZ,
  5596. respectively.
  5597.  
  5598. The REP prefixes apply only to one string instruction at a time. To repeat
  5599. a block of instructions, use the LOOP instruction or another looping
  5600. construct.
  5601.  
  5602. The precise action for each iteration is as follows:
  5603.  
  5604.   1.  If the address-size attribute is 16 bits, use CX for the count
  5605.       register; if the address-size attribute is 32 bits, use ECX for the
  5606.       count register.
  5607.  
  5608.   2.  Check CX. If it is zero, exit the iteration, and move to the next
  5609.       instruction.
  5610.  
  5611.   3.  Acknowledge any pending interrupts.
  5612.  
  5613.   4.  Perform the string operation once.
  5614.  
  5615.   5.  Decrement CX or ECX by one; no flags are modified.
  5616.  
  5617.   6.  Check the zero flag if the string operation is SCAS or CMPS. If
  5618.       the repeat condition does not hold, exit the iteration and move to
  5619.       the next instruction. Exit the iteration if the prefix is REPE and ZF
  5620.       is 0 (the last comparison was not equal), or if the prefix is REPNE
  5621.       and ZF is one (the last comparison was equal).
  5622.  
  5623.   7.  Return to step 1 for the next iteration.
  5624.  
  5625. Repeated CMPS and SCAS instructions can be exited if the count is
  5626. exhausted or if the zero flag fails the repeat condition. These two cases
  5627. can be distinguished by using either the JCXZ instruction, or by using
  5628. the conditional jumps that test the zero flag (JZ, JNZ, and JNE).
  5629.  
  5630. Flags Affected
  5631.  
  5632. ZF by REP CMPS and REP SCAS as described above
  5633.  
  5634. Protected Mode Exceptions
  5635.  
  5636. #UD if a repeat prefix is used before an instruction that is not in the
  5637. list above; further exceptions can be generated when the string operation is
  5638. executed; refer to the descriptions of the string instructions themselves
  5639.  
  5640. Real Address Mode Exceptions
  5641.  
  5642. Interrupt 6 if a repeat prefix is used before an instruction that is not in
  5643. the list above; further exceptions can be generated when the string
  5644. operation is executed; refer to the descriptions of the string instructions
  5645. themselves
  5646.  
  5647. Virtual 8086 Mode Exceptions
  5648.  
  5649. #UD if a repeat prefix is used before an instruction that is not in the
  5650. list above; further exceptions can be generated when the string operation is
  5651. executed; refer to the descriptions of the string instructions themselves
  5652.  
  5653. Notes
  5654.  
  5655. Not all input/output ports can handle the rate at which the REP INS
  5656. and REP OUTS instructions execute.
  5657.  
  5658.  
  5659. RET ── Return from Procedure
  5660.  
  5661. Opcode     Instruction  Clocks         Description
  5662.  
  5663. C3         RET          10+m           Return (near) to caller
  5664. CB         RET          18+m,pm=32+m   Return (far) to caller, same
  5665.                                        privilege
  5666. CB         RET          pm=68          Return (far), lesser privilege,
  5667.                                        switch stacks
  5668. C2  iw     RET imm16    10+m           Return (near), pop imm16 bytes of
  5669.                                        parameters
  5670. CA  iw     RET imm16    18+m,pm=32+m   Return (far), same privilege, pop
  5671.                                        imm16 bytes
  5672. CA  iw     RET imm16    pm=68          Return (far), lesser privilege, pop
  5673.                                        imm16 bytes
  5674.  
  5675.  
  5676. Operation
  5677.  
  5678. IF instruction = near RET
  5679. THEN;
  5680.    IF OperandSize = 16
  5681.    THEN
  5682.       IP  Pop();
  5683.       EIP  EIP AND 0000FFFFH;
  5684.    ELSE (* OperandSize = 32 *)
  5685.       EIP  Pop();
  5686.    FI;
  5687.    IF instruction has immediate operand THEN eSP  eSP + imm16; FI;
  5688. FI;
  5689.  
  5690. IF (PE = 0 OR (PE = 1 AND VM = 1))
  5691.    (* real mode or virtual 8086 mode *)
  5692.    AND instruction = far RET
  5693. THEN;
  5694.    IF OperandSize = 16
  5695.    THEN
  5696.       IP  Pop();
  5697.       EIP  EIP AND 0000FFFFH;
  5698.       CS  Pop(); (* 16-bit pop *)
  5699.    ELSE (* OperandSize = 32 *)
  5700.       EIP  Pop();
  5701.       CS  Pop(); (* 32-bit pop, high-order 16-bits discarded *)
  5702.    FI;
  5703.    IF instruction has immediate operand THEN eSP  eSP + imm16; FI;
  5704. FI;
  5705.  
  5706. IF (PE = 1 AND VM = 0) (* Protected mode, not V86 mode *)
  5707.    AND instruction = far RET
  5708. THEN
  5709.    IF OperandSize=32
  5710.    THEN Third word on stack must be within stack limits else #SS(0);
  5711.    ELSE Second word on stack must be within stack limits else #SS(0);
  5712.    FI;
  5713.    Return selector RPL must be ≥ CPL ELSE #GP(return selector)
  5714.    IF return selector RPL = CPL
  5715.    THEN GOTO SAME-LEVEL;
  5716.    ELSE GOTO OUTER-PRIVILEGE-LEVEL;
  5717.    FI;
  5718. FI;
  5719.  
  5720. SAME-LEVEL:
  5721.    Return selector must be non-null ELSE #GP(0)
  5722.    Selector index must be within its descriptor table limits ELSE
  5723.       #GP(selector)
  5724.    Descriptor AR byte must indicate code segment ELSE #GP(selector)
  5725.    IF non-conforming
  5726.    THEN code segment DPL must equal CPL;
  5727.    ELSE #GP(selector);
  5728.    FI;
  5729.    IF conforming
  5730.    THEN code segment DPL must be ≤ CPL;
  5731.    ELSE #GP(selector);
  5732.    FI;
  5733.    Code segment must be present ELSE #NP(selector);
  5734.    Top word on stack must be within stack limits ELSE #SS(0);
  5735.    IP must be in code segment limit ELSE #GP(0);
  5736.    IF OperandSize=32
  5737.    THEN
  5738.       Load CS:EIP from stack
  5739.       Load CS register with descriptor
  5740.       Increment eSP by 8 plus the immediate offset if it exists
  5741.    ELSE (* OperandSize=16 *)
  5742.       Load CS:IP from stack
  5743.       Load CS register with descriptor
  5744.       Increment eSP by 4 plus the immediate offset if it exists
  5745.    FI;
  5746.  
  5747. OUTER-PRIVILEGE-LEVEL:
  5748.    IF OperandSize=32
  5749.    THEN Top (16+immediate) bytes on stack must be within stack limits
  5750.       ELSE #SS(0);
  5751.    ELSE Top (8+immediate) bytes on stack must be within stack limits ELSE
  5752.       #SS(0);
  5753.    FI;
  5754.    Examine return CS selector and associated descriptor:
  5755.       Selector must be non-null ELSE #GP(0);
  5756.       Selector index must be within its descriptor table limits ELSE
  5757.          #GP(selector)
  5758.       Descriptor AR byte must indicate code segment ELSE #GP(selector);
  5759.       IF non-conforming
  5760.       THEN code segment DPL must equal return selector RPL
  5761.       ELSE #GP(selector);
  5762.       FI;
  5763.       IF conforming
  5764.       THEN code segment DPL must be ≤ return selector RPL;
  5765.       ELSE #GP(selector);
  5766.       FI;
  5767.       Segment must be present ELSE #NP(selector)
  5768.    Examine return SS selector and associated descriptor:
  5769.       Selector must be non-null ELSE #GP(0);
  5770.       Selector index must be within its descriptor table limits
  5771.          ELSE #GP(selector);
  5772.       Selector RPL must equal the RPL of the return CS selector ELSE
  5773.          #GP(selector);
  5774.       Descriptor AR byte must indicate a writable data segment ELSE
  5775.          #GP(selector);
  5776.       Descriptor DPL must equal the RPL of the return CS selector ELSE
  5777.          #GP(selector);
  5778.       Segment must be present ELSE #NP(selector);
  5779.    IP must be in code segment limit ELSE #GP(0);
  5780.    Set CPL to the RPL of the return CS selector;
  5781.    IF OperandMode=32
  5782.    THEN
  5783.       Load CS:EIP from stack;
  5784.       Set CS RPL to CPL;
  5785.       Increment eSP by 8 plus the immediate offset if it exists;
  5786.       Load SS:eSP from stack;
  5787.    ELSE (* OperandMode=16 *)
  5788.       Load CS:IP from stack;
  5789.       Set CS RPL to CPL;
  5790.       Increment eSP by 4 plus the immediate offset if it exists;
  5791.       Load SS:eSP from stack;
  5792.    FI;
  5793.    Load the CS register with the return CS descriptor;
  5794.    Load the SS register with the return SS descriptor;
  5795.    For each of ES, FS, GS, and DS
  5796.    DO
  5797.       IF the current register setting is not valid for the outer level,
  5798.          set the register to null (selector  AR  0);
  5799.       To be valid, the register setting must satisfy the following
  5800.          properties:
  5801.          Selector index must be within descriptor table limits;
  5802.          Descriptor AR byte must indicate data or readable code segment;
  5803.          IF segment is data or non-conforming code, THEN
  5804.             DPL must be ≥ CPL, or DPL must be ≥ RPL;
  5805.       FI;
  5806.    OD;
  5807.  
  5808. Description
  5809.  
  5810. RET transfers control to a return address located on the stack. The
  5811. address is usually placed on the stack by a CALL instruction, and the
  5812. return is made to the instruction that follows the CALL.
  5813.  
  5814. The optional numeric parameter to RET gives the number of stack bytes
  5815. (OperandMode=16) or words (OperandMode=32) to be released after the return
  5816. address is popped. These items are typically used as input parameters to the
  5817. procedure called.
  5818.  
  5819. For the intrasegment (near) return, the address on the stack is a segment
  5820. offset, which is popped into the instruction pointer. The CS register is
  5821. unchanged. For the intersegment (far) return, the address on the stack
  5822. is a long pointer. The offset is popped first, followed by the selector.
  5823.  
  5824. In real mode, CS and IP are loaded directly. In Protected Mode, an
  5825. intersegment return causes the processor to check the descriptor
  5826. addressed by the return selector. The AR byte of the descriptor must
  5827. indicate a code segment of equal or lesser privilege (or greater or equal
  5828. numeric value) than the current privilege level. Returns to a lesser
  5829. privilege level cause the stack to be reloaded from the value saved beyond
  5830. the parameter block.
  5831.  
  5832. The DS, ES, FS, and GS segment registers can be set to 0 by the RET
  5833. instruction during an interlevel transfer. If these registers refer to
  5834. segments that cannot be used by the new privilege level, they are set to
  5835. 0 to prevent unauthorized access from the new privilege level.
  5836.  
  5837. Flags Affected
  5838.  
  5839. None
  5840.  
  5841. Protected Mode Exceptions
  5842.  
  5843. #GP, #NP, or #SS, as described under "Operation" above; #PF(fault-code) for
  5844. a page fault
  5845.  
  5846. Real Address Mode Exceptions
  5847.  
  5848. Interrupt 13 if any part of the operand would be outside the effective
  5849. address space from 0 to 0FFFFH
  5850.  
  5851. Virtual 8086 Mode Exceptions
  5852.  
  5853. Same exceptions as in Real Address Mode; #PF(fault-code) for a page
  5854. fault
  5855.  
  5856.  
  5857. SAHF ── Store AH into Flags
  5858.  
  5859. Opcode  Instruction  Clocks   Description
  5860.  
  5861. 9E      SAHF         3        Store AH into flags SF ZF xx AF xx PF xx CF
  5862.  
  5863.  
  5864. Operation
  5865.  
  5866. SF:ZF:xx:AF:xx:PF:xx:CF  AH;
  5867.  
  5868. Description
  5869.  
  5870. SAHF loads the flags listed above with values from the AH register,
  5871. from bits 7, 6, 4, 2, and 0, respectively.
  5872.  
  5873. Flags Affected
  5874.  
  5875. SF, ZF, AF, PF, and CF as described above
  5876.  
  5877. Protected Mode Exceptions
  5878.  
  5879. None
  5880.  
  5881. Real Address Mode Exceptions
  5882.  
  5883. None
  5884.  
  5885. Virtual 8086 Mode Exceptions
  5886.  
  5887. None
  5888.  
  5889.  
  5890. SAL/SAR/SHL/SHR ── Shift Instructions
  5891.  
  5892.  
  5893. Opcode          Instruction       Clocks  Description
  5894.  
  5895. D0   /4         SAL r/m8,1        3/7     Multiply r/m byte by 2, once
  5896. D2   /4         SAL r/m8,CL       3/7     Multiply r/m byte by 2, CL times
  5897. C0   /4 ib      SAL r/m8,imm8     3/7     Multiply r/m byte by 2, imm8
  5898.                                           times
  5899. D1   /4         SAL r/m16,1       3/7     Multiply r/m word by 2, once
  5900. D3   /4         SAL r/m16,CL      3/7     Multiply r/m word by 2, CL times
  5901. C1   /4 ib      SAL r/m16,imm8    3/7     Multiply r/m word by 2, imm8
  5902.                                           times
  5903. D1   /4         SAL r/m32,1       3/7     Multiply r/m dword by 2, once
  5904. D3   /4         SAL r/m32,CL      3/7     Multiply r/m dword by 2, CL
  5905.                                           times
  5906. C1   /4 ib      SAL r/m32,imm8    3/7     Multiply r/m dword by 2, imm8
  5907.                                           times
  5908. D0   /7         SAR r/m8,1        3/7     Signed divide^(1) r/m byte by 2,
  5909.                                           once
  5910. D2   /7         SAR r/m8,CL       3/7     Signed divide^(1) r/m byte by 2,
  5911.                                           CL times
  5912. C0   /7 ib      SAR r/m8,imm8     3/7     Signed divide^(1) r/m byte by 2,
  5913.                                           imm8 times
  5914. D1   /7         SAR r/m16,1       3/7     Signed divide^(1) r/m word by 2,
  5915.                                           once
  5916. D3   /7         SAR r/m16,CL      3/7     Signed divide^(1) r/m word by 2,
  5917.                                           CL times
  5918. C1   /7 ib      SAR r/m16,imm8    3/7     Signed divide^(1) r/m word by 2,
  5919.                                           imm8 times
  5920. D1   /7         SAR r/m32,1       3/7     Signed divide^(1) r/m dword by 2,
  5921.                                           once
  5922. D3   /7         SAR r/m32,CL      3/7     Signed divide^(1) r/m dword by 2,
  5923.                                           CL times
  5924. C1   /7 ib      SAR r/m32,imm8    3/7     Signed divide^(1) r/m dword by 2,
  5925.                                           imm8 times
  5926. D0   /4         SHL r/m8,1        3/7     Multiply r/m byte by 2, once
  5927. D2   /4         SHL r/m8,CL       3/7     Multiply r/m byte by 2, CL times
  5928. C0   /4 ib      SHL r/m8,imm8     3/7     Multiply r/m byte by 2, imm8
  5929.                                           times
  5930. D1   /4         SHL r/m16,1       3/7     Multiply r/m word by 2, once
  5931. D3   /4         SHL r/m16,CL      3/7     Multiply r/m word by 2, CL times
  5932. C1   /4 ib      SHL r/m16,imm8    3/7     Multiply r/m word by 2, imm8
  5933.                                           times
  5934. D1   /4         SHL r/m32,1       3/7     Multiply r/m dword by 2, once
  5935. D3   /4         SHL r/m32,CL      3/7     Multiply r/m dword by 2, CL
  5936.                                           times
  5937. C1   /4 ib      SHL r/m32,imm8    3/7     Multiply r/m dword by 2, imm8
  5938.                                           times
  5939. D0   /5         SHR r/m8,1        3/7     Unsigned divide r/m byte by 2,
  5940.                                           once
  5941. D2   /5         SHR r/m8,CL       3/7     Unsigned divide r/m byte by 2,
  5942.                                           CL times
  5943. C0   /5 ib      SHR r/m8,imm8     3/7     Unsigned divide r/m byte by 2,
  5944.                                           imm8 times
  5945. D1   /5         SHR r/m16,1       3/7     Unsigned divide r/m word by 2,
  5946.                                           once
  5947. D3   /5         SHR r/m16,CL      3/7     Unsigned divide r/m word by 2,
  5948.                                           CL times
  5949. C1   /5 ib      SHR r/m16,imm8    3/7     Unsigned divide r/m word by 2,
  5950.                                           imm8 times
  5951. D1   /5         SHR r/m32,1       3/7     Unsigned divide r/m dword by 2,
  5952.                                           once
  5953. D3   /5         SHR r/m32,CL      3/7     Unsigned divide r/m dword by 2,
  5954.                                           CL times
  5955. C1   /5 ib      SHR r/m32,imm8    3/7     Unsigned divide r/m dword by 2,
  5956.                                           imm8 times
  5957.  
  5958.  
  5959. Not the same division as IDIV; rounding is toward negative infinity.
  5960.  
  5961. Operation
  5962.  
  5963. (* COUNT is the second parameter *)
  5964. (temp)  COUNT;
  5965. WHILE (temp <> 0)
  5966. DO
  5967.    IF instruction is SAL or SHL
  5968.    THEN CF  high-order bit of r/m;
  5969.    FI;
  5970.    IF instruction is SAR or SHR
  5971.    THEN CF  low-order bit of r/m;
  5972.    FI;
  5973.    IF instruction = SAL or SHL
  5974.    THEN r/m  r/m * 2;
  5975.    FI;
  5976.    IF instruction = SAR
  5977.    THEN r/m  r/m /2 (*Signed divide, rounding toward negative infinity*);
  5978.    FI;
  5979.    IF instruction = SHR
  5980.    THEN r/m  r/m / 2; (* Unsigned divide *);
  5981.    FI;
  5982.    temp  temp - 1;
  5983. OD;
  5984. (* Determine overflow for the various instructions *)
  5985. IF COUNT = 1
  5986. THEN
  5987.    IF instruction is SAL or SHL
  5988.    THEN OF  high-order bit of r/m <> (CF);
  5989.    FI;
  5990.    IF instruction is SAR
  5991.    THEN OF  0;
  5992.    FI;
  5993.    IF instruction is SHR
  5994.    THEN OF  high-order bit of operand;
  5995.    FI;
  5996. ELSE OF  undefined;
  5997. FI;
  5998.  
  5999. Description
  6000.  
  6001. SAL (or its synonym, SHL) shifts the bits of the operand upward. The
  6002. high-order bit is shifted into the carry flag, and the low-order bit is set
  6003. to 0.
  6004.  
  6005. SAR and SHR shift the bits of the operand downward. The low-order
  6006. bit is shifted into the carry flag. The effect is to divide the operand by
  6007. 2. SAR performs a signed divide with rounding toward negative infinity (not
  6008. the same as IDIV); the high-order bit remains the same. SHR performs an
  6009. unsigned divide; the high-order bit is set to 0.
  6010.  
  6011. The shift is repeated the number of times indicated by the second
  6012. operand, which is either an immediate number or the contents of the CL
  6013. register. To reduce the maximum execution time, the 80386 does not
  6014. allow shift counts greater than 31. If a shift count greater than 31 is
  6015. attempted, only the bottom five bits of the shift count are used. (The
  6016. 8086 uses all eight bits of the shift count.)
  6017.  
  6018. The overflow flag is set only if the single-shift forms of the instructions
  6019. are used. For left shifts, OF is set to 0 if the high bit of the answer is
  6020. the same as the result of the carry flag (i.e., the top two bits of the
  6021. original operand were the same); OF is set to 1 if they are different. For
  6022. SAR, OF is set to 0 for all single shifts. For SHR, OF is set to the
  6023. high-order bit of the original operand.
  6024.  
  6025. Flags Affected
  6026.  
  6027. OF for single shifts; OF is undefined for multiple shifts; CF, ZF, PF,
  6028. and SF as described in Appendix C
  6029.  
  6030. Protected Mode Exceptions
  6031.  
  6032. #GP(0) if the result is in a nonwritable segment; #GP(0) for an illegal
  6033. memory operand effective address in the CS, DS, ES, FS, or GS
  6034. segments; #SS(0) for an illegal address in the SS segment; #PF(fault-code)
  6035. for a page fault
  6036.  
  6037. Real Address Mode Exceptions
  6038.  
  6039. Interrupt 13 if any part of the operand would lie outside of the effective
  6040. address space from 0 to 0FFFFH
  6041.  
  6042. Virtual 8086 Mode Exceptions
  6043.  
  6044. Same exceptions as in Real Address Mode; #PF(fault-code) for a page
  6045. fault
  6046.  
  6047.  
  6048. SBB ── Integer Subtraction with Borrow
  6049.  
  6050.  
  6051. Opcode       Instruction       Clocks  Description
  6052.  
  6053. 1C  ib       SBB AL,imm8       2       Subtract with borrow immediate byte
  6054.                                        from AL
  6055. 1D  iw       SBB AX,imm16      2       Subtract with borrow immediate word
  6056.                                        from AX
  6057. 1D  id       SBB EAX,imm32     2       Subtract with borrow immediate
  6058.                                        dword from EAX
  6059. 80  /3 ib    SBB r/m8,imm8     2/7     Subtract with borrow immediate byte
  6060.                                        from r/m byte
  6061. 81  /3 iw    SBB r/m16,imm16   2/7     Subtract with borrow immediate word
  6062.                                        from r/m word
  6063. 81  /3 id    SBB r/m32,imm32   2/7     Subtract with borrow immediate
  6064.                                        dword from r/m dword
  6065. 83  /3 ib    SBB r/m16,imm8    2/7     Subtract with borrow sign-extended
  6066.                                        immediate byte from r/m word
  6067. 83  /3 ib    SBB r/m32,imm8    2/7     Subtract with borrow sign-extended
  6068.                                        immediate byte from r/m dword
  6069. 18  /r       SBB r/m8,r8       2/6     Subtract with borrow byte register
  6070.                                        from r/m byte
  6071. 19  /r       SBB r/m16,r16     2/6     Subtract with borrow word register
  6072.                                        from r/m word
  6073. 19  /r       SBB r/m32,r32     2/6     Subtract with borrow dword register
  6074.                                        from r/m dword
  6075. 1A  /r       SBB r8,r/m8       2/7     Subtract with borrow byte register
  6076.                                        from r/m byte
  6077. 1B  /r       SBB r16,r/m16     2/7     Subtract with borrow word register
  6078.                                        from r/m word
  6079. 1B  /r       SBB r32,r/m32     2/7     Subtract with borrow dword register
  6080.                                        from r/m dword
  6081.  
  6082.  
  6083. Operation
  6084.  
  6085. IF SRC is a byte and DEST is a word or dword
  6086. THEN DEST = DEST - (SignExtend(SRC) + CF)
  6087. ELSE DEST  DEST - (SRC + CF);
  6088.  
  6089. Description
  6090.  
  6091. SBB adds the second operand (DEST) to the carry flag (CF) and
  6092. subtracts the result from the first operand (SRC). The result of the
  6093. subtraction is assigned to the first operand (DEST), and the flags are
  6094. set accordingly.
  6095.  
  6096. When an immediate byte value is subtracted from a word operand, the
  6097. immediate value is first sign-extended.
  6098.  
  6099. Flags Affected
  6100.  
  6101. OF, SF, ZF, AF, PF, and CF as described in Appendix C
  6102.  
  6103. Protected Mode Exceptions
  6104.  
  6105. #GP(0) if the result is in a nonwritable segment; #GP(0) for an illegal
  6106. memory operand effective address in the CS, DS, ES, FS, or GS
  6107. segments; #SS(0) for an illegal address in the SS segment; #PF(fault-code)
  6108. for a page fault
  6109.  
  6110. Real Address Mode Exceptions
  6111.  
  6112. Interrupt 13 if any part of the operand would lie outside of the effective
  6113. address space from 0 to 0FFFFH
  6114.  
  6115. Virtual 8086 Mode Exceptions
  6116.  
  6117. Same exceptions as in Real Address Mode; #PF(fault-code) for a page
  6118. fault
  6119.  
  6120.  
  6121. SCAS/SCASB/SCASW/SCASD ── Compare String Data
  6122.  
  6123. Opcode  Instruction  Clocks  Description
  6124.  
  6125. AE      SCAS m8      7       Compare bytes AL-ES:[DI], update (E)DI
  6126. AF      SCAS m16     7       Compare words AX-ES:[DI], update (E)DI
  6127. AF      SCAS m32     7       Compare dwords EAX-ES:[DI], update (E)DI
  6128. AE      SCASB        7       Compare bytes AL-ES:[DI], update (E)DI
  6129. AF      SCASW        7       Compare words AX-ES:[DI], update (E)DI
  6130. AF      SCASD        7       Compare dwords EAX-ES:[DI], update (E)DI
  6131.  
  6132.  
  6133. Operation
  6134.  
  6135. IF AddressSize = 16
  6136. THEN use DI for dest-index;
  6137. ELSE (* AddressSize = 32 *) use EDI for dest-index;
  6138. FI;
  6139. IF byte type of instruction
  6140. THEN
  6141.    AL - [dest-index]; (* Compare byte in AL and dest *)
  6142.    IF DF = 0 THEN IndDec  1 ELSE IncDec  -1; FI;
  6143. ELSE
  6144.    IF OperandSize = 16
  6145.    THEN
  6146.       AX - [dest-index]; (* compare word in AL and dest *)
  6147.       IF DF = 0 THEN IncDec  2 ELSE IncDec  -2; FI;
  6148.    ELSE (* OperandSize = 32 *)
  6149.       EAX - [dest-index];(* compare dword in EAX & dest *)
  6150.       IF DF = 0 THEN IncDec  4 ELSE IncDec  -4; FI;
  6151.    FI;
  6152. FI;
  6153. dest-index = dest-index + IncDec
  6154.  
  6155. Description
  6156.  
  6157. SCAS subtracts the memory byte or word at the destination register from
  6158. the AL, AX or EAX register. The result is discarded; only the flags are set.
  6159. The operand must be addressable from the ES segment; no segment override is
  6160. possible.
  6161.  
  6162. If the address-size attribute for this instruction is 16 bits, DI is used
  6163. as the destination register; otherwise, the address-size attribute is 32
  6164. bits and EDI is used.
  6165.  
  6166. The address of the memory data being compared is determined solely by the
  6167. contents of the destination register, not by the operand to SCAS. The
  6168. operand validates ES segment addressability and determines the data type.
  6169. Load the correct index value into DI or EDI before executing SCAS.
  6170.  
  6171. After the comparison is made, the destination register is automatically
  6172. updated. If the direction flag is 0 (CLD was executed), the destination
  6173. register is incremented; if the direction flag is 1 (STD was executed), it
  6174. is decremented. The increments or decrements are by 1 if bytes are compared,
  6175. by 2 if words are compared, or by 4 if doublewords are compared.
  6176.  
  6177. SCASB, SCASW, and SCASD are synonyms for the byte, word and
  6178. doubleword SCAS instructions that don't require operands. They are
  6179. simpler to code, but provide no type or segment checking.
  6180.  
  6181. SCAS can be preceded by the REPE or REPNE prefix for a block search
  6182. of CX or ECX bytes or words. Refer to the REP instruction for further
  6183. details.
  6184.  
  6185. Flags Affected
  6186.  
  6187. OF, SF, ZF, AF, PF, and CF as described in Appendix C
  6188.  
  6189. Protected Mode Exceptions
  6190.  
  6191. #GP(0) for an illegal memory operand effective address in the CS, DS,
  6192. ES, FS, or GS segments; #SS(0) for an illegal address in the SS segment;
  6193. #PF(fault-code) for a page fault
  6194.  
  6195. Real Address Mode Exceptions
  6196.  
  6197. Interrupt 13 if any part of the operand would lie outside of the effective
  6198. address space from 0 to 0FFFFH
  6199.  
  6200. Virtual 8086 Mode Exceptions
  6201.  
  6202. Same exceptions as in Real Address Mode; #PF(fault-code) for a page
  6203. fault
  6204.  
  6205.  
  6206. SETcc ── Byte Set on Condition
  6207.  
  6208.  
  6209. Opcode   Instruction  Clocks  Description
  6210.  
  6211. 0F  97   SETA r/m8    4/5     Set byte if above (CF=0 and ZF=0)
  6212. 0F  93   SETAE r/m8   4/5     Set byte if above or equal (CF=0)
  6213. 0F  92   SETB r/m8    4/5     Set byte if below (CF=1)
  6214. 0F  96   SETBE r/m8   4/5     Set byte if below or equal (CF=1 or (ZF=1)
  6215. 0F  92   SETC r/m8    4/5     Set if carry (CF=1)
  6216. 0F  94   SETE r/m8    4/5     Set byte if equal (ZF=1)
  6217. 0F  9F   SETG r/m8    4/5     Set byte if greater (ZF=0 or SF=OF)
  6218. 0F  9D   SETGE r/m8   4/5     Set byte if greater or equal (SF=OF)
  6219. 0F  9C   SETL r/m8    4/5     Set byte if less (SF<>OF)
  6220. 0F  9E   SETLE r/m8   4/5     Set byte if less or equal (ZF=1 and
  6221.                               SF<>OF)
  6222. 0F  96   SETNA r/m8   4/5     Set byte if not above (CF=1)
  6223. 0F  92   SETNAE r/m8  4/5     Set byte if not above or equal (CF=1)
  6224. 0F  93   SETNB r/m8   4/5     Set byte if not below (CF=0)
  6225. 0F  97   SETNBE r/m8  4/5     Set byte if not below or equal (CF=0 and
  6226.                               ZF=0)
  6227. 0F  93   SETNC r/m8   4/5     Set byte if not carry (CF=0)
  6228. 0F  95   SETNE r/m8   4/5     Set byte if not equal (ZF=0)
  6229. 0F  9E   SETNG r/m8   4/5     Set byte if not greater (ZF=1 or SF<>OF)
  6230. 0F  9C   SETNGE r/m8  4/5     Set if not greater or equal (SF<>OF)
  6231. 0F  9D   SETNL r/m8   4/5     Set byte if not less (SF=OF)
  6232. 0F  9F   SETNLE r/m8  4/5     Set byte if not less or equal (ZF=1 and
  6233.                               SF<>OF)
  6234. 0F  91   SETNO r/m8   4/5     Set byte if not overflow (OF=0)
  6235. 0F  9B   SETNP r/m8   4/5     Set byte if not parity (PF=0)
  6236. 0F  99   SETNS r/m8   4/5     Set byte if not sign (SF=0)
  6237. 0F  95   SETNZ r/m8   4/5     Set byte if not zero (ZF=0)
  6238. 0F  90   SETO r/m8    4/5     Set byte if overflow (OF=1)
  6239. 0F  9A   SETP r/m8    4/5     Set byte if parity (PF=1)
  6240. 0F  9A   SETPE r/m8   4/5     Set byte if parity even (PF=1)
  6241. 0F  9B   SETPO r/m8   4/5     Set byte if parity odd (PF=0)
  6242. 0F  98   SETS r/m8    4/5     Set byte if sign (SF=1)
  6243. 0F  94   SETZ r/m8    4/5     Set byte if zero (ZF=1)
  6244.  
  6245.  
  6246. Operation
  6247.  
  6248. IF condition THEN r/m8  1 ELSE r/m8  0; FI;
  6249.  
  6250. Description
  6251.  
  6252. SETcc stores a byte at the destination specified by the effective address
  6253. or register if the condition is met, or a 0 byte if the condition is not
  6254. met.
  6255.  
  6256. Flags Affected
  6257.  
  6258. None
  6259.  
  6260. Protected Mode Exceptions
  6261.  
  6262. #GP(0) if the result is in a non-writable segment; #GP(0) for an illegal
  6263. memory operand effective address in the CS, DS, ES, FS, or GS segments;
  6264. #SS(0) for an illegal address in the SS segment; #PF(fault-code) for a page
  6265. fault
  6266.  
  6267. Real Address Mode Exceptions
  6268.  
  6269. Interrupt 13 if any part of the operand would lie outside of the effective
  6270. address space from 0 to 0FFFFH
  6271.  
  6272. Virtual 8086 Mode Exceptions
  6273.  
  6274. Same exceptions as in Real Address Mode; #PF(fault-code) for a page
  6275. fault
  6276.  
  6277.  
  6278. SGDT/SIDT ── Store Global/Interrupt Descriptor Table Register
  6279.  
  6280. Opcode       Instruction   Clocks   Description
  6281.  
  6282. 0F  01 /0    SGDT m        9        Store GDTR to m
  6283. 0F  01 /1    SIDT m        9        Store IDTR to m
  6284.  
  6285.  
  6286. Operation
  6287.  
  6288. DEST  48-bit BASE/LIMIT register contents;
  6289.  
  6290. Description
  6291.  
  6292. SGDT/SIDT copies the contents of the descriptor table register the six
  6293. bytes of memory indicated by the operand. The LIMIT field of the
  6294. register is assigned to the first word at the effective address. If the
  6295. operand-size attribute is 32 bits, the next three bytes are assigned the
  6296. BASE field of the register, and the fourth byte is written with zero. The
  6297. last byte is undefined. Otherwise, if the operand-size attribute is 16
  6298. bits, the next four bytes are assigned the 32-bit BASE field of the
  6299. register.
  6300.  
  6301. SGDT and SIDT are used only in operating system software; they are
  6302. not used in application programs.
  6303.  
  6304. Flags Affected
  6305.  
  6306. None
  6307.  
  6308. Protected Mode Exceptions
  6309.  
  6310. Interrupt 6 if the destination operand is a register; #GP(0) if the
  6311. destination is in a nonwritable segment; #GP(0) for an illegal memory
  6312. operand effective address in the CS, DS, ES, FS, or GS segments; #SS(0) for
  6313. an illegal address in the SS segment; #PF(fault-code) for a page fault
  6314.  
  6315. Real Address Mode Exceptions
  6316.  
  6317. Interrupt 6 if the destination operand is a register; Interrupt 13 if any
  6318. part of the operand would lie outside of the effective address space from
  6319. 0 to 0FFFFH
  6320.  
  6321. Virtual 8086 Mode Exceptions
  6322.  
  6323. Same exceptions as in Real Address Mode; #PF(fault-code) for a page
  6324. fault
  6325.  
  6326. Compatability Note
  6327.  
  6328. The 16-bit forms of the SGDT/SIDT instructions are compatible with
  6329. the 80286, if the value in the upper eight bits is not referenced. The
  6330. 80286 stores 1's in these upper bits, whereas the 80386 stores 0's if the
  6331. operand-size attribute is 16 bits. These bits were specified as undefined
  6332. by the SGDT/SIDT instructions in the iAPX 286 Programmer's
  6333. Reference Manual.
  6334.  
  6335.  
  6336. SHLD ── Double Precision Shift Left
  6337.  
  6338. Opcode   Instruction          Clocks   Description
  6339.  
  6340. 0F  A4   SHLD r/m16,r16,imm8  3/7      r/m16 gets SHL of r/m16 concatenated
  6341.                                        with r16
  6342. 0F  A4   SHLD r/m32,r32,imm8  3/7      r/m32 gets SHL of r/m32 concatenated
  6343.                                        with r32
  6344. 0F  A5   SHLD r/m16,r16,CL    3/7      r/m16 gets SHL of r/m16 concatenated
  6345.                                        with r16
  6346. 0F  A5   SHLD r/m32,r32,CL    3/7      r/m32 gets SHL of r/m32 concatenated
  6347.                                        with r32
  6348.  
  6349.  
  6350. Operation
  6351.  
  6352. (* count is an unsigned integer corresponding to the last operand of the
  6353. instruction, either an immediate byte or the byte in register CL *)
  6354. ShiftAmt  count MOD 32;
  6355. inBits  register; (* Allow overlapped operands *)
  6356. IF ShiftAmt = 0
  6357. THEN no operation
  6358. ELSE
  6359.    IF ShiftAmt ≥ OperandSize
  6360.    THEN (* Bad parameters *)
  6361.       r/m  UNDEFINED;
  6362.       CF, OF, SF, ZF, AF, PF  UNDEFINED;
  6363.    ELSE (* Perform the shift *)
  6364.       CF  BIT[Base, OperandSize - ShiftAmt];
  6365.          (* Last bit shifted out on exit *)
  6366.    FOR i  OperandSize - 1 DOWNTO ShiftAmt
  6367.    DO
  6368.       BIT[Base, i]  BIT[Base, i - ShiftAmt];
  6369.    OF;
  6370.    FOR i  ShiftAmt - 1 DOWNTO 0
  6371.    DO
  6372.       BIT[Base, i]  BIT[inBits, i - ShiftAmt + OperandSize];
  6373.    OD;
  6374.    Set SF, ZF, PF (r/m);
  6375.       (* SF, ZF, PF are set according to the value of the result *)
  6376.    AF  UNDEFINED;
  6377.    FI;
  6378. FI;
  6379.  
  6380. Description
  6381.  
  6382. SHLD shifts the first operand provided by the r/m field to the left as
  6383. many bits as specified by the count operand. The second operand (r16 or r32)
  6384. provides the bits to shift in from the right (starting with bit 0). The
  6385. result is stored back into the r/m operand. The register remains unaltered.
  6386.  
  6387. The count operand is provided by either an immediate byte or the contents
  6388. of the CL register. These operands are taken MODULO 32 to provide a number
  6389. between 0 and 31 by which to shift. Because the bits to shift are provided
  6390. by the specified registers, the operation is useful for multiprecision
  6391. shifts (64 bits or more). The SF, ZF and PF flags are set according to the
  6392. value of the result. CS is set to the value of the last bit shifted out. OF
  6393. and AF are left undefined.
  6394.  
  6395. Flags Affected
  6396.  
  6397. OF, SF, ZF, PF, and CF as described above; AF and OF are undefined
  6398.  
  6399. Protected Mode Exceptions
  6400.  
  6401. #GP(0) if the result is in a nonwritable segment; #GP(0) for an illegal
  6402. memory operand effective address in the CS, DS, ES, FS, or GS segments;
  6403. #SS(0) for an illegal address in the SS segment; #PF(fault-code) for a page
  6404. fault
  6405.  
  6406. Real Address Mode Exceptions
  6407.  
  6408. Interrupt 13 if any part of the operand would lie outside of the effective
  6409. address space from 0 to 0FFFFH
  6410.  
  6411. Virtual 8086 Mode Exceptions
  6412.  
  6413. Same exceptions as in Real Address Mode; #PF(fault-code) for a page fault
  6414.  
  6415.  
  6416. SHRD ── Double Precision Shift Right
  6417.  
  6418. Opcode   Instruction           Clocks  Description
  6419.  
  6420. 0F  AC   SHRD r/m16,r16,imm8   3/7     r/m16 gets SHR of r/m16 concatenated
  6421.                                        with r16
  6422. 0F  AC   SHRD r/m32,r32,imm8   3/7     r/m32 gets SHR of r/m32 concatenated
  6423.                                        with r32
  6424. 0F  AD   SHRD r/m16,r16,CL     3/7     r/m16 gets SHR of r/m16 concatenated
  6425.                                        with r16
  6426. 0F  AD   SHRD r/m32,r32,CL     3/7     r/m32 gets SHR of r/m32 concatenated
  6427.                                        with r32
  6428.  
  6429.  
  6430. Operation
  6431.  
  6432. (* count is an unsigned integer corresponding to the last operand of the
  6433. instruction, either an immediate byte or the byte in register CL *)
  6434. ShiftAmt  count MOD 32;
  6435. inBits  register; (* Allow overlapped operands *)
  6436. IF ShiftAmt = 0
  6437. THEN no operation
  6438. ELSE
  6439.    IF ShiftAmt ≥ OperandSize
  6440.    THEN (* Bad parameters *)
  6441.       r/m  UNDEFINED;
  6442.       CF, OF, SF, ZF, AF, PF  UNDEFINED;
  6443.    ELSE (* Perform the shift *)
  6444.       CF  BIT[r/m, ShiftAmt - 1]; (* last bit shifted out on exit *)
  6445.       FOR i  0 TO OperandSize - 1 - ShiftAmt
  6446.       DO
  6447.          BIT[r/m, i]  BIT[r/m, i - ShiftAmt];
  6448.       OD;
  6449.       FOR i  OperandSize - ShiftAmt TO OperandSize - 1
  6450.       DO
  6451.          BIT[r/m,i]  BIT[inBits,i+ShiftAmt - OperandSize];
  6452.       OD;
  6453.       Set SF, ZF, PF (r/m);
  6454.          (* SF, ZF, PF are set according to the value of the result *)
  6455.       Set SF, ZF, PF (r/m);
  6456.       AF  UNDEFINED;
  6457.    FI;
  6458. FI;
  6459.  
  6460. Description
  6461.  
  6462. SHRD shifts the first operand provided by the r/m field to the right as many
  6463. bits as specified by the count operand. The second operand (r16 or r32)
  6464. provides the bits to shift in from the left (starting with bit 31). The
  6465. result is stored back into the r/m operand. The register remains unaltered.
  6466.  
  6467. The count operand is provided by either an immediate byte or the contents
  6468. of the CL register. These operands are taken MODULO 32 to provide a number
  6469. between 0 and 31 by which to shift. Because the bits to shift are provided
  6470. by the specified register, the operation is useful for multi-precision
  6471. shifts (64 bits or more). The SF, ZF and PF flags are set according to the
  6472. value of the result. CS is set to the value of the last bit shifted out. OF
  6473. and AF are left undefined.
  6474.  
  6475. Flags Affected
  6476.  
  6477. OF, SF, ZF, PF, and CF as described above; AF and OF are undefined
  6478.  
  6479. Protected Mode Exceptions
  6480.  
  6481. #GP(0) if the result is in a nonwritable segment; #GP(0) for an illegal
  6482. memory operand effective address in the CS, DS, ES, FS, or GS
  6483. segments; #SS(0) for an illegal address in the SS segment; #PF(fault-code)
  6484. for a page fault
  6485.  
  6486. Real Address Mode Exceptions
  6487.  
  6488. Interrupt 13 if any part of the operand would lie outside of the effective
  6489. address space from 0 to 0FFFFH
  6490.  
  6491. Virtual 8086 Mode Exceptions
  6492.  
  6493. Same exceptions as in Real Address Mode; #PF(fault-code) for a page
  6494. fault
  6495.  
  6496.  
  6497. SLDT ── Store Local Descriptor Table Register
  6498.  
  6499. Opcode      Instruction   Clocks      Description
  6500.  
  6501. 0F  00 /0   SLDT r/m16    pm=2/2      Store LDTR to EA word
  6502.  
  6503.  
  6504. Operation
  6505.  
  6506. r/m16  LDTR;
  6507.  
  6508. Description
  6509.  
  6510. SLDT stores the Local Descriptor Table Register (LDTR) in the two-byte
  6511. register or memory location indicated by the effective address operand.
  6512. This register is a selector that points into the Global Descriptor Table.
  6513.  
  6514. SLDT is used only in operating system software. It is not used in
  6515. application programs.
  6516.  
  6517. Flags Affected
  6518.  
  6519. None
  6520.  
  6521. Protected Mode Exceptions
  6522.  
  6523. #GP(0) if the result is in a nonwritable segment; #GP(0) for an illegal
  6524. memory operand effective address in the CS, DS, ES, FS, or GS segments;
  6525. #SS(0) for an illegal address in the SS segment; #PF(fault-code) for a page
  6526. fault
  6527.  
  6528. Real Address Mode Exceptions
  6529.  
  6530. Interrupt 6; SLDT is not recognized in Real Address Mode
  6531.  
  6532. Virtual 8086 Mode Exceptions
  6533.  
  6534. Same exceptions as in Real Address Mode; #PF(fault-code) for a page fault
  6535.  
  6536. Notes
  6537.  
  6538. The operand-size attribute has no effect on the operation of the
  6539. instruction.
  6540.  
  6541.  
  6542. SMSW ── Store Machine Status Word
  6543.  
  6544. Opcode      Instruction     Clocks          Description
  6545.  
  6546. 0F  01 /4   SMSW r/m16      2/3,pm=2/2      Store machine status word to EA
  6547.                                             word
  6548.  
  6549.  
  6550. Operation
  6551.  
  6552. r/m16  MSW;
  6553.  
  6554. Description
  6555.  
  6556. SMSW stores the machine status word (part of CR0) in the two-byte register
  6557. or memory location indicated by the effective address operand.
  6558.  
  6559. Flags Affected
  6560.  
  6561. None
  6562.  
  6563. Protected Mode Exceptions
  6564.  
  6565. #GP(0) if the result is in a nonwritable segment; #GP(0) for an illegal
  6566. memory operand effective address in the CS, DS, ES, FS, or GS segments;
  6567. #SS(0) for an illegal address in the SS segment; #PF(fault-code) for a page
  6568. fault
  6569.  
  6570. Real Address Mode Exceptions
  6571.  
  6572. Interrupt 13 if any part of the operand would lie outside of the effective
  6573. address space from 0 to 0FFFFH
  6574.  
  6575. Virtual 8086 Mode Exceptions
  6576.  
  6577. Same exceptions as in Real Address Mode; #PF(fault-code) for a page fault
  6578.  
  6579. Notes
  6580.  
  6581. This instruction is provided for compatibility with the 80286; 80386
  6582. programs should use MOV ..., CR0.
  6583.  
  6584.  
  6585. STC ── Set Carry Flag
  6586.  
  6587. Opcode      Instruction     Clocks      Description
  6588.  
  6589. F9          STC             2           Set carry flag
  6590.  
  6591.  
  6592. Operation
  6593.  
  6594. CF  1;
  6595.  
  6596. Description
  6597.  
  6598. STC sets the carry flag to 1.
  6599.  
  6600. Flags Affected
  6601.  
  6602. CF = 1
  6603.  
  6604. Protected Mode Exceptions
  6605.  
  6606. None
  6607.  
  6608. Real Address Mode Exceptions
  6609.  
  6610. None
  6611.  
  6612. Virtual 8086 Mode Exceptions
  6613.  
  6614. None
  6615.  
  6616.  
  6617. STD ── Set Direction Flag
  6618.  
  6619. Opcode  Instruction   Clocks    Description
  6620.  
  6621. FD      STD           2         Set direction flag so (E)SI and/or (E)DI
  6622.                                 decrement
  6623.  
  6624.  
  6625. Operation
  6626.  
  6627. DF  1;
  6628.  
  6629. Description
  6630.  
  6631. STD sets the direction flag to 1, causing all subsequent string operations
  6632. to decrement the index registers, (E)SI and/or (E)DI, on which they
  6633. operate.
  6634.  
  6635. Flags Affected
  6636.  
  6637. DF = 1
  6638.  
  6639. Protected Mode Exceptions
  6640.  
  6641. None
  6642.  
  6643. Real Address Mode Exceptions
  6644.  
  6645. None
  6646.  
  6647. Virtual 8086 Mode Exceptions
  6648.  
  6649. None
  6650.  
  6651.  
  6652. STI ── Set Interrupt Flag
  6653.  
  6654. Opcode  Instruction   Clocks   Description
  6655.  
  6656. F13     STI           3        Set interrupt flag; interrupts enabled at the
  6657.                                end of the next instruction
  6658.  
  6659.  
  6660. Operation
  6661.  
  6662. IF  1
  6663.  
  6664. Description
  6665.  
  6666. STI sets the interrupt flag to 1. The 80386 then responds to external
  6667. interrupts after executing the next instruction if the next instruction
  6668. allows the interrupt flag to remain enabled. If external interrupts are
  6669. disabled and you code STI, RET (such as at the end of a subroutine),
  6670. the RET is allowed to execute before external interrupts are recognized.
  6671. Also, if external interrupts are disabled and you code STI, CLI, then
  6672. external interrupts are not recognized because the CLI instruction clears
  6673. the interrupt flag during its execution.
  6674.  
  6675. Flags Affected
  6676.  
  6677. IF = 1
  6678.  
  6679. Protected Mode Exceptions
  6680.  
  6681. #GP(0) if the current privilege level is greater (has less privilege) than
  6682. the I/O privilege level
  6683.  
  6684. Real Address Mode Exceptions
  6685.  
  6686. None
  6687.  
  6688. Virtual 8086 Mode Exceptions
  6689.  
  6690. None
  6691.  
  6692.  
  6693. STOS/STOSB/STOSW/STOSD ── Store String Data
  6694.  
  6695. Opcode  Instruction  Clocks   Description
  6696.  
  6697. AA      STOS m8      4        Store AL in byte ES:[(E)DI], update (E)DI
  6698. AB      STOS m16     4        Store AX in word ES:[(E)DI], update (E)DI
  6699. AB      STOS m32     4        Store EAX in dword ES:[(E)DI], update (E)DI
  6700. AA      STOSB        4        Store AL in byte ES:[(E)DI], update (E)DI
  6701. AB      STOSW        4        Store AX in word ES:[(E)DI], update (E)DI
  6702. AB      STOSD        4        Store EAX in dword ES:[(E)DI], update (E)DI
  6703.  
  6704.  
  6705. Operation
  6706.  
  6707. IF AddressSize = 16
  6708. THEN use ES:DI for DestReg
  6709. ELSE (* AddressSize = 32 *) use ES:EDI for DestReg;
  6710. FI;
  6711. IF byte type of instruction
  6712. THEN
  6713.    (ES:DestReg)  AL;
  6714.    IF DF = 0
  6715.    THEN DestReg  DestReg + 1;
  6716.    ELSE DestReg  DestReg - 1;
  6717.    FI;
  6718. ELSE IF OperandSize = 16
  6719.    THEN
  6720.       (ES:DestReg)  AX;
  6721.       IF DF = 0
  6722.       THEN DestReg  DestReg + 2;
  6723.       ELSE DestReg  DestReg - 2;
  6724.       FI;
  6725.    ELSE (* OperandSize = 32 *)
  6726.       (ES:DestReg)  EAX;
  6727.       IF DF = 0
  6728.       THEN DestReg  DestReg + 4;
  6729.       ELSE DestReg  DestReg - 4;
  6730.       FI;
  6731.    FI;
  6732. FI;
  6733.  
  6734. Description
  6735.  
  6736. STOS transfers the contents of all AL, AX, or EAX register to the memory
  6737. byte or word given by the destination register relative to the ES segment.
  6738. The destination register is DI for an address-size attribute of 16 bits or
  6739. EDI for an address-size attribute of 32 bits.
  6740.  
  6741. The destination operand must be addressable from the ES register. A segment
  6742. override is not possible.
  6743.  
  6744. The address of the destination is determined by the contents of the
  6745. destination register, not by the explicit operand of STOS. This operand is
  6746. used only to validate ES segment addressability and to determine the data
  6747. type. Load the correct index value into the destination register before
  6748. executing STOS.
  6749.  
  6750. After the transfer is made, DI is automatically updated. If the direction
  6751. flag is 0 (CLD was executed), DI is incremented; if the direction flag is
  6752. 1 (STD was executed), DI is decremented. DI is incremented or decremented by
  6753. 1 if a byte is stored, by 2 if a word is stored, or by 4 if a doubleword is
  6754. stored.
  6755.  
  6756. STOSB, STOSW, and STOSD are synonyms for the byte, word, and doubleword STOS
  6757. instructions, that do not require an operand. They are simpler to use, but
  6758. provide no type or segment checking.
  6759.  
  6760. STOS can be preceded by the REP prefix for a block fill of CX or ECX bytes,
  6761. words, or doublewords. Refer to the REP instruction for further details.
  6762.  
  6763. Flags Affected
  6764.  
  6765. None
  6766.  
  6767. Protected Mode Exceptions
  6768.  
  6769. #GP(0) if the result is in a nonwritable segment; #GP(0) for an illegal
  6770. memory operand effective address in the CS, DS, ES, FS, or GS segments;
  6771. #SS(0) for an illegal address in the SS segment; #PF(fault-code) for a page
  6772. fault
  6773.  
  6774. Real Address Mode Exceptions
  6775.  
  6776. Interrupt 13 if any part of the operand would lie outside of the effective
  6777. address space from 0 to 0FFFFH
  6778.  
  6779. Virtual 8086 Mode Exceptions
  6780.  
  6781. Same exceptions as in Real Address Mode; #PF(fault-code) for a page fault
  6782.  
  6783.  
  6784. STR ── Store Task Register
  6785.  
  6786. Opcode        Instruction   Clocks       Description
  6787.  
  6788. 0F  00 /1     STR r/m16     pm=23/27     Load EA word into task register
  6789.  
  6790.  
  6791. Operation
  6792.  
  6793. r/m  task register;
  6794.  
  6795. Description
  6796.  
  6797. The contents of the task register are copied to the two-byte register or
  6798. memory location indicated by the effective address operand.
  6799.  
  6800. STR is used only in operating system software. It is not used in application
  6801. programs.
  6802.  
  6803. Flags Affected
  6804.  
  6805. None
  6806.  
  6807. Protected Mode Exceptions
  6808.  
  6809. #GP(0) if the result is in a nonwritable segment; #GP(0) for an illegal
  6810. memory operand effective address in the CS, DS, ES, FS, or GS segments;
  6811. #SS(0) for an illegal address in the SS segment; #PF(fault-code) for a page
  6812. fault
  6813.  
  6814. Real Address Mode Exceptions
  6815.  
  6816. Interrupt 6; STR is not recognized in Real Address Mode
  6817.  
  6818. Virtual 8086 Mode Exceptions
  6819.  
  6820. Same exceptions as in Real Address Mode
  6821.  
  6822. Notes
  6823.  
  6824. The operand-size attribute has no effect on this instruction.
  6825.  
  6826.  
  6827. SUB ── Integer Subtraction
  6828.  
  6829. Opcode      Instruction      Clocks   Description
  6830.  
  6831. 2C  ib      SUB AL,imm8      2        Subtract immediate byte from AL
  6832. 2D  iw      SUB AX,imm16     2        Subtract immediate word from AX
  6833. 2D  id      SUB EAX,imm32    2        Subtract immediate dword from EAX
  6834. 80  /5 ib   SUB r/m8,imm8    2/7      Subtract immediate byte from r/m byte
  6835. 81  /5 iw   SUB r/m16,imm16  2/7      Subtract immediate word from r/m word
  6836. 81  /5 id   SUB r/m32,imm32  2/7      Subtract immediate dword from r/m
  6837.                                       dword
  6838. 83  /5 ib   SUB r/m16,imm8   2/7      Subtract sign-extended immediate byte
  6839.                                       from r/m word
  6840. 83  /5 ib   SUB r/m32,imm8   2/7      Subtract sign-extended immediate byte
  6841.                                       from r/m dword
  6842. 28  /r      SUB r/m8,r8      2/6      Subtract byte register from r/m byte
  6843. 29  /r      SUB r/m16,r16    2/6      Subtract word register from r/m word
  6844. 29  /r      SUB r/m32,r32    2/6      Subtract dword register from r/m
  6845.                                       dword
  6846. 2A  /r      SUB r8,r/m8      2/7      Subtract byte register from r/m byte
  6847. 2B  /r      SUB r16,r/m16    2/7      Subtract word register from r/m word
  6848. 2B  /r      SUB r32,r/m32    2/7      Subtract dword register from r/m
  6849.                                       dword
  6850.  
  6851.  
  6852. Operation
  6853.  
  6854. IF SRC is a byte and DEST is a word or dword
  6855. THEN DEST = DEST - SignExtend(SRC);
  6856. ELSE DEST  DEST - SRC;
  6857. FI;
  6858.  
  6859. Description
  6860.  
  6861. SUB subtracts the second operand (SRC) from the first operand (DEST). The
  6862. first operand is assigned the result of the subtraction, and the flags are
  6863. set accordingly.
  6864.  
  6865. When an immediate byte value is subtracted from a word operand, the
  6866. immediate value is first sign-extended to the size of the destination
  6867. operand.
  6868.  
  6869. Flags Affected
  6870.  
  6871. OF, SF, ZF, AF, PF, and CF as described in Appendix C
  6872.  
  6873. Protected Mode Exceptions
  6874.  
  6875. #GP(0) if the result is in a nonwritable segment; #GP(0) for an illegal
  6876. memory operand effective address in the CS, DS, ES, FS, or GS segments;
  6877. #SS(0) for an illegal address in the SS segment; #PF(fault-code) for a page
  6878. fault
  6879.  
  6880. Real Address Mode Exceptions
  6881.  
  6882. Interrupt 13 if any part of the operand would lie outside of the effective
  6883. address space from 0 to 0FFFFH
  6884.  
  6885. Virtual 8086 Mode Exceptions
  6886.  
  6887. Same exceptions as in Real Address Mode; #PF(fault-code) for a page fault
  6888.  
  6889.  
  6890. TEST ── Logical Compare
  6891.  
  6892. Opcode       Instruction       Clocks   Description
  6893.  
  6894. A8   ib      TEST AL,imm8      2        AND immediate byte with AL
  6895. A9   iw      TEST AX,imm16     2        AND immediate word with AX
  6896. A9   id      TEST EAX,imm32    2        AND immediate dword with EAX
  6897. F6   /0 ib   TEST r/m8,imm8    2/5      AND immediate byte with r/m byte
  6898. F7   /0 iw   TEST r/m16,imm16  2/5      AND immediate word with r/m word
  6899. F7   /0 id   TEST r/m32,imm32  2/5      AND immediate dword with r/m dword
  6900. 84   /r      TEST r/m8,r8      2/5      AND byte register with r/m byte
  6901. 85   /r      TEST r/m16,r16    2/5      AND word register with r/m word
  6902. 85   /r      TEST r/m32,r32    2/5      AND dword register with r/m dword
  6903.  
  6904.  
  6905. Operation
  6906.  
  6907. DEST : = LeftSRC AND RightSRC;
  6908. CF  0;
  6909. OF  0;
  6910.  
  6911. Description
  6912.  
  6913. TEST computes the bit-wise logical AND of its two operands. Each bit
  6914. of the result is 1 if both of the corresponding bits of the operands are 1;
  6915. otherwise, each bit is 0. The result of the operation is discarded and only
  6916. the flags are modified.
  6917.  
  6918. Flags Affected
  6919.  
  6920. OF = 0, CF = 0; SF, ZF, and PF as described in Appendix C
  6921.  
  6922. Protected Mode Exceptions
  6923.  
  6924. #GP(0) for an illegal memory operand effective address in the CS, DS,
  6925. ES, FS, or GS segments; #SS(0) for an illegal address in the SS segment;
  6926. #PF(fault-code) for a page fault
  6927.  
  6928. Real Address Mode Exceptions
  6929.  
  6930. Interrupt 13 if any part of the operand would lie outside of the effective
  6931. address space from 0 to 0FFFFH
  6932.  
  6933. Virtual 8086 Mode Exceptions
  6934.  
  6935. Same exceptions as in Real Address Mode; #PF(fault-code) for a page
  6936. fault
  6937.  
  6938.  
  6939. VERR, VERW ── Verify a Segment for Reading or Writing
  6940.  
  6941. Opcode       Instruction   Clocks      Description
  6942.  
  6943. 0F  00 /4    VERR r/m16    pm=10/11    Set ZF=1 if segment can be read,
  6944.                                        selector in r/m16
  6945. 0F  00 /5    VERW r/m16    pm=15/16    Set ZF=1 if segment can be written,
  6946.                                        selector in r/m16
  6947.  
  6948.  
  6949. Operation
  6950.  
  6951. IF segment with selector at (r/m) is accessible
  6952.    with current protection level
  6953.    AND ((segment is readable for VERR) OR
  6954.       (segment is writable for VERW))
  6955. THEN ZF  0;
  6956. ELSE ZF  1;
  6957. FI;
  6958.  
  6959. Description
  6960.  
  6961. The two-byte register or memory operand of VERR and VERW contains
  6962. the value of a selector. VERR and VERW determine whether the
  6963. segment denoted by the selector is reachable from the current privilege
  6964. level and whether the segment is readable (VERR) or writable (VERW).
  6965. If the segment is accessible, the zero flag is set to 1; if the segment is
  6966. not accessible, the zero flag is set to 0. To set ZF, the following
  6967. conditions must be met:
  6968.  
  6969.   ■  The selector must denote a descriptor within the bounds of the table
  6970.      (GDT or LDT); the selector must be "defined."
  6971.  
  6972.   ■  The selector must denote the descriptor of a code or data segment
  6973.      (not that of a task state segment, LDT, or a gate).
  6974.  
  6975.   ■  For VERR, the segment must be readable. For VERW, the segment
  6976.      must be a writable data segment.
  6977.  
  6978.   ■  If the code segment is readable and conforming, the descriptor
  6979.      privilege level (DPL) can be any value for VERR. Otherwise, the
  6980.      DPL must be greater than or equal to (have less or the same
  6981.      privilege as) both the current privilege level and the selector's RPL.
  6982.  
  6983. The validation performed is the same as if the segment were loaded into
  6984. DS, ES, FS, or GS, and the indicated access (read or write) were
  6985. performed. The zero flag receives the result of the validation. The
  6986. selector's value cannot result in a protection exception, enabling the
  6987. software to anticipate possible segment access problems.
  6988.  
  6989. Flags Affected
  6990.  
  6991. ZF as described above
  6992.  
  6993. Protected Mode Exceptions
  6994.  
  6995. Faults generated by illegal addressing of the memory operand that
  6996. contains the selector, the selector is not loaded into any segment
  6997. register, and no faults attributable to the selector operand are generated
  6998.  
  6999. #GP(0) for an illegal memory operand effective address in the CS, DS,
  7000. ES, FS, or GS segments; #SS(0) for an illegal address in the SS segment;
  7001. #PF(fault-code) for a page fault
  7002.  
  7003. Real Address Mode Exceptions
  7004.  
  7005. Interrupt 6; VERR and VERW are not recognized in Real Address Mode
  7006.  
  7007. Virtual 8086 Mode Exceptions
  7008.  
  7009. Same exceptions as in Real Address Mode; #PF(fault-code) for a page
  7010. fault
  7011.  
  7012.  
  7013. WAIT ── Wait until BUSY# Pin is Inactive (HIGH)
  7014.  
  7015. Opcode   Instruction   Clocks     Description
  7016.  
  7017. 9B       WAIT          6 min.     Wait until BUSY pin is inactive (HIGH)
  7018.  
  7019.  
  7020. Description
  7021.  
  7022. WAIT suspends execution of 80386 instructions until the BUSY# pin is
  7023. inactive (high). The BUSY# pin is driven by the 80287 numeric processor
  7024. extension.
  7025.  
  7026. Flags Affected
  7027.  
  7028. None
  7029.  
  7030. Protected Mode Exceptions
  7031.  
  7032. #NM if the task-switched flag in the machine status word (the lower 16 bits
  7033. of register CR0) is set; #MF if the ERROR# input pin is asserted (i.e., the
  7034. 80287 has detected an unmasked numeric error)
  7035.  
  7036. Real Address Mode Exceptions
  7037.  
  7038. Same exceptions as in Protected Mode
  7039.  
  7040. Virtual 8086 Mode Exceptions
  7041.  
  7042. Same exceptions as in Protected Mode
  7043.  
  7044.  
  7045. XCHG ── Exchange Register/Memory with Register
  7046.  
  7047. Opcode    Instruction      Clocks     Description
  7048.  
  7049. 90 + r    XCHG AX,r16      3          Exchange word register with AX
  7050. 90 + r    XCHG r16,AX      3          Exchange word register with AX
  7051. 90 + r    XCHG EAX,r32     3          Exchange dword register with EAX
  7052. 90 + r    XCHG r32,EAX     3          Exchange dword register with EAX
  7053. 86  /r    XCHG r/m8,r8     3          Exchange byte register with EA byte
  7054. 86  /r    XCHG r8,r/m8     3/5        Exchange byte register with EA byte
  7055. 87  /r    XCHG r/m16,r16   3          Exchange word register with EA word
  7056. 87  /r    XCHG r16,r/m16   3/5        Exchange word register with EA word
  7057. 87  /r    XCHG r/m32,r32   3          Exchange dword register with EA dword
  7058. 87  /r    XCHG r32,r/m32   3/5        Exchange dword register with EA dword
  7059.  
  7060.  
  7061. Operation
  7062.  
  7063. temp  DEST
  7064. DEST  SRC
  7065. SRC  temp
  7066.  
  7067. Description
  7068.  
  7069. XCHG exchanges two operands. The operands can be in either order. If a
  7070. memory operand is involved, BUS LOCK is asserted for the duration of the
  7071. exchange, regardless of the presence or absence of the LOCK prefix or of the
  7072. value of the IOPL.
  7073.  
  7074. Flags Affected
  7075.  
  7076. None
  7077.  
  7078. Protected Mode Exceptions
  7079.  
  7080. #GP(0) if either operand is in a nonwritable segment; #GP(0) for an
  7081. illegal memory operand effective address in the CS, DS, ES, FS, or GS
  7082. segments; #SS(0) for an illegal address in the SS segment; #PF(fault-code)
  7083. for a page fault
  7084.  
  7085. Real Address Mode Exceptions
  7086.  
  7087. Interrupt 13 if any part of the operand would lie outside of the effective
  7088. address space from 0 to 0FFFFH
  7089.  
  7090. Virtual 8086 Mode Exceptions
  7091.  
  7092. Same exceptions as in Real Address Mode; #PF(fault-code) for a page
  7093. fault
  7094.  
  7095.  
  7096. XLAT/XLATB ── Table Look-up Translation
  7097.  
  7098. D7    XLAT m8    5     Set AL to memory byte DS:[(E)BX + unsigned AL]
  7099. D7    XLATB      5     Set AL to memory byte DS:[(E)BX + unsigned AL]
  7100.  
  7101.  
  7102. Operation
  7103.  
  7104. IF AddressSize = 16
  7105. THEN
  7106.    AL  (BX + ZeroExtend(AL))
  7107. ELSE (* AddressSize = 32 *)
  7108.    AL  (EBX + ZeroExtend(AL));
  7109. FI;
  7110.  
  7111. Description
  7112.  
  7113. XLAT changes the AL register from the table index to the table entry. AL
  7114. should be the unsigned index into a table addressed by DS:BX (for an
  7115. address-size attribute of 16 bits) or DS:EBX (for an address-size attribute
  7116. of 32 bits).
  7117.  
  7118. The operand to XLAT allows for the possibility of a segment override. XLAT
  7119. uses the contents of BX even if they differ from the offset of the operand.
  7120. The offset of the operand should have been moved intoBX/EBX with a previous
  7121. instruction.
  7122.  
  7123. The no-operand form, XLATB, can be used if the BX/EBX table will always
  7124. reside in the DS segment.
  7125.  
  7126. Flags Affected
  7127.  
  7128. None
  7129.  
  7130. Protected Mode Exceptions
  7131.  
  7132. #GP(0) for an illegal memory operand effective address in the CS, DS, ES,
  7133. FS, or GS segments; #SS(0) for an illegal address in the SS segment;
  7134. #PF(fault-code) for a page fault
  7135.  
  7136. Real Address Mode Exceptions
  7137.  
  7138. Interrupt 13 if any part of the operand would lie outside of the effective
  7139. address space from 0 to 0FFFFH
  7140.  
  7141. Virtual 8086 Mode Exceptions
  7142.  
  7143. Same exceptions as in Real Address Mode; #PF(fault-code) for a page fault
  7144.  
  7145.  
  7146. XOR ── Logical Exclusive OR
  7147.  
  7148.  
  7149. Opcode      Instruction      Clocks   Description
  7150.  
  7151. 34  ib      XOR AL,imm8      2        Exclusive-OR immediate byte to AL
  7152. 35  iw      XOR AX,imm16     2        Exclusive-OR immediate word to AX
  7153. 35  id      XOR EAX,imm32    2        Exclusive-OR immediate dword to EAX
  7154. 80  /6 ib   XOR r/m8,imm8    2/7      Exclusive-OR immediate byte to r/m
  7155.                                       byte
  7156. 81  /6 iw   XOR r/m16,imm16  2/7      Exclusive-OR immediate word to r/m
  7157.                                       word
  7158. 81  /6 id   XOR r/m32,imm32  2/7      Exclusive-OR immediate dword to r/m
  7159.                                       dword
  7160. 83  /6 ib   XOR r/m16,imm8   2/7      XOR sign-extended immediate byte
  7161.                                       with r/m word
  7162. 83  /6 ib   XOR r/m32,imm8   2/7      XOR sign-extended immediate byte
  7163.                                       with r/m dword
  7164. 30  /r      XOR r/m8,r8      2/6      Exclusive-OR byte register to r/m
  7165.                                       byte
  7166. 31  /r      XOR r/m16,r16    2/6      Exclusive-OR word register to r/m
  7167.                                       word
  7168. 31  /r      XOR r/m32,r32    2/6      Exclusive-OR dword register to r/m
  7169.                                       dword
  7170. 32  /r      XOR r8,r/m8      2/7      Exclusive-OR byte register to r/m
  7171.                                       byte
  7172. 33  /r      XOR r16,r/m16    2/7      Exclusive-OR word register to r/m
  7173.                                       word
  7174. 33  /r      XOR r32,r/m32    2/7      Exclusive-OR dword register to r/m
  7175.                                       dword
  7176.  
  7177.  
  7178. Operation
  7179.  
  7180. DEST  LeftSRC XOR RightSRC
  7181. CF  0
  7182. OF  0
  7183.  
  7184. Description
  7185.  
  7186. XOR computes the exclusive OR of the two operands. Each bit of the result
  7187. is 1 if the corresponding bits of the operands are different; each bit is 0
  7188. if the corresponding bits are the same. The answer replaces the first
  7189. operand.
  7190.  
  7191. Flags Affected
  7192.  
  7193. CF = 0, OF = 0; SF, ZF, and PF as described in Appendix C; AF is undefined
  7194.  
  7195. Protected Mode Exceptions
  7196.  
  7197. #GP(0) if the result is in a nonwritable segment; #GP(0) for an illegal
  7198. memory operand effective address in the CS, DS, ES, FS, or GS segments;
  7199. #SS(0) for an illegal address in the SS segment; #PF(fault-code) for a page
  7200. fault
  7201.  
  7202. Real Address Mode Exceptions
  7203.  
  7204. Interrupt 13 if any part of the operand would lie outside of the effective
  7205. address space from 0 to 0FFFFH
  7206.  
  7207. Virtual 8086 Mode Exceptions
  7208.  
  7209. Same exceptions as in Real Address Mode; #PF(fault-code) for a page
  7210. fault
  7211.  
  7212.  
  7213.