1 of 23

IBM® z/Architecture�EDIT (ED) and EDIT AND MARK (EDMK) Instructions

Dan Greiner – IBM Architect Emeritus

1

2 of 23

The Legal Stuff

  • Trademarks:
    • IBM is a registered trademark of the International Business Machines Corporation in the United States, other countries, or both. The following terms which may appear in this presentation are trademarks or registered trademarks of the International Business Machines Corporation in the United States, other countries, or both:
      • ESA/390
      • z/Architecture
      • z/OS
      • z/VM
    • Linux is a registered trademark of Linus Torvalds in the United States, other countries or both.
    • Unicode is a registered trademark of Unicode, Incorporated in the United States, other countries, or both.
    • Other trademarks and registered trademarks are the properties of their respective companies.
  • All information contained in this document is subject to change without notice. All information contained in this document was obtained in laboratory environment and is presented as an illustration. The results obtained in other operating environments may vary.
  • While the information contained herein is believed to be accurate, such information is preliminary, and should not be relied upon for accuracy or completeness, and no representations or warranties of accuracy or completeness are made.
  • The information in contained in this document is provided on an “AS IS” basis. In no event will the author be liable for damages arising directly or indirectly from any use of the information contained in this document.

© Copyright Dan F. Greiner 2022.

2

3 of 23

ED & EDMK Uses

How to take this signed packed-decimal value …

31

41

59

26

53

58

97

9C

3

.

1

4

1

,

5

9

2

,

6

5

3

,

5

8

9

,

7

9

… and turn it into this printable EBCDIC value (in 1 instruction).

00

00

00

00

12

34

56

7C

$

1

2

,

3

4

5

.

6

7

00

03

99

5A

*

*

*

3

9

.

9

5

*

*

How to take this signed packed-decimal value …

… and turn it into this printable EBCDIC value (in 1 instruction).

How to take this signed packed-decimal value …

… and turn it into this printable EBCDIC value (in 2 instructions).

3

4 of 23

EDIT (ED)

ED D1,(L,B1),D2,(B2) [SS-a]

DE

L

B2

D2

B1

D1

The first operand designates the location of the pattern bytes which are:

  • Replaced with a 2nd-op source digit
  • Replaced with a fill byte, or
  • Unchanged

The second operand designates the location of the source bytes consisting of signed or unsigned packed-decimal data

n

n

n

n

n

n

n

n

n

n

n

n

n

n

s

//

//

Pat

Pat

Pat

Pat

Pat

Pat

Pat

Pat

Pat

Pat

Pat

Pat

//

//

The L (length) field designates one less than the number of bytes in the first operand.

4

5 of 23

Significance Indicator

  • The significance indicator (SI) is an internal flag that has multiple functions:
    • SI controls the handling of the fill byte:
      • When a leading packed-decimal zero from the 2nd operand is converted to a zoned zero value in the 1st operand.
      • When handling a message byte (more later)
    • SI controls the setting of the condition code based on the rightmost (or only) field being edited in the 1st operand.
  • SI is set as follows:
    • Off (0):
      • When instruction execution begins
      • When a field separator is encountered in the 1st operand
      • When a 2nd-operand source byte contains a plus code in bits 4-7.
    • On (1):
      • When a significance-starter pattern byte encountered in the 1st operand.
      • When nonzero packed-decimal source digit is selected in the 2nd operand (and the sign code of the source byte is not plus).

5

6 of 23

The 1st Operand

  • The 1st operand comprises pattern bytes, having the following encoding:
    • Digit Selector (DS): X’20’
    • Significance Starter (SS): X’21’
    • Field Separator (FS): X’22’
    • Message byte (MB): Anything else
  • Depending on the pattern byte, it is updated based on its encoding as follows:
    • Replace with the next digit selected from the 2nd operand, or
    • Replace with the fill byte, or
    • Remains unchanged.
  • The length (L) of the first operand in bytes is specified in bits 8-15 of the instruction.
    • The object code generated is one less than that specified in the assembler-language statement.

6

7 of 23

1st-Operand Fill Byte

  • The leftmost pattern byte in the first operand is the fill byte.
    • When a DS or SS selects a zero digit from the 2nd operand, and the significance indicator is off, the 1st-operand pattern byte is replaced with the fill byte.
    • When a 1st-operand pattern byte is a field separator, the field separator is always replaced by the fill byte.
    • When a 1st-operand pattern byte is a message byte, and the significance indicator is off, the message byte is replaced by a fill byte.
  • The fill byte may any character, including a control function (i.e., DS, SS, or FS).

7

8 of 23

