Remove leading spaces



High Level Assembler(HLASM) for MVS & VM & VSE

Remove leading spaces

Postby armak » Wed Jun 03, 2015 2:56 pm

Hi all, I am sort of a new to assembler and currently facing an issue of leading spaces in string.The input record of mine is not at correct as it was supposed to be.
so, i have to remove those extra spaces from it.
I have alredy made a routine to do that for me but still i wanna knw that is there any instruction or by using a trick in any instruction could do the same.
armak
 
Posts: 1
Joined: Wed Jun 03, 2015 2:48 pm
Has thanked: 0 time
Been thanked: 0 time

Re: Remove leading spaces

Postby enrico-sorichetti » Wed Jun 03, 2015 4:17 pm

I have alredy made a routine to do that for me but still i wanna knw that is there any instruction or by using a trick in any instruction could do the same.

until You post Your code nobody will be able to tell if You can do better :mrgreen:
cheers
enrico
When I tell somebody to RTFM or STFW I usually have the page open in another tab/window of my browser,
so that I am sure that the information requested can be reached with a very small effort
enrico-sorichetti
Global moderator
 
Posts: 2994
Joined: Fri Apr 18, 2008 11:25 pm
Has thanked: 0 time
Been thanked: 164 times

Re: Remove leading spaces

Postby steve-myers » Thu Jun 04, 2015 7:40 am

There are two ways to do this.
  1. In place. In other words -
    A        DC    CL10'   X'

    becomes
    A        DC    CL10'X   '
  2. 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.
steve-myers
Global moderator
 
Posts: 2105
Joined: Thu Jun 03, 2010 6:21 pm
Has thanked: 4 times
Been thanked: 243 times


Return to Assembler

 


  • Related topics
    Replies
    Views
    Last post