HLASM - EX = EXecute another instruction

The opcode of the EX instruction is X'44'.


  1. Execute another instruction, modifying the second byte of that instruction prior to execution. Thus it is important to know what the second byte of the "target" instruction is used for.
  2. Force an abend for debugging by EXecuting an EXecute instruction, which is not allowed and causes an S0c3 abend.


  1. Register containing the 8 bits to be ORed into the target instruction.
  2. Address of the instruction to be executed (in index, base, displacement format).


  1. The processor retrieves the target instruction.
  2. The low order 8 bits of the register specified is OR-ed into the second byte of the retrieved target instruction. The target instruction in storage remains unchanged. The second byte of the target instruction will typically hold a length or a mask value, though this is not necessarily the case.
  3. The modified instruction is executed.
  4. The condition code does not change, unless it is set by the target instruction.

Special Cases

  1. When an EX of an EX instruction - either the EX itself or a different EX - is done, it causes an S0C3 abend. JES uses this. Some programmers\ prefer it to a x'00' S0C1 abend, because the chances of an S0C3 occurring by chance are many orders of magnitude lower than an S0C1 happening by chance.

Related Instructions

  1. None.


  1. All hardware supports the EX instruction.


  1. Instructions having an 8-bit length code in the second byte are commonly used with EX. These instructions include MVC, CLC, TRT, TR.
  2. Instructions having a 4-bit mask in the second byte are sometimes used with EX as well. Typical examples would be BC, ICM, STCM.
  3. Instructions working on packed decimal operands can be used as a target of EX as well, but these instructions have two length codes in the second byte.
  4. All length codes designate an operand length of the code plus one. For packed decimal operands, this holds for both length fields in the instruction. So, to specify the operand length(s) correctly, one has to be subtracted from each length before the EX can use it with the target instruction. Lengths are commonly decremented by using a BCTR instruction.
  5. With packed decimal instructions it is important to realize that both length fields in the instruction will participate in the OR-ing. If either length is to remain unchanged, then zeros have to be supplied in the appropriate positions in the first argument to the EX instruction.
  6. Many instructions specify one or two registers in the second byte of the instruction. Therefore, EX can modify the register(s) to be used with these instructions.
  7. All requirements of the executed instruction must be met, including alignment of storage operands.


         YREGS                          * Define register names
* The first code sample below shows the 2 most common uses of EX.
* The first packs a numeric field after determining how many digits there are.
* The second moves a variable number of characters.
* The examples use TRT which scans a field, looking for specified characters.
* When it finds something, it puts the address of the found character in
* register 1, and the byte from the search table in register 2.
* For a description of TRT, see that instructions description.
* In the first TRT, we ignore ##s and look for anything else,
* in order to find the length of the numeric field.
* We then use EX to pack the exact number of digits found.
* In the second TRT, we ignore everything else, and look for a period,
* in order to find the text length.
* We then move the exact number of characters in the string.
         SR    R2,R2                    * TRT does not clear the high 3 bytes.
         TRT   CARD(16),TESTNUM         * Scan to find end of ### field.
         BZ    TOOLONG                  * More than 15 digits, error
         BCTR  R2,NOTNUM                * Not ending in blank, error.
         S     R1,=A(CARD+1)            * Calc length of ### -1
         EX    R1,PACK                  * and pack ### into packed field
         TRT   CARD,FINDPER             * Find end of text
         S     R1,=A(CARD+1)            * Calc length we want to move
         EX    R1,MOVECHAR              * move to output field
DW       DC    D'0'
LINE     DC    CL133' '
* TRT table: Numbers are X'F0'through X'F9'
TESTNUM  DC    CL64' ',X'01',CL175' ',XL10'00',CL6' '
* TRT table: Period is X'75'
FINDPER  DC    XL75'00',C'.',XL180'00'
* ===================================
TESTNUM1 DC    CL240' ',XL10'00',CL6' '
         ORG   TESTNUM+C' '
         DC    X'01'
FINDPER1 DC    XL256'00'
         ORG   FINDPER+C'.'
         DC    C'.'
* There are 2 ways to define the TRT tables shown above.
* Both are shown above and both produce the same result.
         YREGS                          * Define register names