Digit Selector (DS, 1st-operand pattern byte)

  • Code value X’20’
  • Depending on the significance indicator, the DS pattern byte is replaced by:
    • The fill byte – when SI is off and the next packed-decimal digit in the 2nd operand is zero.
    • The zoned-decimal representation of the next packed-decimal digit in the 2nd operand – when either SI is on or the decimal digit is nonzero.
  • When a nonzero decimal digit is inserted, SI is turned on if the rightmost 4 bits of the 2nd-operand source byte are not a plus code (i.e., not hex A, C, E, or F).

8

9 of 23

Significance Starter�(SS, 1st-operand pattern byte)

  • Code value X’21’
  • Operates identically to a digit selector (DS), except:
    • For a DS, the significance indicator (SI) is turned on if a nonzero source digit is processed, and the rightmost 4 bits of the source byte is not a plus code.
    • For a SS, SI is turned on regardless of whether the source digit is zero, and the rightmost 4 bits of the source byte is not a plus code.
  • SS can be used to indicate that subsequent leading zeros should be formatted as such in the 1st operand.

9

10 of 23

Field Separator (FS, 1st-operand pattern byte)

  • Code value X’22’
  • A field separator in the 1st operand is always replaced by the fill byte.
  • The significance indicator is always turned off.

  • And that’s all there is to it!

10

11 of 23

Message Byte (MB, 1st-Operand Pattern Byte)

  • Code value: Anything other than DS, SS, or FS.
  • Handling of the message byte is as follows:
    • When SI is off, the message byte is replaced by the fill byte.
    • When SI is on, the message byte is unchanged.
  • In either case, SI is unchanged.

  • Example of message bytes:

Message byte (also serves as fill byte).

40

20

20

20

6B

20

20

20

6B

20

21

20

4B

20

20

Message bytes (comma separators).

Message bytes (comma separators).

Message byte (decimal point).

11

12 of 23

2nd-Operand Source Bytes & Source Digits

  • Variable-length signed or unsigned packed-decimal fields.
  • Each four bits of a source byte form a source digit
  • Leftmost source digit of each source byte must be a valid packed-decimal digit (0-9)
    • General-operand data exception recognized the left source digit of a source byte is a packed-decimal sign code (hex A-F)�
  • Example of multiple fields in the 2nd operand:

Negative sign code.

Positive sign code.

Whoops!�Sign code in left digit is invalid.

31

41

59

26

53

58

97

9D

14

14

21

35

62

37

30

9C

00

00

45

77

81

B3

40

7D

1st Field

2nd Field

3rd Field

12

13 of 23

Condition Code

  • The condition code is set based on the results in the rightmost (or only) edited field.
    • CC0: Rightmost (or only) field is zero or has zero length
    • CC1: Significance indicator is on
      • When the rightmost source byte examined contains a packed-decimal sign code, SI=1 indicates a negative result.
    • CC2: Significance indicator is off
      • When the rightmost source byte examined contains a packed-decimal sign code, SI=0 indicates a positive result.

  • Note: When SI is on, but the source field is unsigned, CC1 will be set.

13

14 of 23

EDIT AND MARK (EDMK)

EDMK D1,(L,B1),D2,(B2) [SS-a]

DF

L

B2

D2

B1

D1

0

0

0

1

7

8

9

9

5

C

40

20

6B

20

20

20

6B

20

21

20

4B

20

20

1st Operand Before (hex):

1

,

7

8

9

.

9

5

1st Operand After (EBCDIC):

General register 1 points to the leftmost significant digit of the rightmost (or only) field having significance.

14

15 of 23

Examples of EDIT (ED) (1 of 3)

Message Byte

Digit Selector

Significance Starter

Field Separator

Edit a Value in Millionths

40

20

6B

20

20

20

6B

20

21

20

4B

20

20

20

6B

20

20

20

1st Operand (before, hex):

1

2

3

,

4

5

6

.

7

8

9

,

0

1

2

1st Operand (after, EBCDIC):

2

Resulting condition code:

01

23

45

67

89

01

2C

2nd Operand (hex):

(code: P’0123456789012’)

Same Thing but with Smaller 2nd Operand

40

20

6B

20

20

20

6B

20

21

20

4B

20

20

20

6B

20

20

20

1st Operand (before, hex):

1

.

2

3

4

,

5

6

7

1st Operand (after, EBCDIC):

2

Resulting condition code:

00

00

00

12

34

56

7C

2nd Operand (hex):

(code: P’0000001234567’)

Same Thing but with 2nd Operand of Zero

40

20

6B

20

20

20

6B

20

21

20

4B

20

20

