Presentation is loading. Please wait.

Presentation is loading. Please wait.

CIS 020 Assembly Programming Chapter 08 - Advanced Decimal Arithmetic Instructions © John Urrutia 2012, All Rights Reserved.5/27/20121.

Similar presentations


Presentation on theme: "CIS 020 Assembly Programming Chapter 08 - Advanced Decimal Arithmetic Instructions © John Urrutia 2012, All Rights Reserved.5/27/20121."— Presentation transcript:

1 CIS 020 Assembly Programming Chapter 08 - Advanced Decimal Arithmetic Instructions © John Urrutia 2012, All Rights Reserved.5/27/20121

2 Objectives How to format and use the following decimal instructions: Zero and Add Pack – ZAP Multiply Packed – MP Divide Packed – DP Compare Packed – CP © John Urrutia 2012, All Rights Reserved.25/27/2012

3 ZAP – Zero and Add Packed Two step process 1 st initializes the receiving operand to packed zeros 2 nd add the sending operand to the receiving operand Syntax of Instruction Op Code – ZAP Operand 1 – label or address, will contain the value of 2 nd operand after execution. Operand 2 – label or address, must be a packed-decimal format value. Value is added right to left to operand 1 and padded, if necessary, with zeros on the left. © John Urrutia 2012, All Rights Reserved.35/27/2012

4 ZAP – Zero and Add Packed © John Urrutia 2012, All Rights Reserved.45/27/2012

5 ZAP – Zero and Add Packed © John Urrutia 2012, All Rights Reserved.55/27/2012

6 ZAP – Zero and Add Packed Most Decimal instructions set the Condition Code (reprised) ZAP – set the Condition Code 0 – 2 nd Operand value is zero 1 – 2 nd Operand value is negative 2 – 2 nd Operand value is positive 3 – 2 nd Operand length is > 1 st Operand (Overflow) Branching instructions BZ – on Zero, BM – on Negative, BP – on Positive, BO – on Overflow © John Urrutia 2012, All Rights Reserved.65/27/2012

7 MP – Multiply Packed Syntax of Instruction Op Code – MP Operand 1 – multiplicand (before execution) and product (after execution) Operand 2 – multiplier Both Operands must be in packed-decimal format Operand 1 should be twice larger than the size of Operand 2 to absolutely prevent overflow conditions. All packed-decimal instructions set the sign to X’C’ – Positive or X’D’ – Negative © John Urrutia 2012, All Rights Reserved.75/27/2012

8 MP – Multiply Packed Calculating decimal field size Maximum number of digits in the multiplicand + Maximum number of digits in the multiplier = Maximum number of digits in the product The receiving field (Operand 1) in bytes must be = the whole number in (Max product digits + 2) / 2 See chart next slide © John Urrutia 2012, All Rights Reserved.85/27/2012

9 MP – Multiply Packed © John Urrutia 2012, All Rights Reserved.95/27/2012 Multiplicand Multiplier 12345678 1 22.5 33.5 44.5 55.5 2 2.5 33.5 44.5 55.5 6 3 33.5 44.5 55.5 66.5 4 3.5 44.5 55.5 66.5 7 5 4455.5 66.5 77.5 6 4.5 55.5 66.5 77.5 8 7 55.5 66.5 77.5 8 8 5.5 66.5 77.5 8 Bytes

10 MP – Multiply Packed FLD1 – 2 digits © John Urrutia 2012, All Rights Reserved.105/27/2012 FLD2 – 3 digits

11 MP – Multiply Packed FLD1 – 2 digits © John Urrutia 2012, All Rights Reserved.115/27/2012 FLD2 – 2 digits

12 MP – Multiply Packed Example © John Urrutia 2012, All Rights Reserved.125/27/2012

13 DP – Divide Packed Syntax of Instruction Op Code – DP Operand 1 – dividend (before execution) and quotient & remainder (after execution) Operand 2 – divisor Both Operands must be in packed-decimal format Operand 1 length (quotient) should be equal to Divisor digits converted to packed bytes plus Dividend digits converted to packed bytes All packed-decimal instructions set the sign to X’C’ – Positive or X’D’ – Negative © John Urrutia 2012, All Rights Reserved.135/27/2012

14 DP – Divide Packed The Dividend (before execution) is stored in Operand 1 Dividend is 5 bytes – The Quotient & Remainder (after execution) is stored in Operand 1 Quotient is 3 bytes – Remainder is 2 bytes – Operand 1 must be 5 bytes – The Remainder is the same size as the Divisor © John Urrutia 2012, All Rights Reserved.145/27/2012 99999C 000C 99999C000C 009999900C

15 DP – Divide Packed Example © John Urrutia 2012, All Rights Reserved.155/27/2012

16 CP – Compare Packed Syntax of Instruction Op Code – CP Operand 1 – label or address Operand 2 – label or address Both Operands must be in packed-decimal format Operands are not changed Condition code is set to Operands are equal– BE 1 st operand is low– BL 1 st operand is high– BH © John Urrutia 2012, All Rights Reserved.165/27/2012

17 CP – Compare Packed Rules Comparison is algebraic & both operands are unchanged The sign of the second operand is changed The operands are added If the result is zero the operands are equal CC=0 If the result is negative operand 1 is low CC=1 If the result is positive operand 1 is high CC=2 Operands of unequal size are padded with zeros © John Urrutia 2012, All Rights Reserved.175/27/2012

18 CP – Compare Packed Example © John Urrutia 2012, All Rights Reserved.185/27/2012

19 Exercise Using the ADVDECSH shell write a program that will do a binary search for a number you pick between 1 and 32 inclusive. © John Urrutia 2012, All Rights Reserved.195/27/2012


Download ppt "CIS 020 Assembly Programming Chapter 08 - Advanced Decimal Arithmetic Instructions © John Urrutia 2012, All Rights Reserved.5/27/20121."

Similar presentations


Ads by Google