Portal | Manuals | References | Downloads | Info | Programs | JCLs | Master the Mainframes
IBM Mainframe Computers Forums Index
 
Register
 
IBM Mainframe Computers Forums Index Mainframe: Search IBM Mainframe Forum: FAQ Memberlist Usergroups Profile Log in to check your private messages Log in
 

 

need help in removing comma's in 70 byts of field in assembl

 
Post new topic   Reply to topic    IBMMAINFRAMES.com Support Forums -> PL/I & Assembler
View previous topic :: :: View next topic  
Author Message
ravi243

New User


Joined: 03 Aug 2011
Posts: 8
Location: Bangalore

PostPosted: Sun Nov 10, 2013 9:56 pm    Post subject: need help in removing comma's in 70 byts of field in assembl
Reply with quote

Hi Every One,

In one of my requirement, I have to check for comma's and remove those if present. Could any one please tell me how can I do this.

Thanks much in advance.
Ravi
Back to top
View user's profile Send private message

Bill O'Boyle

CICS Moderator


Joined: 14 Jan 2008
Posts: 2502
Location: Atlanta, Georgia, USA

PostPosted: Mon Nov 11, 2013 3:35 am    Post subject: Reply to: need help in removing comma's in 70 byts of field
Reply with quote

If your task is to remove them outright, then your can do it in several ways:

A) TRT - Translate and Test (a single sweep). A succession of these, left justifying the data in the target-area as you move from left to right, with each new TRT beginning at the comma-address (in R1) just found + 1. The TRT requires a 256-byte table, consisting of 256 X'00's and set the comma-offset to X'FF', as the character you want to stop at.

B) TR - Translate - A two phase sweep, with the first sweep, converting commas to spaces in the target-area. The second sweep, left-justify the target-area into a separate 70-byte workarea, until you've addressed the target-area beyond byte-70. Always initialise the separate workarea to spaces beforehand. You'll need three registers for this. Your workarea will be left justified with low-order spaces after the second sweep.