20

6B

20

20

20

1st Operand (before, hex):

0

.

0

0

0

,

0

0

0

1st Operand (after, EBCDIC):

0

Resulting condition code:

00

00

00

00

00

00

0C

2nd Operand (hex):

(code: P’0000000000000’)

15

16 of 23

Examples of EDIT (ED) (2 of 3)

Message Byte

Digit Selector

Significance Starter

Field Separator

Edit a Value with an Asterisk as the Fill Byte

5C

20

6B

20

20

20

6B

20

21

20

4B

20

20

1st Operand (before, hex):

*

9

,

8

7

6

,

5

4

3

.

2

1

1st Operand (after, EBCDIC):

2

Resulting condition code:

98

76

54

32

1C

2nd Operand (hex):

(code: P’987654321’)

Same Thing, but with More Asterisks

5C

20

6B

20

20

20

6B

20

21

20

4B

20

20

1st Operand (before, hex):

*

*

*

*

*

1

,

0

2

4

.

0

0

1st Operand (after, EBCDIC):

1 (sign code ‘D’ means negative)

Resulting condition code:

00

01

02

40

0D

2nd Operand (hex):

(code: P’-000102400’)

Same Thing, but with Lots More Asterisks

5C

20

6B

20

20

20

6B

20

21

20

4B

20

20

1st Operand (before, hex):

*

*

*

*

*

*

*

*

*

1

.

9

8

1st Operand (after, EBCDIC):

2

Resulting condition code:

00

00

00

19

8C

2nd Operand (hex):

(code: P’000000198’)

16

17 of 23

Examples of EDIT (ED) (3 of 3)

Message Byte

Digit Selector

Significance Starter

Field Separator

Edit Pattern Leading Off with a Significance Starter

1

Resulting condition code:

00

00

00

00

06

2nd Operand (hex):

(code: P’-00000000069’)

40

21

20

4B

20

20

20

6B

20

20

20

6B

20

1st Operand (before, hex):

20

20

0

.

0

0

0

,

0

0

0

,

0

1st Operand (after, EBCDIC):

6

9

9D

Editing Multiple Fields from a Single Packed Number

2

Resulting condition code:

12

34

56

70

04

2nd Operand (hex):

(code: P’1234567004321’)

32

1C

40

20

20

6B

20

21

20

4B

20

20

22

20

6B

1st Operand (before, hex):

20

21

20

4B

20

20

1

2

,

3

4

5

.

6

7

1st Operand (after, EBCDIC):

4

3

.

2

1

Editing Multiple Fields from Multiple Packed Numbers

2

Resulting condition code:

12

3C

45

6C

78

2nd Operand (hex):

(code: P’123,456,789,012’)

9C

01

2C

40

21

4B

20

20

22

1st Operand (before, hex):

21

4B

20

20

22

21

4B

20

20

22

21

4B

20

20

22

1

.

2

3

4

.

5

6

7

.

1st Operand (after, EBCDIC):

8

9

.

1

2

17

18 of 23

Examples of EDIT AND MARK (EDMK) (1 of 2)

Message Byte

Digit Selector

Significance Starter

Field Separator

Edit a Value in Millionths, Mark the 1st Significant Digit

40

20

6B

20

20

20

6B

20

21

20

4B

20

20

20

6B

20

20

20

1st Operand (before, hex):

1

2

3

,

4

5

6

.

7

8

9

,

0

1

2

1st Operand (after, EBCDIC):

2

Resulting condition code:

01

23

45

67

89

01

2C

2nd Operand (hex):

(code: P’0123456789012’)

Editing Multiple Fields from a Single Packed Number

2

Resulting condition code:

12

34

56

70

04

2nd Operand (hex):

(code: P’1234567004321’)

32

1C

40

20

20

6B

20

21

20

4B

20

20

22

20

6B

1st Operand (before, hex):

20

21

20

4B

20

20

1

2

,

3

4

5

.

6

7

1st Operand (after, EBCDIC):

4

3

.

2

1

GR1 after

General register 1 points to the leftmost significant digit of the rightmost (or only) field having significance.

GR1 after

18

19 of 23

Examples of EDIT AND MARK (EDMK) (2 of 2)

Message Byte

Digit Selector

Significance Starter

Field Separator

Edit a Value of Zeroes with No Significance Starter

40

20

20

20

20

20

1st Operand (before, hex):

1st Operand (after, EBCDIC):

0

Resulting condition code:

00

00

0C

2nd Operand (hex):

(code: P’00000’)

WARNING: General register 1 is unmodified when no significant digits are discovered.

GR1 after

