There are two ways to do this.
- In place. In other words -
becomes
- New area, in other words -
A DC CL10' X'
B DC CL10' '
becomes
A DC CL10' X'
B DC CL10'X '
In the second option, you can move A to B in one instruction and also pad the vacated bytes in A with blanks in B. Both options require considerable setup code. This is code for the second option.
LA 3,DATA
LA 4,L'DATA
LA 5,LASTDATA
TLOOP MVC FROM,0(3)
MVC TO,0(3)
SR 1,1
TRT 0(L'DATA,3),MVLTRT
BZ NOMOVE
LR 0,1
LA 1,L'DATA(,3)
SR 1,0
BNP NOMOVE
ICM 1,B'1000',=C' '
LA 14,TO
LA 15,L'TO
MVCL 14,0
NOMOVE LA 0,L'MSG
LA 1,MSG
TPUT (1),(0),R
BXLE 3,4,TLOOP
...
DATA DC CL10' X'
DC CL10' X '
DC CL10' XXX'
DC CL10' X '
DC CL10' X X'
DC CL10' X X'
DC CL10'X '
DC CL10'XXXXXXXXXX'
LASTDATA DC CL10' '
MSG DC 0C'C''----+----1'' -> C''----+----1'''
DC C'C'''
FROM DC CL10' ',C''' -> C'''
TO DC CL10' ',C''''
DC 0D'0'
MVLTRT DC X'00',(C' '-(*-MVLTRT))X'04' Table to locate
DC X'00',(256-(*-MVLTRT))X'04' a non-blank
In both options, you must locate the first non-blank: this can be done in one instruction with the TRT instruction. The TRT instruction will store the address of the first non-blank in register 1 and it sets the condition code to 1 or 2. If it did not find a non-blank, it sets the condition code to 0. The MVLTRT table in the example regards X'00' and C' ' as blanks. In the example, the BZ instruction will branch if no non-blanks were found and the condition code was set to -.
The program computes the length of data to move, from the address of the first non-blank to the end of data in register 1 and sets the high order 8 bits of register 1 to blank to provide the data to replace the vacated bytes in the input area. It then sets register 14 with the address of the new output area and register 15 with the length of the output area and uses MVCL to copy the data to the output area.
The TPUT instruction writes data to the current users TSO terminal.