C) BCT - Branch on Count. A single sweep, pointing a register at the target-area start, loading another register with value of 70 (use an LA with an L') and a third register, pointing to a separate 70-byte workarea. In the sweep, move each valid byte (non-comma and non-space) to the workarea. Always initialise the separate workarea to spaces beforehand. Your workarea will be left justified with low-order spaces after this one and only sweep.

To save yourself some time, before doing anything, issue a TRT against the 70-byte target-area, using a 256-byte table, consisting of 256 X'00's and set the comma-offset to X'FF'.

If after the TRT (which inherently uses R1 and R2), a BZ condition-code indicates there aren't any comma's, whereas a BNZ indicates there is at least one.

Example translate-table -
Code:

XLATETBL  DC    XL256'00'      256-BYTES OF X'00'S
          ORG   XLATETBL+C','  REDEFINITION
          DC    XL1'FF'        SET COMMA-SLOT TO X'FF'

One of these three should get you on your way, with choice "C" being the most rudimentary.

Welcome to the forum.

HTH....
Back to top
View user's profile Send private message
dick scherrer

Site Director


Joined: 23 Nov 2006
Posts: 19270
Location: Inside the Matrix

PostPosted: Tue Nov 12, 2013 7:35 pm    Post subject:
Reply with quote

Hello and welcome to the forum

How do you define " remove those if present"?

Should they become a space or some other value or should the data be shifted?

As usual, the best way to ask this kind of questio is to show some sample input and the output you want from that sample input.
Back to top
View user's profile Send private message
ravi243

New User


Joined: 03 Aug 2011
Posts: 8
Location: Bangalore

PostPosted: Wed Nov 13, 2013 11:46 pm    Post subject: Reply to: need help in removing comma's in 70 byts of field
Reply with quote

Thank You Bill for valuable reply

Dick, The Data needs to be shifted.

Input: This site is very useful, helpful

Output should: This site is very useful helpful
Back to top
View user's profile Send private message
dick scherrer

Site Director


Joined: 23 Nov 2006
Posts: 19270
Location: Inside the Matrix

PostPosted: Thu Nov 14, 2013 1:09 am    Post subject:
Reply with quote

Hello,

Move spaces to an "output area".

Then write a loop that will move 1 char from the "input" to the "output" skipping any comma found.
Back to top
View user's profile Send private message
Bill O'Boyle

CICS Moderator


Joined: 14 Jan 2008
Posts: 2502
Location: Atlanta, Georgia, USA

PostPosted: Thu Nov 14, 2013 1:10 am    Post subject: Reply to: need help in removing comma's in 70 byts of field
Reply with quote

I've only desk-checked the following -

Code:

TRGTAREA DS    CL70                TARGET-AREA                         
WORKAREA DS    CL(L'TRGTAREA)      WORK-AREA                           
SAVEREGS DS    3F                  SAVE-AREA FOR R6 THRU R8             
*                                                                       
         MVC   TRGTAREA,=CL70'ABCDEF,ABCDEF,ABCDEF,ABCDEF'             
         MVI   WORKAREA,C' '       ENSURE SPACES                       
         MVC   WORKAREA+1(L'WORKAREA-1),WORKAREA                       
         STM   R6,R8,SAVEREGS      SAVE R6 THRU R8                     
         LA    R6,TRGTAREA         POINT TO TARGET-AREA                 
         LA    R7,L'TRGTAREA       LOAD TARGET-AREA LGTH               
         LA    R8,WORKAREA         POINT TO WORK-AREA                   
SQZLOOP  EQU   *                                                       
         CLI   0(R6),C','          IS THIS A COMMA?                     
         JE    SQZBUMP             YES, BYPASS THIS BYTE               
         MVC   0(1,R8),0(R6)       MOVE TO WORK-AREA                   
         LA    R8,1(,R8)           BUMP 'WORK-AREA' ADDRESS             
SQZBUMP  EQU   *                                                       
         LA    R6,1(,R6)           BUMP 'TARGET-AREA' ADDRESS           
         JCT   R7,SQZLOOP          BRANCH WHEN NON-ZERO                 
         LM    R6,R8,SAVEREGS      RESTORE R6 THRU R8                   

Once the JCT completes, WORKAREA will contain 'ABCDEFABCDEFABCDEFABCDEF', padded with low-order spaces, with all commas removed.

HTH....
Back to top
View user's profile Send private message
dbzTHEdinosauer

Global Moderator


Joined: 20 Oct 2006
Posts: 6966
Location: porcelain throne

PostPosted: Mon Nov 18, 2013 8:45 pm    Post subject:
Reply with quote

why not do it using sort?
Back to top
View user's profile Send private message
dick scherrer

Site Director


Joined: 23 Nov 2006
Posts: 19270
Location: Inside the Matrix

PostPosted: Mon Nov 18, 2013 9:17 pm    Post subject:
Reply with quote

Hi Dick,

Quote:
why not do it using sort?
My thought - this was being added to some existing code (couldn't say why i believed this) . . .

If not, SORT should be considered icon_cool.gif

d
Back to top
View user's profile Send private message
Bill O'Boyle

CICS Moderator


Joined: 14 Jan 2008
Posts: 2502
Location: Atlanta, Georgia, USA

PostPosted: Tue Nov 19, 2013 12:06 am    Post subject: Reply to: need help in removing comma's in 70 byts of field
Reply with quote

DBZ and Dick,

Never considered SORT, but it's a better way to go. No programming, just JCL.

Marvelous idea.... icon_biggrin.gif

Regards,
Back to top
View user's profile Send private message
steve-myers

Active User


Joined: 30 Nov 2013
Posts: 462
Location: The Universe

PostPosted: Tue Apr 29, 2014 9:11 pm    Post subject:
Reply with quote

This too late for ravi243's homework turn in. At entry the only requirement is a valid base register.
Code:
         ...
SCAN     TRT   DATA,TRTTAB         Find a comma
         BZ    DONE                Br if no comma found
         LA    14,1(,1)            Compute address of the byte after  ->
                                    the comma
         LA    15,DATA+L'DATA      Load address of the end of the     ->
                                    data area
         SR    15,14               Compute bytes to move
         BNP   DONE                Br if nothing left to move
         BCTR  15,0                Reduce length by 1
         EX    15,MVC              Remove the comma
         MVI   DATA+L'DATA-1,C' '  Make sure vacated byte is blank
         B     SCAN                Try again
MVC      MVC   0(*-*,1),1(1)       ** Execute only **
DONE     ...
TRTTAB   DC    0XL256'0',(C',')X'00',X'04',(256-(*-TRTTAB))X'00'
DATA     DC    CL70'Moore School, 3300 Walnut Street, Philadelphia PA 1>
               9104'
         ...
Many programmers preset register 1 before the TRT, but it's not necessary here, for two reasons
  • A default value must be set for use after a condition code 0, but this code exits after condition code 0.
  • TRT may not set the high order bit or high order 8 bits of register 1, depending on the AMODE, to 0, which will bollix the length calculation for the MVC. It's not necessary here, though this is a good exercise for a lazy reader.
Another issue is an argument can be made the code should resume its scan after it has removed a comma at the point where it detected the comma, to reduce execution time of the TRT. True, but then you have two other issues.
  • The arithmetic uses CPU time. How much will you save by scanning fewer bytes? Hard to answer, especially since the answer depends on how deep you are into the data area.
  • More instructions means more potential debugging time.
For what it's worth, the address for the Moore School of the University of Pennsylvania, the former home of ENIAC, is technically incorrect. As indicated here, it's at the intersection of 33rd Street and Walnut Street, but there is no entry to the building on Walnut Street. The main entry is on 33rd Street, so the correct address is something or other South 33rd Street.
Back to top
View user's profile Send private message
PeterHolland

Global Moderator


Joined: 27 Oct 2009
Posts: 2422
Location: Netherlands, Amstelveen

PostPosted: Thu May 01, 2014 3:29 pm    Post subject: Reply to: need help in removing comma's in 70 byts of field
Reply with quote

steve, here a nice link (pdf alert) concerning cpu time :

http://www.ifipwg103.org/seminar/IdiomRecognitionTN.pdf
Back to top
View user's profile Send private message
steve-myers

Active User


Joined: 30 Nov 2013
Posts: 462
Location: The Universe

PostPosted: Thu May 01, 2014 4:18 pm    Post subject:
Reply with quote

steve-myers wrote:
... Another issue is an argument can be made the code should resume its scan after it has removed a comma at the point where it detected the comma, to reduce execution time of the TRT. True, but then you have two other issues.
  • The arithmetic uses CPU time. How much will you save by scanning fewer bytes? Hard to answer, especially since the answer depends on how deep you are into the data area.
...
I played around with code some more. In the process I realized
  • If there was 1 comma in the last byte it would not be cleared.
  • The scan length to resume the scan was the same length used to shift the text.
The revised code becomes
Code:
         ...
         LA    15,L'DATA-1         Load initial length
         LA    1,DATA              Load addr to start scan
SCAN     EX    15,TRT              Find a comma
         BZ    DONE                Br if no comma found
         MVI   0(1),C' '           Replace comma with a blank
         LA    14,1(,1)            Compute address of the byte after  ->
                                    the comma
         LA    15,DATA+L'DATA      Load address of the end of the     ->
                                    data area
         SR    15,14               Compute bytes to move
         BNP   DONE                Br if nothing left to move
         BCTR  15,0                Reduce length by 1
         EX    15,MVC              Remove the comma
         MVI   DATA+L'DATA-1,C' '  Make sure vacated byte is blank
         B     SCAN                Try again
TRT      TRT   0(*-*,1),TRTTAB     ** Execute only **
MVC      MVC   0(*-*,1),1(1)       ** Execute only **
DONE     ...
TRTTAB   DC    0XL256'0',(C',')X'00',X'04',(256-(*-TRTTAB))X'00'
DATA     DC    CL70'Moore School, 3300 Walnut Street, Philadelphia PA 1>
               9104'
The MVI 0(1),C' ' after the BZ corrects the bug.

The two instructions at the start set an initial length and scan address.

Mr. Holland: I looked through the slides in your reference. I had never realized the relative performance of TRT was as good as apparently shown in the slides; it makes a case of sorts for complex instruction set hardware as opposed to RISC hardware! Personally, I never quite believed the case for RISCy hardware, though I'm reluctant to step into that holy war. In any event, the slides in Mr. Holland's reference suggest that the optimization implied by the revised code is hardly necessary.
Back to top
View user's profile Send private message
steve-myers

Active User


Joined: 30 Nov 2013
Posts: 462
Location: The Universe

PostPosted: Sun May 11, 2014 3:15 am    Post subject:
Reply with quote

Mt. Holland's reference discussed the use of the SRST (Search String) instruction for the case where just one character is being searched for. I remember researching the instruction in the 1990s and concluded it would be useful for C language programs and library functions with their null character terminated strings, and promptly forgot it and never tried to use it. Since it does not need to load bytes from a table for each character the instruction is testing, it should be faster than the TRT instruction for this application.

In practice, however, since the strings are fairly short – 70 bytes in our application – there is little chance of measuring the performance improvement. In any event, here is the resulting program.
Code:
         ...
         LA    3,DATA              Load address of start of data
         LHI   0,C','              Load stop character
NEXT     LA    4,DATA+L'DATA       Load address of end of data
         SRST  4,3                 Scan for a comma
         BC    B'1011',DONE        Br if we did not find a comma
         MVI   0(4),C' '           Set comma to blank
         LA    15,DATA+L'DATA-1    Load address of end of data
         SR    15,4                Compute length to move
         BM    DONE                Br if nothing to move
         EX    15,MVC              Shift data
         MVI   DATA+L'DATA-1,C' '  Set vacated character to blank
         LR    3,4                 Set new start of scan
         B     NEXT                And try again
MVC      MVC   0(*-*,4),1(4)       ** Execute only **
DONE     ...
DATA     DC    CL70'3401 MARKET STREET, PHILADELPHIA PA 19104'
Back to top
View user's profile Send private message
steve-myers

Active User


Joined: 30 Nov 2013
Posts: 462
Location: The Universe

PostPosted: Mon May 12, 2014 5:07 am    Post subject:
Reply with quote

Mr. O'Boyle proposed using the BCT instruction for loop control, and even provided an admittedly untested example.

I admit I tend to avoid BCT. When possible I prefer BXLE. BCT usually requires two instructions to close a loop; when you use BXLE you can usually close the loop with just the BXLE. The following tested fragment uses BCT; the readers will see the similarities with the examples that use the TRT and SRST instructions.
Code:
         ...
         LA    3,DATA              Load address of start of data
         LA    0,L'DATA            Load bytes in string
NEXT     CLI   0(3),C','           Test if comma
         BNE   BUMP                Br if we did not find a comma
         MVI   0(3),C' '           Set comma to blank
         LA    15,DATA+L'DATA-1    Load address of end of data
         SR    15,3                Compute length to move
         BM    DONE                Br if nothing to move
         EX    15,MVC              Shift data
         MVI   DATA+L'DATA-1,C' '  Set vacated character to blank
BUMP     AHI   3,1                 Update the scan pointer
         BCT   0,NEXT              And try again
         B     DONE
MVC      MVC   0(*-*,3),1(3)       ** Execute only **
DONE     ...
DATA     DC    CL70'3401 MARKET STREET, PHILADELPHIA PA 19104'
Readers may also understand why instructions like TRT or SRST will often outperform code like this example. This example uses 4 instructions for each byte that is not a comma; worse, it fetches the test byte one byte at a time. Instructions like SRST or TRT can fetch multiple bytes in the string when starting and don't have to repeat the fetch as often.
Back to top
View user's profile Send private message
View previous topic :: :: View next topic  
Post new topic   Reply to topic    IBMMAINFRAMES.com Support Forums -> PL/I & Assembler All times are GMT + 6 Hours
Page 1 of 1

 

Search our Forum:

Similar Topics
Topic Author Forum Replies Posted
No new posts Removing Duplicates based on certain ... chandracdac DFSORT/ICETOOL 8 Fri Dec 09, 2016 4:40 am
No new posts Performing arithmetic on input field zh_lad DFSORT/ICETOOL 24 Tue Dec 06, 2016 8:04 pm
No new posts Add PD field from 2nd file to PD in 1st Sushant Garje DFSORT/ICETOOL 6 Thu Dec 01, 2016 4:32 pm
No new posts How to split the records using the am... vnktrrd DFSORT/ICETOOL 24 Fri Oct 28, 2016 7:33 pm
No new posts Sort records based on numeric field. Alks SYNCSORT 2 Wed Oct 19, 2016 10:14 pm


Facebook
Back to Top
 
Mainframe Wiki | Forum Rules | Bookmarks | Subscriptions | FAQ | Tutorials | Contact Us