* remove "\r" nonsense
[mascara-docs.git] / i386 / i386.reference / BOUND.htm
blob95ae6b192998970b54fa806db2ea563b50812bb6
1 <!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML 2.0//EN">
2 <HTML>
3 <HEAD>
4 <TITLE>80386 Programmer's Reference Manual -- Opcode BOUND</TITLE>
5 </HEAD>
6 <BODY>
7 <B>up:</B> <A HREF="c17.htm">
8 Chapter 17 -- 80386 Instruction Set</A><BR>
9 <B>prev:</B><A HREF="ARPL.htm"> ARPL Adjust RPL Field of Selector</A><BR>
10 <B>next:</B><A HREF="BSF.htm"> BSF Bit Scan Forward</A>
11 <P>
12 <HR>
13 <P>
14 <H1>BOUND -- Check Array Index Against Bounds</H1>
16 <PRE>
17 Opcode Instruction Clocks Description
19 62 /r BOUND r16,m16&16 10 Check if r16 is within bounds
20 (passes test)
21 62 /r BOUND r32,m32&32 10 Check if r32 is within bounds
22 (passes test)
23 </PRE>
25 <H2>Operation</H2>
27 <PRE>
28 IF (LeftSRC < [RightSRC] OR LeftSRC > [RightSRC + OperandSize/8])
29 (* Under lower bound or over upper bound *)
30 THEN Interrupt 5;
31 FI;
32 </PRE>
34 <H2>Description</H2>
36 BOUND ensures that a signed array index is within the limits specified by a
37 block of memory consisting of an upper and a lower bound. Each bound uses
38 one word for an operand-size attribute of 16 bits and a doubleword for an
39 operand-size attribute of 32 bits. The first operand (a register) must be
40 greater than or equal to the first bound in memory (lower bound), and less
41 than or equal to the second bound in memory (upper bound). If the register
42 is not within bounds, an Interrupt 5 occurs; the return EIP points to the
43 BOUND instruction.
44 <P>
45 The bounds limit data structure is usually placed just before the array
46 itself, making the limits addressable via a constant offset from the
47 beginning of the array.
49 <H2>Flags Affected</H2>
51 None
53 <H2>Protected Mode Exceptions</H2>
55 Interrupt 5 if the bounds test fails, as described above; #GP(0) for an
56 illegal memory operand effective address in the CS, DS, ES, FS, or GS
57 segments; #SS(0) for an illegal address in the SS segment; #PF(fault-code)
58 for a page fault
59 <P>
60 The second operand must be a memory operand, not a register. If BOUND is
61 executed with a ModRM byte representing a register as the second operand,
62 #UD occurs.
64 <H2>Real Address Mode Exceptions</H2>
66 Interrupt 5 if the bounds test fails; Interrupt 13 if any part of the
67 operand would lie outside of the effective address space from 0 to 0FFFFH;
68 Interrupt 6 if the second operand is a register
70 <H2>Virtual 8086 Mode Exceptions</H2>
72 Same exceptions as in Real Address Mode; #PF(fault-code) for a page fault
75 <P>
76 <HR>
77 <P>
78 <B>up:</B> <A HREF="c17.htm">
79 Chapter 17 -- 80386 Instruction Set</A><BR>
80 <B>prev:</B><A HREF="ARPL.htm"> ARPL Adjust RPL Field of Selector</A><BR>
81 <B>next:</B><A HREF="BSF.htm"> BSF Bit Scan Forward</A>
82 </BODY>