General register 1 contains the address of leftmost significant digit of the rightmost field having a significant digit. Because the third field is insignificant, GR1 does not point to it.

Editing Multiple Fields from a Single Packed Number

0

Resulting condition code:

12

3C

45

6D

00

2nd Operand (hex):

(code: P’123,-456,000’)

0C

1

2

3

4

5

6

1st Operand (after, EBCDIC):

40

20

21

20

22

1st Operand (before, hex):

20

21

20

22

20

20

20

19

20 of 23

Programmator Caveat

Signed packed-decimal fields always contain an odd number of digits.

    • The rightmost 4 bits of the rightmost byte of the packed field contains the sign code.
      • Binary 1010, 1100, 1110 and 1111 indicate positive (1100 preferred)
      • Binary 1011 and 1101 indicate negative (1101 preferred)
    • If a signed packed-decimal field contains an even number of digits, the leftmost digit will always be zero!
      • P‘11235813’ generates X‘011235813C’
      • P‘-123456’ generates X‘0123456D’
    • A common mistake in generating ED and EDMK pattern bytes is to not account for this leading zero!

20

21 of 23

ED and EDMK Conceptual Flow

END 🡨 OP1 + L;

LRF 🡨 0 (left);

NZD 🡨 0;

SI 🡨 0 (off);

ED & EDMK

*OP1 and�*(OP1+L) accessible

Access Exception

FB 🡨 *OP1;

SI

LRF 🡨 0 (left);

No

Yes

(left) 0

1 (right)

LRF

PB 🡨 *OP1;

PB == DS�or

PB == SS

PB == FS

Yes

SI 🡨 0;�NZD 🡨 0;

Yes

No

1

0

*OP1 🡨 FB;

OP1++;

OP1 > END

NZD

No

Yes

Exit CC0

SI

1

Exit CC1

0

0

1

Exit CC2

RD > 9

Yes

*OP2 accessible

Access Exception

No

SB 🡨 *OP2;

SD 🡨 SB >> 4;

RD 🡨 SB & 0x0F;

OP2++;

SD > 9

General Op. Data Exception

Yes

Yes

LRF 🡨 LRF ^ 1;

SI

0

1

SD

0

>0

For EDMK, GR1 set to OP1.

*OP1 🡨 FB;

*OP1 🡨 SD | 0xF0;

Get Next Source Digit

Handle DS or SS Pattern Byte

No

No

SD 🡨 RD;

SD

>0

NZD 🡨 1;

0

PB == SS

Yes

No

RD == PLUS

SI 🡨 1;

Yes

No

SI 🡨 0;

A

Notes:�A. When the pattern byte is a message byte (i.e., not a DS, SS, or FS) and the significance indicator is on, � the pattern byte is effectively unchanged. A store of unchanged data must occur for change-bit setting� and PER purposes.

B. This is a simplification of the operand-2 access checking. On all modern machines, all accessed bytes of� the second operand are assured to be accessible before any byte of operand 1 is stored.

B

21

22 of 23

Explanation of Symbols Used in Conceptual Flow

  • 🡨 Assignment
  • + Addition
  • ++ Increment
  • & Logical AND
  • | Logical OR
  • ^ Logical exclusive OR (XOR)
  • * Dereferencing of pointer
  • CC Condition code set at instruction completion
  • DS Digit selector (pattern byte X’20’)
  • END Pointer to the last byte of the 1st operand
  • FB Fill byte (1st byte of 1st operand)
  • FS Field separator (pattern byte X’22’)
  • GR1 General register 1
  • L Length of the 1st operand from the instruction text (zero based)
  • LRF Left / right flag (0=left; 1=right)
  • NZD Non-zero-detected flag (0=nothing yet; 1=nonzero detected)
  • OP1 Pointer to the next byte of the 1st operand
  • OP2 Pointer to the next byte of the 2nd operand
  • PB Pattern byte from the 1st operand
  • PLUS Packed-decimal positive sign code (i.e., hex A, C, E, or F)
  • RD Right digit from the source byte
  • SB Source byte from the 2nd operand
  • SD Source digit from the source byte
  • SI Significance indicator (0=off, 1=on)
  • SS Significance starter (pattern byte X’21’)

22

23 of 23

Lessons Learned

  • ED and EDMK provide extremely powerful capabilities for efficiently formatting signed or unsigned packed-decimal data
    • Replacing insignificant leading zeros and message bytes with a fill character.
    • Adding formatting characters such as magnitude and decimal characters
    • Processing multiple fields

All in a single instruction!

  • EDMK provides the indication of where significance is detected in the result (if it’s detected at all).

23