1 / 42

Packed Decimal Manipulation, Part 2

2. ED (Edit) Instruction. Used to convert one or more packed decimal numbers into a format for printing.Can do formatting at the same time: suppress leading zeros, insert punctuation, append a minus sign, insert text.Works better than UNPK and doesn't need OI (which you haven't yet learned).. 3.

gaerwn
Download Presentation

Packed Decimal Manipulation, Part 2

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


    1. 1 Packed Decimal Manipulation, Part 2 ED, EDMK (Chapter 7.7 - 7.8) CVD, CVB (Chapter 7.6)

    2. 2 ED (Edit) Instruction Used to convert one or more packed decimal numbers into a format for printing. Can do formatting at the same time: suppress leading zeros, insert punctuation, append a minus sign, insert text. Works better than UNPK and doesn't need OI (which you haven't yet learned).

    3. 3 ED (Edit) Instruction As you might guess, if it does so much, the instruction is rather complex. Format: label ED D1(L,B1),D2(B2)

    4. 4 ED (Edit) Instruction The first operand receives the result. It is the pattern: the characters placed in the pattern before the ED determine the placement of the digits and any editing.

    5. 5 ED (Edit) Instruction Editing characters in the pattern: 20 (actually, X'20') is a digit selector – it is replaced by one digit from the packed decimal number. 21 is a significance starter – it shows when to start printing leading zeros (if at all). Doubles as a digit selector as well.

    6. 6 ED (Edit) Instruction 22 is a field separator – separates two fields if editing more than one field at a time. Any other hex digit is a message character (i.e., would be put into the print line as shown). Examples: decimal point (4B), / (61), $ (5B). First character in the pattern is the fill character It replaces leading zeros. At least one fill character will always print because it is never replaced by a digit (it isn't a digit selector).

    7. 7 ED (Edit) Instruction L – length. Always determined by first operand (the pattern), whether the length is specified or omitted (uses default). ED always works left to right, character by character. It grabs the leftmost digit from the source and puts it in the leftmost byte of the pattern, then continues to move, byte by byte, to the right. Digits must match precisely -- no automatic padding.

    8. 8 ED (Edit) Instruction Progressively more complicated examples seem to be the best way to illustrate how this works...

    9. 9 ED (Edit) Instruction ED NUM1(4),NUM2 NUM1 (pattern) NUM2 (source) before 40 20 20 20 12 3C (123) after 40 F1 F2 F3 unchanged

    10. 10 ED (Edit) Instruction Remember, the fill character will always print, even if it means truncating digits. Bad example follows...

    11. 11 ED (Edit) Instruction ED NUM1(4),NUM2 NUM1 (pattern) NUM2 (source) before 40 20 20 12 3C (123) after 40 F1 F2 unchanged

    12. 12 ED (Edit) Instruction You must have just as many digit selectors (20 and 21) as you have digits (for last example, three digits). Be careful: you must have just as many digit selectors as you have digits. There will always be an odd number of digits in a packed decimal number, so there will always be an odd number of digit selectors in the pattern.

    13. 13 ED (Edit) Instruction Code for this last example: MVC NUM1(4),=X'40202020' ED NUM1(4),NUM2 ———————— OR ———————— ED NUM1(4),NUM2 ... NUM1 DC X'40202020' DS .....

    14. 14 ED (Edit) Instruction Second example works only once – pattern is wiped out by the move, so it won’t work for any other numbers later in the program.

    15. 15 ED (Edit) Instruction With this pattern just examined, only blanks will print if the source number is zero: NUM1 NUM2 before 40 20 20 20 00 0C after 40 40 40 40 unchanged

    16. 16 ED (Edit) Instruction So, use a significance starter (X‘21’) to tell ED when to start printing zeros. The first zero prints in the position after the significance starter. That is, the significance starter turns on the significance indicator and zeros start printing in the next position. The significance starter also functions as a digit selector.

    17. 17 ED (Edit) Instruction ED NUM1(4),NUM2 NUM1 NUM2 before 40 20 21 20 00 0C after 40 40 40 F0 unchanged

    18. 18 ED (Edit) Instruction In a packed decimal number, the decimal point is not stored – you have to keep track of it. Put a X‘4B’ (period) in that position in the pattern and the decimal will print.

    19. 19 ED (Edit) Instruction ED NUM1(5),NUM2 NUM1 NUM2 before 40 21 4B 20 20 12 3C (1.23) after 40 F1 4B F2 F3 unchanged

    20. 20 ED (Edit) Instruction Message characters like decimal (4B), / (61), $ (5B) are replaced by the fill character until the significance indicator is turned on, which happens when: The significance starter is encountered, or A non-zero digit is encountered in the source number.

    21. 21 ED (Edit) Instruction The significance indicator must be turned on before the decimal character is encountered or the decimal character will be replaced by the fill character.

    22. 22 ED (Edit) Instruction You can use one long field pattern with field separators (X‘22’) to edit multiple numbers all at once. When you feel up to it, read example 8, page 174.

    23. 23 ED (Edit) Instruction When a positive sign digit is encountered in the last byte of the source number, the significance indicator is turned off. However, when a negative sign digit is encountered, the significance indicator stays on.

    24. 24 ED (Edit) Instruction So, just as message characters can be used within a pattern, you can use them at the end of the pattern for negative numbers only. Negative numbers can be represented on the print line in two ways: 123 – (X‘60’) 123 CR (X‘C3D9’)

    25. 25 ED (Edit) Instruction ED NUM1(5),NUM2 NUM1 NUM2 before 40 20 21 20 60 12 3D (-123) after 40 F1 F2 F3 60 unchanged

    26. 26 ED (Edit) Instruction ED NUM1(7),NUM2 NUM1 NUM2 before 40 20 21 20 40 C3 D9 12 3D (-123) after 40 F1 F2 F3 40 C3 D9 unchanged

    27. 27 ED (Edit) Instruction ED NUM1(7),NUM2 NUM1 NUM2 before 40 20 21 20 40 C3 D9 12 3C (+123) after 40 F1 F2 F3 40 40 40 unchanged

    28. 28 ED (Edit) Instruction Again, the number of digit selectors (20 and 21, each a byte long) must match the number of single digits in the packed decimal source number. Again, the digits are moved left to right, one by one. If you don’t match the digits and digits selectors properly, the number will be incorrect. This does not intelligently truncate or pad the way COBOL does.

    29. 29 EDMK Instruction Edit and Mark: Does everything the ED does, plus points R1 to the first non-zero digit that actually turns the significance indicator on. R1 can then be used to insert a $ one position to the left of the first digit. If the significance starter (rather than a non-zero number) turns the significance indicator on, R1 is unchanged.

    30. 30 EDMK Instruction Format: label EDMK D1(L,B1),D2(B2) The operands work the same as for an ED instruction.

    31. 31 EDMK Instruction ED NUM1(7),NUM2 NUM1 NUM2 before 40 20 20 21 4B 20 20 01 23 4C (1234) after 40 40 F1 F2 4B F3 F4 unchanged

    32. 32 EDMK Instruction Using EDMK to insert a $ just in front of the first digit of a number: LA R1,NUM1+4 Point R1 at decimal in case NUM2 = 0 EDMK NUM1(7),NUM2 R1 Points at 1st printed no matter what. BCTR R1,R0 Move back 1 char. MVI 0(R1),C‘$’ Insert $. . . . NUM1 PL5 Decimal in pattern at NUM1 + 4: 40 20 20 21 4B 20 20

    33. 33 CVB & CVD Instructions Time to learn replacements for XDECI and XDECO, because they are peculiar to Assist and not on most standard assemblers. We will now use ED/EDMK instructions to ready packed decimal numbers for printing. That means that any numbers we have in registers must first be converted to decimal before using ED/EDMK.

    34. 34 CVB & CVD Instructions New commands: CVB (Convert to Binary) – converts a packed decimal number in storage to a binary fullword in a register. CVD (Convert to Decimal) – converts a fullword in a register to a packed decimal number in storage.

    35. 35 CVB & CVD Instructions

    36. 36 CVB Instruction Format: label CVB r,D(X,B)

    37. 37 CVB Instruction label CVB R4,DBLWORD R4 DBLWORD (packed) before irrelevant 00 00 00 00 00 00 01 8C after 00 00 00 12 unchanged

    38. 38 CVB Instruction label CVB R4,DBLWORD R4 DBLWORD (packed) before irrelevant 00 00 00 00 00 00 25 6C after 00 00 01 00 unchanged

    39. 39 CVB Instruction Possible errors on CVB: specification exception if not on a doubleword boundary. data exception if not a valid packed decimal number. fixed-point divide exception if the number is too large to be stored in a fullword. addressing and protection exceptions.

    40. 40 CVD Instruction Format: label CVD r,D(X,B)

    41. 41 CVD Instruction label CVD R4,DBLWORD R4 DBLWORD before 00 00 00 28 irrelevant after unchanged 00 00 00 00 00 00 04 0C

    42. 42 CVD Instruction Errors: specification exception if not on a doubleword boundary. Addressing exception if address doesn’t exist. Protection exception if address is outside the boundaries of the program.

More Related