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

  1. Chapter 17  80386 Instruction Set
  2.  
  3. ────────────────────────────────────────────────────────────────────────────
  4.  
  5. This chapter presents instructions for the 80386 in alphabetical order. For
  6. each instruction, the forms are given for each operand combination,
  7. including object code produced, operands required, execution time, and a
  8. description. For each instruction, there is an operational description and a
  9. summary of exceptions generated.
  10.  
  11.  
  12. 17.1  Operand-Size and Address-Size Attributes
  13.  
  14. When executing an instruction, the 80386 can address memory using either 16
  15. or 32-bit addresses. Consequently, each instruction that uses memory
  16. addresses has associated with it an address-size attribute of either 16 or
  17. 32 bits. 16-bit addresses imply both the use of a 16-bit displacement in
  18. the instruction and the generation of a 16-bit address offset (segment
  19. relative address) as the result of the effective address calculation.
  20. 32-bit addresses imply the use of a 32-bit displacement and the generation
  21. of a 32-bit address offset. Similarly, an instruction that accesses words
  22. (16 bits) or doublewords (32 bits) has an operand-size attribute of either
  23. 16 or 32 bits.
  24.  
  25. The attributes are determined by a combination of defaults, instruction
  26. prefixes, and (for programs executing in protected mode) size-specification
  27. bits in segment descriptors.
  28.  
  29.  
  30. 17.1.1  Default Segment Attribute
  31.  
  32. For programs executed in protected mode, the D-bit in executable-segment
  33. descriptors determines the default attribute for both address size and
  34. operand size. These default attributes apply to the execution of all
  35. instructions in the segment. A value of zero in the D-bit sets the default
  36. address size and operand size to 16 bits; a value of one, to 32 bits.
  37.  
  38. Programs that execute in real mode or virtual-8086 mode have 16-bit
  39. addresses and operands by default.
  40.  
  41.  
  42. 17.1.2  Operand-Size and Address-Size Instruction Prefixes
  43.  
  44. The internal encoding of an instruction can include two byte-long prefixes:
  45. the address-size prefix, 67H, and the operand-size prefix, 66H. (A later
  46. section, "Instruction Format," shows the position of the prefixes in an
  47. instruction's encoding.) These prefixes override the default segment
  48. attributes for the instruction that follows. Table 17-1 shows the effect of
  49. each possible combination of defaults and overrides.
  50.  
  51.  
  52. 17.1.3  Address-Size Attribute for Stack
  53.  
  54. Instructions that use the stack implicitly (for example: POP EAX also have
  55. a stack address-size attribute of either 16 or 32 bits. Instructions with a
  56. stack address-size attribute of 16 use the 16-bit SP stack pointer register;
  57. instructions with a stack address-size attribute of 32 bits use the 32-bit
  58. ESP register to form the address of the top of the stack.
  59.  
  60. The stack address-size attribute is controlled by the B-bit of the
  61. data-segment descriptor in the SS register. A value of zero in the B-bit
  62. selects a stack address-size attribute of 16; a value of one selects a stack
  63. address-size attribute of 32.
  64.  
  65.  
  66. Table 17-1. Effective Size Attributes
  67.  
  68. Segment Default D = ...      0    0    0    0    1    1    1    1
  69. Operand-Size Prefix 66H      N    N    Y    Y    N    N    Y    Y
  70. Address-Size Prefix 67H      N    Y    N    Y    N    Y    N    Y
  71.  
  72. Effective Operand Size      16   16   32   32   32   32   16   16
  73. Effective Address Size      16   32   16   32   32   16   32   16
  74.  
  75. Y = Yes, this instruction prefix is present
  76. N = No, this instruction prefix is not present
  77.  
  78.  
  79. 17.2  Instruction Format
  80.  
  81. All instruction encodings are subsets of the general instruction format
  82. shown in Figure 17-1. Instructions consist of optional instruction
  83. prefixes, one or two primary opcode bytes, possibly an address specifier
  84. consisting of the ModR/M byte and the SIB (Scale Index Base) byte, a
  85. displacement, if required, and an immediate data field, if required.
  86.  
  87. Smaller encoding fields can be defined within the primary opcode or
  88. opcodes. These fields define the direction of the operation, the size of the
  89. displacements, the register encoding, or sign extension; encoding fields
  90. vary depending on the class of operation.
  91.  
  92. Most instructions that can refer to an operand in memory have an addressing
  93. form byte following the primary opcode byte(s). This byte, called the ModR/M
  94. byte, specifies the address form to be used. Certain encodings of the ModR/M
  95. byte indicate a second addressing byte, the SIB (Scale Index Base) byte,
  96. which follows the ModR/M byte and is required to fully specify the
  97. addressing form.
  98.  
  99. Addressing forms can include a displacement immediately following either
  100. the ModR/M or SIB byte. If a displacement is present, it can be 8-, 16- or
  101. 32-bits.
  102.  
  103. If the instruction specifies an immediate operand, the immediate operand
  104. always follows any displacement bytes. The immediate operand, if specified,
  105. is always the last field of the instruction.
  106.  
  107. The following are the allowable instruction prefix codes:
  108.  
  109.    F3H    REP prefix (used only with string instructions)
  110.    F3H    REPE/REPZ prefix (used only with string instructions
  111.    F2H    REPNE/REPNZ prefix (used only with string instructions)
  112.    F0H    LOCK prefix
  113.  
  114. The following are the segment override prefixes:
  115.  
  116.    2EH    CS segment override prefix
  117.    36H    SS segment override prefix
  118.    3EH    DS segment override prefix
  119.    26H    ES segment override prefix
  120.    64H    FS segment override prefix
  121.    65H    GS segment override prefix
  122.    66H    Operand-size override
  123.    67H    Address-size override
  124.  
  125.  
  126. Figure 17-1.  80386 Instruction Format
  127.  
  128.       ╔═══════════════╦═══════════════╦═══════════════╦═══════════════╗
  129.       ║  INSTRUCTION  ║   ADDRESS-    ║    OPERAND-   ║   SEGMENT     ║
  130.       ║    PREFIX     ║  SIZE PREFIX  ║  SIZE PREFIX  ║   OVERRIDE    ║
  131.       ╠═══════════════╩═══════════════╩═══════════════╩═══════════════╣
  132.       ║     0 OR 1         0 OR 1           0 OR 1         0 OR 1     ║
  133.       ╟─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─╢
  134.       ║                        NUMBER OF BYTES                        ║
  135.       ╚═══════════════════════════════════════════════════════════════╝
  136.  
  137.       ╔══════════╦═══════════╦═══════╦══════════════════╦═════════════╗
  138.       ║  OPCODE  ║  MODR/M   ║  SIB  ║   DISPLACEMENT   ║  IMMEDIATE  ║
  139.       ║          ║           ║       ║                  ║             ║
  140.       ╠══════════╩═══════════╩═══════╩══════════════════╩═════════════╣
  141.       ║  1 OR 2     0 OR 1    0 OR 1      0,1,2 OR 4       0,1,2 OR 4 ║
  142.       ╟─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─╢
  143.       ║                        NUMBER OF BYTES                        ║
  144.       ╚═══════════════════════════════════════════════════════════════╝
  145.  
  146.  
  147. 17.2.1  ModR/M and SIB Bytes
  148.  
  149. The ModR/M and SIB bytes follow the opcode byte(s) in many of the 80386
  150. instructions. They contain the following information:
  151.  
  152.   ■  The indexing type or register number to be used in the instruction
  153.   ■  The register to be used, or more information to select the instruction
  154.   ■  The base, index, and scale information
  155.  
  156. The ModR/M byte contains three fields of information:
  157.  
  158.   ■  The mod field, which occupies the two most significant bits of the 
  159.      byte, combines with the r/m field to form 32 possible values: eight
  160.      registers and 24 indexing modes
  161.  
  162.   ■  The reg field, which occupies the next three bits following the mod
  163.      field, specifies either a register number or three more bits of opcode
  164.      information. The meaning of the reg field is determined by the first
  165.      (opcode) byte of the instruction.
  166.  
  167.   ■  The r/m field, which occupies the three least significant bits of the
  168.      byte, can specify a register as the location of an operand, or can form
  169.      part of the addressing-mode encoding in combination with the field as
  170.      described above
  171.  
  172. The based indexed and scaled indexed forms of 32-bit addressing require the
  173. SIB byte. The presence of the SIB byte is indicated by certain encodings of
  174. the ModR/M byte. The SIB byte then includes the following fields:
  175.  
  176.   ■  The ss field, which occupies the two most significant bits of the
  177.      byte, specifies the scale factor
  178.  
  179.   ■  The index field, which occupies the next three bits following the ss
  180.      field and specifies the register number of the index register
  181.  
  182.   ■  The base field, which occupies the three least significant bits of the
  183.      byte, specifies the register number of the base register
  184.  
  185. Figure 17-2 shows the formats of the ModR/M and SIB bytes.
  186.  
  187. The values and the corresponding addressing forms of the ModR/M and SIB
  188. bytes are shown in Tables 17-2, 17-3, and 17-4. The 16-bit addressing
  189. forms specified by the ModR/M byte are in Table 17-2. The 32-bit addressing
  190. forms specified by ModR/M are in Table 17-3. Table 17-4 shows the 32-bit
  191. addressing forms specified by the SIB byte
  192.  
  193.  
  194. Figure 17-2.  ModR/M and SIB Byte Formats
  195.  
  196.                                  MODR/M BYTE
  197.  
  198.                      7    6    5    4    3    2    1    0
  199.                     ╔════════╦═════════════╦═════════════╗
  200.                     ║  MOD   ║ REG/OPCODE  ║     R/M     ║
  201.                     ╚════════╩═════════════╩═════════════╝
  202.  
  203.                           SIB (SCALE INDEX BASE) BYTE
  204.  
  205.                      7    6    5    4    3    2    1    0
  206.                     ╔════════╦═════════════╦═════════════╗
  207.                     ║   SS   ║    INDEX    ║    BASE     ║
  208.                     ╚════════╩═════════════╩═════════════╝
  209.  
  210.  
  211. Table 17-2. 16-Bit Addressing Forms with the ModR/M Byte
  212.  
  213.  
  214. r8(/r)                     AL    CL    DL    BL    AH    CH    DH    BH
  215. r16(/r)                    AX    CX    DX    BX    SP    BP    SI    DI
  216. r32(/r)                    EAX   ECX   EDX   EBX   ESP   EBP   ESI   EDI
  217. /digit (Opcode)            0     1     2     3     4     5     6     7
  218. REG =                      000   001   010   011   100   101   110   111
  219.  
  220.    Effective
  221. ┌───Address
  222. disp8 denotes an 8-bit displacement following the ModR/M byte, to be
  223. sign-extended and added to the index. disp16 denotes a 16-bit displacement
  224. following the ModR/M byte, to be added to the index. Default segment
  225. register is SS for the effective addresses containing a BP index, DS for
  226. other effective addresses.──┐ ┌Mod R/M┐ ┌────────ModR/M Values in Hexadecimal────────┐
  227.  
  228. [BX + SI]            000   00    08    10    18    20    28    30    38
  229. [BX + DI]            001   01    09    11    19    21    29    31    39
  230. [BP + SI]            010   02    0A    12    1A    22    2A    32    3A
  231. [BP + DI]            011   03    0B    13    1B    23    2B    33    3B
  232. [SI]             00  100   04    0C    14    1C    24    2C    34    3C
  233. [DI]                 101   05    0D    15    1D    25    2D    35    3D
  234. disp16               110   06    0E    16    1E    26    2E    36    3E
  235. [BX]                 111   07    0F    17    1F    27    2F    37    3F
  236.  
  237. [BX+SI]+disp8        000   40    48    50    58    60    68    70    78
  238. [BX+DI]+disp8        001   41    49    51    59    61    69    71    79
  239. [BP+SI]+disp8        010   42    4A    52    5A    62    6A    72    7A
  240. [BP+DI]+disp8        011   43    4B    53    5B    63    6B    73    7B
  241. [SI]+disp8       01  100   44    4C    54    5C    64    6C    74    7C
  242. [DI]+disp8           101   45    4D    55    5D    65    6D    75    7D
  243. [BP]+disp8           110   46    4E    56    5E    66    6E    76    7E
  244. [BX]+disp8           111   47    4F    57    5F    67    6F    77    7F
  245.  
  246. [BX+SI]+disp16       000   80    88    90    98    A0    A8    B0    B8
  247. [BX+DI]+disp16       001   81    89    91    99    A1    A9    B1    B9
  248. [BX+SI]+disp16       010   82    8A    92    9A    A2    AA    B2    BA
  249. [BX+DI]+disp16       011   83    8B    93    9B    A3    AB    B3    BB
  250. [SI]+disp16      10  100   84    8C    94    9C    A4    AC    B4    BC
  251. [DI]+disp16          101   85    8D    95    9D    A5    AD    B5    BD
  252. [BP]+disp16          110   86    8E    96    9E    A6    AE    B6    BE
  253. [BX]+disp16          111   87    8F    97    9F    A7    AF    B7    BF
  254.  
  255. EAX/AX/AL            000   C0    C8    D0    D8    E0    E8    F0    F8
  256. ECX/CX/CL            001   C1    C9    D1    D9    E1    E9    F1    F9
  257. EDX/DX/DL            010   C2    CA    D2    DA    E2    EA    F2    FA
  258. EBX/BX/BL            011   C3    CB    D3    DB    E3    EB    F3    FB
  259. ESP/SP/AH        11  100   C4    CC    D4    DC    E4    EC    F4    FC
  260. EBP/BP/CH            101   C5    CD    D5    DD    E5    ED    F5    FD
  261. ESI/SI/DH            110   C6    CE    D6    DE    E6    EE    F6    FE
  262. EDI/DI/BH            111   C7    CF    D7    DF    E7    EF    F7    FF
  263.  
  264.  
  265. ───────────────────────────────────────────────────────────────────────────
  266. NOTES:
  267.   disp8 denotes an 8-bit displacement following the ModR/M byte, to be
  268.   sign-extended and added to the index. disp16 denotes a 16-bit displacement
  269.   following the ModR/M byte, to be added to the index. Default segment
  270.   register is SS for the effective addresses containing a BP index, DS for
  271.   other effective addresses.
  272. ───────────────────────────────────────────────────────────────────────────
  273.  
  274.  
  275. Table 17-3. 32-Bit Addressing Forms with the ModR/M Byte
  276.  
  277.  
  278. r8(/r)                     AL    CL    DL    BL    AH    CH    DH    BH
  279. r16(/r)                    AX    CX    DX    BX    SP    BP    SI    DI
  280. r32(/r)                    EAX   ECX   EDX   EBX   ESP   EBP   ESI   EDI
  281. /digit (Opcode)            0     1     2     3     4     5     6     7
  282. REG =                      000   001   010   011   100   101   110   111
  283.  
  284.    Effective
  285. ┌───Address
  286. [--] [--] means a SIB follows the ModR/M byte. disp8 denotes an 8-bit
  287. displacement following the SIB byte, to be sign-extended and added to the
  288. index. disp32 denotes a 32-bit displacement following the ModR/M byte, to
  289. be added to the index.──┐ ┌Mod R/M┐ ┌─────────ModR/M Values in Hexadecimal───────┐
  290.  
  291. [EAX]                000   00    08    10    18    20    28    30    38
  292. [ECX]                001   01    09    11    19    21    29    31    39
  293. [EDX]                010   02    0A    12    1A    22    2A    32    3A
  294. [EBX]                011   03    0B    13    1B    23    2B    33    3B
  295. [--] [--]        00  100   04    0C    14    1C    24    2C    34    3C
  296. disp32               101   05    0D    15    1D    25    2D    35    3D
  297. [ESI]                110   06    0E    16    1E    26    2E    36    3E
  298. [EDI]                111   07    0F    17    1F    27    2F    37    3F
  299.  
  300. disp8[EAX]           000   40    48    50    58    60    68    70    78
  301. disp8[ECX]           001   41    49    51    59    61    69    71    79
  302. disp8[EDX]           010   42    4A    52    5A    62    6A    72    7A
  303. disp8[EPX];          011   43    4B    53    5B    63    6B    73    7B
  304. disp8[--] [--]   01  100   44    4C    54    5C    64    6C    74    7C
  305. disp8[ebp]           101   45    4D    55    5D    65    6D    75    7D
  306. disp8[ESI]           110   46    4E    56    5E    66    6E    76    7E
  307. disp8[EDI]           111   47    4F    57    5F    67    6F    77    7F
  308.  
  309. disp32[EAX]          000   80    88    90    98    A0    A8    B0    B8
  310. disp32[ECX]          001   81    89    91    99    A1    A9    B1    B9
  311. disp32[EDX]          010   82    8A    92    9A    A2    AA    B2    BA
  312. disp32[EBX]          011   83    8B    93    9B    A3    AB    B3    BB
  313. disp32[--] [--]  10  100   84    8C    94    9C    A4    AC    B4    BC
  314. disp32[EBP]          101   85    8D    95    9D    A5    AD    B5    BD
  315. disp32[ESI]          110   86    8E    96    9E    A6    AE    B6    BE
  316. disp32[EDI]          111   87    8F    97    9F    A7    AF    B7    BF
  317.  
  318. EAX/AX/AL            000   C0    C8    D0    D8    E0    E8    F0    F8
  319. ECX/CX/CL            001   C1    C9    D1    D9    E1    E9    F1    F9
  320. EDX/DX/DL            010   C2    CA    D2    DA    E2    EA    F2    FA
  321. EBX/BX/BL            011   C3    CB    D3    DB    E3    EB    F3    FB
  322. ESP/SP/AH        11  100   C4    CC    D4    DC    E4    EC    F4    FC
  323. EBP/BP/CH            101   C5    CD    D5    DD    E5    ED    F5    FD
  324. ESI/SI/DH            110   C6    CE    D6    DE    E6    EE    F6    FE
  325. EDI/DI/BH            111   C7    CF    D7    DF    E7    EF    F7    FF
  326.  
  327.  
  328. ───────────────────────────────────────────────────────────────────────────
  329. NOTES:
  330.   [--] [--] means a SIB follows the ModR/M byte. disp8 denotes an 8-bit
  331.   displacement following the SIB byte, to be sign-extended and added to the
  332.   index. disp32 denotes a 32-bit displacement following the ModR/M byte, to
  333.   be added to the index.
  334. ───────────────────────────────────────────────────────────────────────────
  335.  
  336.  
  337. Table 17-4. 32-Bit Addressing Forms with the SIB Byte
  338.  
  339.  
  340.    r32                      EAX   ECX   EDX   EBX   ESP   [*]
  341. [*] means a disp32 with no base if MOD is 00, [ESP] otherwise. This provides
  342. the following addressing modes:
  343.       disp32[index]        (MOD=00)
  344.       disp8[EBP][index]    (MOD=01)
  345.       disp32[EBP][index]   (MOD=10)  ESI   EDI
  346.    Base =                   0     1     2     3     4     5     6     7
  347.    Base =                   000   001   010   011   100   101   110   111
  348.  
  349. ┌Scaled Index
  350. [*] means a disp32 with no base if MOD is 00, [ESP] otherwise. This provides
  351. the following addressing modes:
  352.       disp32[index]        (MOD=00)
  353.       disp8[EBP][index]    (MOD=01)
  354.       disp32[EBP][index]   (MOD=10)┐┌SS Index┐  ┌────────ModR/M Values in Hexadecimal────────┐
  355.  
  356. [EAX]                000    00    01    02    03    04    05    06    07
  357. [ECX]                001    08    09    0A    0B    0C    0D    0E    0F
  358. [EDX]                010    10    11    12    13    14    15    16    17
  359. [EBX]                011    18    19    1A    1B    1C    1D    1E    1F
  360. none             00  100    20    21    22    23    24    25    26    27
  361. [EBP]                101    28    29    2A    2B    2C    2D    2E    2F
  362. [ESI]                110    30    31    32    33    34    35    36    37
  363. [EDI]                111    38    39    3A    3B    3C    3D    3E    3F
  364.  
  365. [EAX*2]              000    40    41    42    43    44    45    46    47
  366. [ECX*2]              001    48    49    4A    4B    4C    4D    4E    4F
  367. [ECX*2]              010    50    51    52    53    54    55    56    57
  368. [EBX*2]              011    58    59    5A    5B    5C    5D    5E    5F
  369. none             01  100    60    61    62    63    64    65    66    67
  370. [EBP*2]              101    68    69    6A    6B    6C    6D    6E    6F
  371. [ESI*2]              110    70    71    72    73    74    75    76    77
  372. [EDI*2]              111    78    79    7A    7B    7C    7D    7E    7F
  373.  
  374. [EAX*4]              000    80    81    82    83    84    85    86    87
  375. [ECX*4]              001    88    89    8A    8B    8C    8D    8E    8F
  376. [EDX*4]              010    90    91    92    93    94    95    96    97
  377. [EBX*4]              011    98    89    9A    9B    9C    9D    9E    9F
  378. none             10  100    A0    A1    A2    A3    A4    A5    A6    A7
  379. [EBP*4]              101    A8    A9    AA    AB    AC    AD    AE    AF
  380. [ESI*4]              110    B0    B1    B2    B3    B4    B5    B6    B7
  381. [EDI*4]              111    B8    B9    BA    BB    BC    BD    BE    BF
  382.  
  383. [EAX*8]              000    C0    C1    C2    C3    C4    C5    C6    C7
  384. [ECX*8]              001    C8    C9    CA    CB    CC    CD    CE    CF
  385. [EDX*8]              010    D0    D1    D2    D3    D4    D5    D6    D7
  386. [EBX*8]              011    D8    D9    DA    DB    DC    DD    DE    DF
  387. none             11  100    E0    E1    E2    E3    E4    E5    E6    E7
  388. [EBP*8]              101    E8    E9    EA    EB    EC    ED    EE    EF
  389. [ESI*8]              110    F0    F1    F2    F3    F4    F5    F6    F7
  390. [EDI*8]              111    F8    F9    FA    FB    FC    FD    FE    FF
  391.  
  392.  
  393. ───────────────────────────────────────────────────────────────────────────
  394. NOTES:
  395.   [*] means a disp32 with no base if MOD is 00, [ESP] otherwise. This
  396.   provides the following addressing modes:
  397.       disp32[index]        (MOD=00)
  398.       disp8[EBP][index]    (MOD=01)
  399.       disp32[EBP][index]   (MOD=10)
  400. ───────────────────────────────────────────────────────────────────────────
  401.  
  402.  
  403. 17.2.2  How to Read the Instruction Set Pages
  404.  
  405. The following is an example of the format used for each 80386 instruction
  406. description in this chapter:
  407.  
  408. CMC ── Complement Carry Flag
  409.  
  410. Opcode   Instruction         Clocks      Description
  411.  
  412. F5        CMC                  2            Complement carry flag
  413.  
  414. The above table is followed by paragraphs labelled "Operation,"
  415. "Description," "Flags Affected," "Protected Mode Exceptions," "Real
  416. Address Mode Exceptions," and, optionally, "Notes." The following sections
  417. explain the notational conventions and abbreviations used in these
  418. paragraphs of the instruction descriptions.
  419.  
  420.  
  421. 17.2.2.1  Opcode
  422.  
  423. The "Opcode" column gives the complete object code produced for each form
  424. of the instruction. When possible, the codes are given as hexadecimal bytes,
  425. in the same order in which they appear in memory. Definitions of entries
  426. other than hexadecimal bytes are as follows:
  427.  
  428. /digit: (digit is between 0 and 7) indicates that the ModR/M byte of the
  429. instruction uses only the r/m (register or memory) operand. The reg field
  430. contains the digit that provides an extension to the instruction's opcode.
  431.  
  432. /r: indicates that the ModR/M byte of the instruction contains both a
  433. register operand and an r/m operand.
  434.  
  435. cb, cw, cd, cp: a 1-byte (cb), 2-byte (cw), 4-byte (cd) or 6-byte (cp)
  436. value following the opcode that is used to specify a code offset and
  437. possibly a new value for the code segment register.
  438.  
  439. ib, iw, id: a 1-byte (ib), 2-byte (iw), or 4-byte (id) immediate operand to
  440. the instruction that follows the opcode, ModR/M bytes or scale-indexing
  441. bytes. The opcode determines if the operand is a signed value. All words and
  442. doublewords are given with the low-order byte first.
  443.  
  444. +rb, +rw, +rd: a register code, from 0 through 7, added to the hexadecimal
  445. byte given at the left of the plus sign to form a single opcode byte. The
  446. codes are──
  447.  
  448.       rb         rw         rd
  449.     AL = 0     AX = 0     EAX = 0
  450.     CL = 1     CX = 1     ECX = 1
  451.     DL = 2     DX = 2     EDX = 2
  452.     BL = 3     BX = 3     EBX = 3
  453.     AH = 4     SP = 4     ESP = 4
  454.     CH = 5     BP = 5     EBP = 5
  455.     DH = 6     SI = 6     ESI = 6
  456.     BH = 7     DI = 7     EDI = 7
  457.  
  458.  
  459. 17.2.2.2  Instruction
  460.  
  461. The "Instruction" column gives the syntax of the instruction statement as
  462. it would appear in an ASM386 program. The following is a list of the symbols
  463. used to represent operands in the instruction statements:
  464.  
  465. rel8: a relative address in the range from 128 bytes before the end of the
  466. instruction to 127 bytes after the end of the instruction.
  467.  
  468. rel16, rel32: a relative address within the same code segment as the
  469. instruction assembled. rel16 applies to instructions with an operand-size
  470. attribute of 16 bits; rel32 applies to instructions with an operand-size
  471. attribute of 32 bits.
  472.  
  473. ptr16:16, ptr16:32: a FAR pointer, typically in a code segment different
  474. from that of the instruction. The notation 16:16 indicates that the value of
  475. the pointer has two parts. The value to the right of the colon is a 16-bit
  476. selector or value destined for the code segment register. The value to the
  477. left corresponds to the offset within the destination segment. ptr16:16 is
  478. used when the instruction's operand-size attribute is 16 bits; ptr16:32 is
  479. used with the 32-bit attribute.
  480.  
  481. r8: one of the byte registers AL, CL, DL, BL, AH, CH, DH, or BH.
  482.  
  483. r16: one of the word registers AX, CX, DX, BX, SP, BP, SI, or DI.
  484.  
  485. r32: one of the doubleword registers EAX, ECX, EDX, EBX, ESP, EBP, ESI, or
  486. EDI.
  487.  
  488. imm8: an immediate byte value. imm8 is a signed number between -128 and
  489. +127 inclusive. For instructions in which imm8 is combined with a word or
  490. doubleword operand, the immediate value is sign-extended to form a word or
  491. doubleword. The upper byte of the word is filled with the topmost bit of the
  492. immediate value.
  493.  
  494. imm16: an immediate word value used for instructions whose operand-size
  495. attribute is 16 bits. This is a number between -32768 and +32767 inclusive.
  496.  
  497. imm32: an immediate doubleword value used for instructions whose
  498. operand-size attribute is 32-bits. It allows the use of a number between
  499. +2147483647 and -2147483648.
  500.  
  501. r/m8: a one-byte operand that is either the contents of a byte register
  502. (AL, BL, CL, DL, AH, BH, CH, DH), or a byte from memory.
  503.  
  504. r/m16: a word register or memory operand used for instructions whose
  505. operand-size attribute is 16 bits. The word registers are: AX, BX, CX, DX,
  506. SP, BP, SI, DI. The contents of memory are found at the address provided by
  507. the effective address computation.
  508.  
  509. r/m32: a doubleword register or memory operand used for instructions whose
  510. operand-size attribute is 32-bits. The doubleword registers are: EAX, EBX,
  511. ECX, EDX, ESP, EBP, ESI, EDI. The contents of memory are found at the
  512. address provided by the effective address computation.
  513.  
  514. m8: a memory byte addressed by DS:SI or ES:DI (used only by string
  515. instructions).
  516.  
  517. m16: a memory word addressed by DS:SI or ES:DI (used only by string
  518. instructions).
  519.  
  520. m32: a memory doubleword addressed by DS:SI or ES:DI (used only by string
  521. instructions).
  522.  
  523. m16:16, M16:32: a memory operand containing a far pointer composed of two
  524. numbers. The number to the left of the colon corresponds to the pointer's
  525. segment selector. The number to the right corresponds to its offset.
  526.  
  527. m16 & 32, m16 & 16, m32 & 32: a memory operand consisting of data item pairs
  528. whose sizes are indicated on the left and the right side of the ampersand.
  529. All memory addressing modes are allowed. m16 & 16 and m32 & 32 operands are
  530. used by the BOUND instruction to provide an operand containing an upper and
  531. lower bounds for array indices. m16 & 32 is used by LIDT and LGDT to
  532. provide a word with which to load the limit field, and a doubleword with
  533. which to load the base field of the corresponding Global and Interrupt
  534. Descriptor Table Registers.
  535.  
  536. moffs8, moffs16, moffs32: (memory offset) a simple memory variable of type
  537. BYTE, WORD, or DWORD used by some variants of the MOV instruction. The
  538. actual address is given by a simple offset relative to the segment base. No
  539. ModR/M byte is used in the instruction. The number shown with moffs
  540. indicates its size, which is determined by the address-size attribute of the
  541. instruction.
  542.  
  543. Sreg: a segment register. The segment register bit assignments are ES=0,
  544. CS=1, SS=2, DS=3, FS=4, and GS=5.
  545.  
  546.  
  547. 17.2.2.3  Clocks
  548.  
  549. The "Clocks" column gives the number of clock cycles the instruction takes
  550. to execute. The clock count calculations makes the following assumptions:
  551.  
  552.   ■  The instruction has been prefetched and decoded and is ready for
  553.      execution.
  554.  
  555.   ■  Bus cycles do not require wait states.
  556.  
  557.   ■  There are no local bus HOLD requests delaying processor access to the
  558.      bus.
  559.  
  560.   ■  No exceptions are detected during instruction execution.
  561.  
  562.   ■  Memory operands are aligned.
  563.  
  564. Clock counts for instructions that have an r/m (register or memory) operand
  565. are separated by a slash. The count to the left is used for a register
  566. operand; the count to the right is used for a memory operand.
  567.  
  568. The following symbols are used in the clock count specifications:
  569.  
  570.   ■  n, which represents a number of repetitions.
  571.  
  572.   ■  m, which represents the number of components in the next instruction
  573.      executed, where the entire displacement (if any) counts as one
  574.      component, the entire immediate data (if any) counts as one component,
  575.      and every other byte of the instruction and prefix(es) each counts as
  576.      one component.
  577.  
  578.   ■  pm=, a clock count that applies when the instruction executes in
  579.      Protected Mode. pm= is not given when the clock counts are the same for
  580.      Protected and Real Address Modes.
  581.  
  582. When an exception occurs during the execution of an instruction and the
  583. exception handler is in another task, the instruction execution time is
  584. increased by the number of clocks to effect a task switch. This parameter
  585. depends on several factors:
  586.  
  587.   ■  The type of TSS used to represent the current task (386 TSS or 286
  588.      TSS).
  589.  
  590.   ■  The type of TSS used to represent the new task.
  591.  
  592.   ■  Whether the current task is in V86 mode.
  593.  
  594.   ■  Whether the new task is in V86 mode.
  595.  
  596. Table 17-5 summarizes the task switch times for exceptions.
  597.  
  598.  
  599. Table 17-5. Task Switch Times for Exceptions
  600.  
  601.                        New Task
  602.  
  603. Old              386 TSS     286 TSS
  604. Task             VM = 0
  605.  
  606. 386   VM = 0       309        282
  607. TSS
  608.  
  609. 386   VM = 1       314        231
  610. TSS
  611.  
  612. 286                307        282
  613. TSS
  614.  
  615.  
  616. 17.2.2.4  Description
  617.  
  618. The "Description" column following the "Clocks" column briefly explains the
  619. various forms of the instruction. The "Operation" and "Description" sections
  620. contain more details of the instruction's operation.
  621.  
  622.  
  623. 17.2.2.5  Operation
  624.  
  625. The "Operation" section contains an algorithmic description of the
  626. instruction which uses a notation similar to the Algol or Pascal language.
  627. The algorithms are composed of the following elements:
  628.  
  629. Comments are enclosed within the symbol pairs "(*" and "*)".
  630.  
  631. Compound statements are enclosed between the keywords of the "if" statement
  632. (IF, THEN, ELSE, FI) or of the "do" statement (DO, OD), or of the "case"
  633. statement (CASE ... OF, ESAC).
  634.  
  635. A register name implies the contents of the register. A register name
  636. enclosed in brackets implies the contents of the location whose address is
  637. contained in that register. For example, ES:[DI] indicates the contents of
  638. the location whose ES segment relative address is in register DI. [SI]
  639. indicates the contents of the address contained in register SI relative to
  640. SI's default segment (DS) or overridden segment.
  641.  
  642. Brackets also used for memory operands, where they mean that the contents
  643. of the memory location is a segment-relative offset. For example, [SRC]
  644. indicates that the contents of the source operand is a segment-relative
  645. offset.
  646.  
  647. A  B; indicates that the value of B is assigned to A.
  648.  
  649. The symbols =, <>, ≥, and ≤ are relational operators used to compare two
  650. values, meaning equal, not equal, greater or equal, less or equal,
  651. respectively. A relational expression such as A = B is TRUE if the value of
  652. A is equal to B; otherwise it is FALSE.
  653.  
  654. The following identifiers are used in the algorithmic descriptions:
  655.  
  656.   ■  OperandSize represents the operand-size attribute of the instruction,
  657.      which is either 16 or 32 bits. AddressSize represents the address-size
  658.      attribute, which is either 16 or 32 bits. For example,
  659.  
  660.    IF instruction = CMPSW
  661.    THEN OperandSize  16;
  662.    ELSE
  663.       IF instruction = CMPSD
  664.       THEN OperandSize  32;
  665.       FI;
  666.    FI;
  667.  
  668. indicates that the operand-size attribute depends on the form of the CMPS
  669. instruction used. Refer to the explanation of address-size and operand-size
  670. attributes at the beginning of this chapter for general guidelines on how
  671. these attributes are determined.
  672.  
  673.   ■  StackAddrSize represents the stack address-size attribute associated
  674.      with the instruction, which has a value of 16 or 32 bits, as explained
  675.      earlier in the chapter.
  676.  
  677.   ■  SRC represents the source operand. When there are two operands, SRC is
  678.      the one on the right.
  679.  
  680.   ■  DEST represents the destination operand. When there are two operands,
  681.      DEST is the one on the left.
  682.  
  683.   ■  LeftSRC, RightSRC distinguishes between two operands when both are
  684.      source operands.
  685.  
  686.   ■  eSP represents either the SP register or the ESP register depending on
  687.      the setting of the B-bit for the current stack segment.
  688.  
  689. The following functions are used in the algorithmic descriptions:
  690.  
  691.   ■  Truncate to 16 bits(value) reduces the size of the value to fit in 16
  692.      bits by discarding the uppermost bits as needed.
  693.  
  694.   ■  Addr(operand) returns the effective address of the operand (the result
  695.      of the effective address calculation prior to adding the segment base).
  696.  
  697.   ■  ZeroExtend(value) returns a value zero-extended to the operand-size
  698.      attribute of the instruction. For example, if OperandSize = 32,
  699.      ZeroExtend of a byte value of -10 converts the byte from F6H to
  700.      doubleword with hexadecimal value 000000F6H. If the value passed to
  701.      ZeroExtend and the operand-size attribute are the same size,
  702.      ZeroExtend returns the value unaltered.
  703.  
  704.   ■  SignExtend(value) returns a value sign-extended to the operand-size
  705.      attribute of the instruction. For example, if OperandSize = 32,
  706.      SignExtend of a byte containing the value -10 converts the byte from
  707.      F6H to a doubleword with hexadecimal value FFFFFFF6H. If the value
  708.      passed to SignExtend and the operand-size attribute are the same size,
  709.      SignExtend returns the value unaltered.
  710.  
  711.   ■  Push(value) pushes a value onto the stack. The number of bytes pushed
  712.      is determined by the operand-size attribute of the instruction. The
  713.      action of Push is as follows:
  714.  
  715.    IF StackAddrSize = 16
  716.    THEN
  717.       IF OperandSize = 16
  718.       THEN
  719.          SP  SP - 2;
  720.          SS:[SP]  value; (* 2 bytes assigned starting at
  721.                              byte address in SP *)
  722.       ELSE (* OperandSize = 32 *)
  723.          SP  SP - 4;
  724.          SS:[SP]  value; (* 4 bytes assigned starting at
  725.                              byte address in SP *)
  726.       FI;
  727.    ELSE (* StackAddrSize = 32 *)
  728.       IF OperandSize = 16
  729.       THEN
  730.          ESP  ESP - 2;
  731.          SS:[ESP]  value; (* 2 bytes assigned starting at
  732.                               byte address in ESP*)
  733.       ELSE (* OperandSize = 32 *)
  734.          ESP  ESP - 4;
  735.          SS:[ESP]  value; (* 4 bytes assigned starting at
  736.                               byte address in ESP*)
  737.       FI;
  738.    FI;
  739.  
  740.   ■  Pop(value) removes the value from the top of the stack and returns it.
  741.      The statement EAX  Pop( ); assigns to EAX the 32-bit value that Pop
  742.      took from the top of the stack. Pop will return either a word or a
  743.      doubleword depending on the operand-size attribute. The action of Pop
  744.      is as follows:
  745.  
  746.    IF StackAddrSize = 16
  747.    THEN
  748.       IF OperandSize = 16
  749.       THEN
  750.          ret val  SS:[SP]; (* 2-byte value *)
  751.          SP  SP + 2;
  752.       ELSE (* OperandSize = 32 *)
  753.          ret val  SS:[SP]; (* 4-byte value *)
  754.          SP  SP + 4;
  755.       FI;
  756.    ELSE (* StackAddrSize = 32 *)
  757.       IF OperandSize = 16
  758.       THEN
  759.          ret val  SS:[ESP]; (* 2 bytes value *)
  760.          ESP  ESP + 2;
  761.       ELSE (* OperandSize = 32 *)
  762.          ret val  SS:[ESP]; (* 4 bytes value *)
  763.          ESP  ESP + 4;
  764.       FI;
  765.    FI;
  766.    RETURN(ret val); (*returns a word or doubleword*)
  767.  
  768.   ■  Bit[BitBase, BitOffset] returns the address of a bit within a bit
  769.      string, which is a sequence of bits in memory or a register. Bits are
  770.      numbered from low-order to high-order within registers and within
  771.      memory bytes. In memory, the two bytes of a word are stored with the
  772.      low-order byte at the lower address.
  773.  
  774.    If the base operand is a register, the offset can be in the range 0..31.
  775.    This offset addresses a bit within the indicated register. An example,
  776.    "BIT[EAX, 21]," is illustrated in Figure 17-3.
  777.  
  778.    If BitBase is a memory address, BitOffset can range from -2 gigabits to 2
  779.    gigabits. The addressed bit is numbered (Offset MOD 8) within the byte at
  780.    address (BitBase + (BitOffset DIV 8)), where DIV is signed division with
  781.    rounding towards negative infinity, and MOD returns a positive number.
  782.    This is illustrated in Figure 17-4.
  783.  
  784.   ■  I-O-Permission(I-O-Address, width) returns TRUE or FALSE depending on
  785.    the I/O permission bitmap and other factors. This function is defined as
  786.    follows:
  787.  
  788.    IF TSS type is 286 THEN RETURN FALSE; FI;
  789.    Ptr  [TSS + 66]; (* fetch bitmap pointer *)
  790.    BitStringAddr  SHR (I-O-Address, 3) + Ptr;
  791.    MaskShift  I-O-Address AND 7;
  792.    CASE width OF:
  793.          BYTE: nBitMask  1;
  794.          WORD: nBitMask  3;
  795.          DWORD: nBitMask  15;
  796.    ESAC;
  797.    mask  SHL (nBitMask, MaskShift);
  798.    CheckString  [BitStringAddr] AND mask;
  799.    IF CheckString = 0
  800.    THEN RETURN (TRUE);
  801.    ELSE RETURN (FALSE);
  802.    FI;
  803.  
  804.   ■  Switch-Tasks is the task switching function described in Chapter 7.
  805.  
  806.  
  807. 17.2.2.6  Description
  808.  
  809. The "Description" section contains further explanation of the instruction's
  810. operation.
  811.  
  812.  
  813. Figure 17-3.  Bit Offset for BIT[EAX, 21]
  814.  
  815.    31                    21                                               0
  816.   ╔═════════════════════╦═╦═══════════════════════════════════════════════╗
  817.   ║                     ║ ║                                               ║
  818.   ╚═════════════════════╩═╩═══════════════════════════════════════════════╝
  819.                                                                          
  820.                          └────────────────────BITOFFSET = 21──────────────┘
  821.  
  822.  
  823. Figure 17-4.  Memory Bit Indexing
  824.  
  825.                          BIT INDEXING (POSITIVE OFFSET)
  826.  
  827.                7 6 5 4 3 2 1 0 7 6 5 4 3 2 1 0 7 6 5 4 3 2 1 0
  828.              ╔════╤═╤═════════╤═══════════════╤════════════════╗
  829.              ║    │ │         │               │                ║
  830.              ╚════╧═╧═════════╧═══════════════╪════════════════╝
  831.              │  BITBASE + 1   │    BITBASE    │  BITBASE - 1   │
  832.                                              │
  833.                    └────────OFFSET = 13───────┘
  834.  
  835.                          BIT INDEXING (NEGATIVE OFFSET)
  836.  
  837.                7 6 5 4 3 2 1 0 7 6 5 4 3 2 1 0 7 6 5 4 3 2 1 0
  838.              ╔════════════════╤═══════════════╤═══╤═╤══════════╗
  839.              ║                │               │   │ │          ║
  840.              ╚════════════════╪═══════════════╧═══╧═╧══════════╝
  841.              │    BITBASE     │  BITBASE - 1  │  BITBASE - 2   │
  842.                               │                    
  843.                               └─────OFFSET = -11───┘
  844.  
  845.  
  846. 17.2.2.7  Flags Affected
  847.  
  848. The "Flags Affected" section lists the flags that are affected by the
  849. instruction, as follows:
  850.  
  851.   ■  If a flag is always cleared or always set by the instruction, the
  852.      value is given (0 or 1) after the flag name. Arithmetic and logical
  853.      instructions usually assign values to the status flags in the uniform
  854.      manner described in Appendix C. Nonconventional assignments are
  855.      described in the "Operation" section.
  856.  
  857.   ■  The values of flags listed as "undefined" may be changed by the
  858.      instruction in an indeterminate manner.
  859.  
  860. All flags not listed are unchanged by the instruction.
  861.  
  862.  
  863. 17.2.2.8  Protected Mode Exceptions
  864.  
  865. This section lists the exceptions that can occur when the instruction is
  866. executed in 80386 Protected Mode. The exception names are a pound sign (#)
  867. followed by two letters and an optional error code in parentheses. For
  868. example, #GP(0) denotes a general protection exception with an error code of
  869. 0. Table 17-6 associates each two-letter name with the corresponding
  870. interrupt number.
  871.  
  872. Chapter 9 describes the exceptions and the 80386 state upon entry to the
  873. exception.
  874.  
  875. Application programmers should consult the documentation provided with
  876. their operating systems to determine the actions taken when exceptions
  877. occur.
  878.  
  879.  
  880. Table 17-6. 80386 Exceptions
  881.  
  882. Mnemonic     Interrupt    Description
  883.  
  884. #UD           6           Invalid opcode
  885. #NM           7           Coprocessor not available
  886. #DF           8           Double fault
  887. #TS          10           Invalid TSS
  888. #NP          11           Segment or gate not present
  889. #SS          12           Stack fault
  890. #GP          13           General protection fault
  891. #PF          14           Page fault
  892. #MF          16           Math (coprocessor) fault
  893.  
  894.  
  895. 17.2.2.9  Real Address Mode Exceptions
  896.  
  897. Because less error checking is performed by the 80386 in Real Address Mode,
  898. this mode has fewer exception conditions. Refer to Chapter 14 for further
  899. information on these exceptions.
  900.  
  901.  
  902. 17.2.2.10  Virtual-8086 Mode Exceptions
  903.  
  904. Virtual 8086 tasks provide the ability to simulate Virtual 8086 machines.
  905. Virtual 8086 Mode exceptions are similar to those for the 8086 processor,
  906. but there are some differences. Refer to Chapter 15 for details.
  907.