* This is a rather long example, that shows the use of EX twice.
* The first use is to pack a variable number of numeric digits.
* The second use is to move a string of variable length.
* Note that because EX OR's the low byte of the specified register,
* there may already be some non-zero bits in the target instruction.
* The example shows reading a text file, and narrowing the text to
* fit into a column width that is specified in the first record of
* the text read.
         GET   INPUTDCB,LINE            * Read the control record.
         TRT   LINE,TESTNUM             * Test for numeric field.
         BZ    TOOLONG                  * If too long, error.
         S     R1,=A(LINE+1)            * Calc length-1 of ###
         BM    NOTNUM                   * If length=0, error.
         EX    R1,PACKLEN               * Pack the digits read
         CVB   R8,DW                    * And make it binary. = col width.
FIRSTREA LA    R3,LINE                  * Point to input record area
         LR    R4,R3                    * Point to first available loc to read
READ     GET   INPUTDCB,(R4)            * Read into first blank area
         CLC   SPACES(12),0(R4)         * Q. spaces?
         BNE   SETSCAN                  * no, go parse.
         PUT   COLUMDCB,(R3)            * yes, write remnants of prior text
         PUT   COLUMDCB,(SPACES)        *      and a blank line.
         MVC   LINE,SPACES              *      init line to blanks
         B     FIRSTREA                 *      and start all over
* In this routine, we'll find the end of the read text, so we know where to
* put the next line read.
SETSCAN  LA    R4,133(R4)               * Point to last possible loc
SETSCANB BCTR  R4,0                     * Backup until we find some text
         CLI   0(R4),C' '               * Q. text yet?
         BE    SETSCANB                 * no, backup more
         LA    R4,2(R4)                 * yes, point 1 byte past end of text.
* In the scan routine, we'll see if there is enough text to fill a column.
* If not, we go read and get some more.
SCAN     LA    R5,1(R3,R8)              * Set end of col width.
         CR    R5,R4                    * Q. is there enough text to fill col line?
         BNH   BACKUP                   * yes, go find work break.
         CLC   SPACES(12),0(R3)         * Q. is there more text?
         BE    FIRSTREA                 * no, go start anew.
         MVC   LINE,0(R3)               * yes, move remaining text to beg of line
         S     R3,=A(LINE)              *     calc how far to backup end-of-text
         SR    R4,R3                    *     calc place to put next input line
         LA    R3,LINE                  *     point to start of text
         B     READ                     *     and go add to end of text
* Here, we back up until we find a word break.
BACKUP   BCTR  R5,0                     * Back up 1 byte
         CLI   0(R5),C' '               * Q. are we still in the middle of word?
         BNE   BACKUP                   * yes, back up 1 more byte to find text.
         LR    R2,R5                    * no, calc length of text to move
         SR    R2,R3                    *     to the column buffer.
         EX    R2,MVCCOL                * move text to column buffer
         PUT   COLUMOUT,column          * write column buffer
         LA    R3,2(R3,R2)              * point to next word
         MVC   COLUMN,SPACES            * space out column buffer
         CLC   SPACES(12),0(R3)         * Q. end of text?
         BE    FIRSTREA                 * yes, start with new text line.
         B     SCAN                     * no, continue with next text word.
ENDOFILE MVC   0(133,R4),SPACES         * Insure spaces
         PUT   COLUMOUT,(R3)            * Write last column record
         CLOSE (INPUTDCB,,COLUMOUT)     * Close files.
MVCCOL   MVC   COLUMN,0(R3)             * Move variable length of text
PACKLEN  PACK  DW,LINE(1)               * Pack variable # of digits to 8 byte field.
DW       DC    D'0'
SPACES   DS    0CL133                   * we use the numeric test tbl for blanks.
TESTNUM  DC    CL240' ',10X'00',CL6' '  * this is used to test for #s.
LINE     DC    2CL133' '                * input text line (long to accomodate 2 lines)
COLUMN   DC    CL133' '                 * output column

To the Opcodes Overview.
To the English Homepage for Hlasm.com.
To the General Homepage for Bixoft and Hlasm.com.

This site is a member of WebRing.
You are invited to browse the list of mainframe-loving sites.
Running Tyrannosaurus Rex Dinos are not dead. They are alive and well and living in data centers all around you. They speak in tongues and work strange magics with computers. Beware the dino! And just in case you're waiting for the final demise of these dino's: remember that dinos ruled the world for 155-million years!
Dinos and other anachronisms
[ Join Now | Ring Hub | Random | << Prev | Next >> ]

Below you find the logo of our sponsor and logos of the web-standards that this page adheres to.