200 likes | 349 Views
Math Instructions. ADD, SUB, MUL, DIV,CLR, SQR. Arithmetic Status Bits:. The arithmetic status bits are found in word 0, bits 0-3, in the controller status file. After each math instruction is executed, the arithmetic status bits are updated as outlined in the following table:.
E N D
Math Instructions ADD, SUB, MUL, DIV,CLR, SQR
Arithmetic Status Bits: • The arithmetic status bits are found in word 0, bits 0-3, in the controller status file. After each math instruction is executed, the arithmetic status bits are updated as outlined in the following table:
Important: If the overflow bit S:0/1 is set by any math operation, the S:5/0 overflow trap bit is then set. If this bit remains set upon execution of an END, temporary end (TND) or refresh (REF) instruction, a recoverable major error code is declared. • Program an OUT with address S:5/0 between the overflow point and END, TND, or REF statement to avoid a major error.
Math Register S:13 and S:14 • Changes to the math register after the following operations occur as noted below:
Add (ADD):Use the ADD instruction to add on value (source A) to another value (source B) and place the result in the destination.
Subtract (SUB):Use the SUB instruction to subtract one value (source B) from another (source A) and place the result in the destination.
32-Bit Addition and Subtraction: • You have the option of performing 16-bit or 32-bit signed integer addition and subtraction. This is facilitated by status file bit S:2/14 (math over flow selection bit).
Multiply (MUL):Use the MUL instruction to multiply one value (source A) by another (source B) and place the result in the destination.
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. • 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 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
Clear (CLR) • Use the CLR instruction to set the destination value of a word to zero. Clear (CLR)
Clear (CLR) • Use the CLR instruction to set the destination value of a word to zero.
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.
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.