I was looking at this very thing recently.  This response is in multiple parts 
due to listserv restrictions.

I got curious about what the compiler was doing for this line of code:

10 SEQ-NUMBER-PCER              PIC S9(4)     COMP.
10  sequence-convert-1-w         pic  zz9.

move seq-number-pcer   to sequence-convert-1-w

This is moving a halfword binary field to 3 bytes zoned decimal, but edited 
with zero suppression.


The way I was taught to do it was how it does it in z/OS Enterprise COBOL v4:

LH    0,1494(0,7)             SEQ-NUMBER-PCER
CVD   0,1536(0,13)            TS2=16
ZAP   1528(2,13),1542(2,13)   TS2=8
MVC   1520(4,13),2073(5)      TS2=0
ED    1520(4,13),1528(13)     TS2=0
MVC   915(3,7),1521(13)       SEQUENCE-CONVERT-1-W

1.      LH loads the halfword binary field into register 0.
2.      CVD converts it from binary to packed decimal.
3.      ZAP copies it; I'm not sure why.
Maybe the ED instruction is restrictive on what are allowable sign nibbles, and 
the ZAP is ensuring that they are valid: x'0D' or x'0C'
4.      MVC is setting up for the ED command: it is establishing an edit mask 
that will tell the ED command how to edit the field.
5.      ED is applying the edit mask to the (copied) packed field, resulting in 
the edited display field.
6.      MVC is moving (copying) the result to the destination field.

Seems pretty simple.

[to be continued, the listserv 250 line limit is brutal]

-----Original Message-----
From: IBM Mainframe Assembler List <ASSEMBLER-LIST@LISTSERV.UGA.EDU> On Behalf 
Of Ngan, Robert
Sent: Wednesday, August 20, 2025 1:51 PM
To: ASSEMBLER-LIST@LISTSERV.UGA.EDU
Subject: Re: Execute-Type Instructions

Speaking of optimizations, a while back I noticed the COBOL compiler generated 
the following code to edit a PIC 9(4) BINARY value into a PIX ZZZZ9 field

          MVC     496(6,R13),1851(R3)   #  TS2=119                +185
          LLH     R2,8(,R2)             #  U010-CO-ID
          VCVD    VRF16,R2,0x85,0
          VUPKZ   VRF16,1005(,R13),0x4  #
          CDZT    FP0,1005(5,R13),0x8   #
          ESDTR   R2,FP0
          VL      VRF17,2224(,R3),0     #
          VL      VRF18,2240(,R3),0     #
          VLRL    VRF20,1005(,R13),0x4  #
          VGBM    VRF19,0x0
          VLEIB   VRF19,0xf0,15
          VO      VRF20,VRF20,VRF19
          VPERM   VRF16,VRF17,VRF20,VRF18
          LHI     R4,0x5
          VSTL    VRF16,R4,496(,R13)    #  TS2=119
          VREPIB  VRF20,0x40
          LLC     R4,2256(R2,R3)        #
          LTR     R4,R4
          JE      L0642
          AHI     R4,0xffff
          VSTL    VRF20,R4,497(,R13)    #  TS2=119
L0642:    EQU     *
          L       R2,108(,R8)           #  BLL_9
          MVC     8(5,R2),497(R13)      #  U016-CO-ID-DISPLAY  TS2=119

I thought "All those vector instructions are better than an a single ED? I'd 
better learn what that's doing so I can use that technique myself".
Today, I decided to recompile the module to see if it generates better code 
since I noticed some of the above code could be further optimized. Our current 
COBOL 6.4 compiler generated:

          MVC     536(6,R13),2403(R3)   #  TS2=119                  +2403
          LLH     R2,8(,R2)             #  U010-CO-ID
          CVD     R2,1050(,R13)         #
          ED      536(6,R13),1055(R13)  #  TS2=119
          L       R2,88(,R8)            #  BLL_9
          MVC     8(5,R2),537(R13)      #  U016-CO-ID-DISPLAY      TS2=119

Robert Ngan
DXC Luxoft

Reply via email to