Pré-visualização | Página 32 de 50
counter to find the average value of B3:1. PrefaceInstruction Set Reference Manual 3–10 Multiply (MUL) Use the MUL instruction to multiply one value (source A) by another (source B) and place the result in the destination. Updates to Arithmetic Status Bits With this Bit: The Processor: Carry (C) always resets. Overflow (V) sets if overflow is detected at destination; otherwise resets. On overflow, the minor error flag is also set. The value –32,768 or 32,767 is placed in the destination. Exception: If you are using an SLC 5/02 or higher processor or a MicroLogix 1000 controller and have S:2/14 (math overflow selection bit) set, then the unsigned, truncated overflow remains in the destination. For floating point destinations, the overflow result remains in the destination. Zero (Z) sets if result is zero; otherwise resets. Sign (S) sets if result is negative; otherwise resets. Changes to the Math Register, S:13 and S:14 Integer – Contains the 32-bit signed integer result of the multiply operation. This result is valid at overflow. Floating Point – The math register does not change. 3333 333 MUL MULTIPLY Source A Source B Dest Output Instruction Math Instructions 3–11 Divide (DIV) Use the DIV instruction to divide one value (source A) by another (source B). The rounded quotient is then placed in the destination. If the remainder is 0.5 or greater, round up occurs in the destination. The unrounded quotient is stored in the most significant word of the math register. The remainder is placed in the least significant word of the math register. Updates to Arithmetic Status Bits With this Bit: The Processor: Carry (C) always resets. Overflow (V) sets if division by zero or overflow is detected; otherwise resets. On overflow, the minor error flag is also set. The value 32,767 is placed in the destination. Exception: If you are using an SLC1 5/02 or higher processor or a MicroLogix 1000 controller and have S:2/14 (math overflow selection bit) set, then the unsigned, truncated overflow remains in the destination. For floating point destinations, the overflow result remains in the destination. Zero (Z) sets if result is zero; otherwise resets; undefined if overflow is set. Sign (S) sets if result is negative; otherwise resets; undefined if overflow is set. Changes to the Math Register, S:13 and S:14 Integer – The unrounded quotient is placed in the most significant word, the remainder is placed in the least significant word. Floating Point – The math register does not change. Example The remainder of 11/2 is 0.5, so the quotient is rounded up to 6 and is stored in the destination. The unrounded quotient, which is 5, is stored in S:14 and the remainder, which is 1, is stored at S:13. 3333 333 DIV DIVIDE Source A Source B Dest Output Instruction DIV DIVIDE Source A N7:0 11 Source B N7:1 2 Dest N7:2 6 where: N7:0 = 11 N7:1 = 2 N7:2 = 6 result: S:14 = 5 S:13 = 1 PrefaceInstruction Set Reference Manual 3–12 Double Divide (DDV) The 32-bit content of the math register is divided by the 16-bit source value and the rounded quotient is placed in the destination. If the remainder is 0.5 or greater, the destination is rounded up. This instruction typically follows a MUL instruction that creates a 32-bit result. Updates to Arithmetic Status Bits With this Bit: The Processor: Carry (C) always resets. Overflow (V) sets if division by zero or if result is greater than 32,767 or less than –32,768; otherwise resets. On overflow, the minor error flag is also set. The value 32,767 is placed in the destination. Zero (Z) sets if result is zero; otherwise resets. Sign (S) sets if result is negative; otherwise resets; undefined if overflow is set. Changes to the Math Register, S:13 and S:14 Initially contains the dividend of the DDV operation. Upon instruction execution, the unrounded quotient is placed in the most significant word of the math register. The remainder is placed in the least significant word of the math register. 3333 333 DDV DOUBLE DIVIDE Source Dest Output Instruction Math Instructions 3–13 Clear (CLR) Use the CLR instruction to set the destination value of a word to zero. Updates to Arithmetic Status Bits With this Bit: The Processor: Carry (C) always resets. Overflow (V) always resets. Zero (Z) always sets. Sign (S) always resets. Square Root (SQR) When this instruction is evaluated as true, the square root of the absolute value of the source is calculated and the rounded result is placed in the destination. The instruction calculates the square root of a negative number without overflow or faults. In applications where the source value may be negative, use a comparison instruction to evaluate the source value to determine if the destination may be invalid. Updates to Arithmetic Status Bits With this Bit: The Processor: Carry (C) is reserved (integer). For floating point, it is always cleared. Overflow (V) always resets. Zero (Z) sets when destination value is zero. Sign (S) always resets. 3333 333 CLR CLEAR Dest Output Instruction 33 333 SQR SQUARE ROOT Source Dest Output Instruction PrefaceInstruction Set Reference Manual 3–14 Scale with Parameters (SCP) Use the SCP instruction to produce a scaled output value that has a linear relationship between the input and scaled values. This instruction supports integer and floating point values. Use this instruction with SLC 5/03 (OS302), SLC 5/04 (OS401), and SLC 5/05 processors. Use the following formula to convert analog input data to engineering units: y = mx + b Where: y = scaled output m = slope (scaled max. – scaled min.) / (input max. – input min.) x = input value b = offset (y intercept) = scaled min – (input min. � slope) Note The Input Minimum, Input Maximum, Scaled Minimum, and Scaled Maximum are used to determine the slope and offset values. The input value can go outside of the specified input limits and no ordering is required. For example, the scaled output value is not necessarily clamped between the scaled minimum and scaled maximum values. Entering Parameters Enter the following parameters when programming this instruction: • Input value can be a word address or an address of floating point data elements. • Input Minimum and Input Maximum values determine the range of data that appears in the Input Value parameter. The value can be a word address, an integer constant, floating point data element, or a floating point constant. • Scaled Minimum and Scaled Maximum values determine the range of data that appears in the Scaled Output parameter. The value can be a word address, an integer constant, floating point data element, or a floating point constant. • Scaled Output value can be a word address or an address of floating point data elements. 333 SCP SCALE W/PARAMETERS Input Input Min. Input Max. Scaled Min. Scaled Max. Scaled Output Output Instruction Math Instructions 3–15 Updates to Arithmetic Status Bits With this Bit: The Processor: Carry (C) always resets. Overflow (V) sets if overflow generated or an unsupported input is detected; otherwise resets. Zero (Z) sets when destination value is zero; otherwise resets. Sign (S) sets if the destination value is negative; otherwise resets. Application Examples Example 1 In the first example, an analog I/O combination module (1746–NIO4I) is in slot 1 of the chassis.