MVSFORUMS.com Forum Index MVSFORUMS.com
A Community of and for MVS Professionals
 
 FAQFAQ   SearchSearch   Quick Manuals   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Assembler - substring

 
Post new topic   Reply to topic   printer-friendly view    MVSFORUMS.com Forum Index -> Application Programming
View previous topic :: View next topic  
Author Message
raj051076
Beginner


Joined: 05 Dec 2002
Posts: 64
Topics: 21

PostPosted: Tue Dec 10, 2002 10:44 pm    Post subject: Assembler - substring Reply with quote

I was just wondering what wil be the equivalent of SUBSTRING in assembler. My requirement is I want to compare a part of a string with something. How do I do this with assembler.

I just started learning assembler and found that it is lot different from other languages.
_________________
Rajib
Back to top
View user's profile Send private message
kolusu
Site Admin
Site Admin


Joined: 26 Nov 2002
Posts: 12359
Topics: 75
Location: San Jose

PostPosted: Tue Dec 10, 2002 11:22 pm    Post subject: Reply with quote

raj051076,

Substring Notation

Hope this helps...

cheers

kolusu
Back to top
View user's profile Send private message Send e-mail Visit poster's website
raj051076
Beginner


Joined: 05 Dec 2002
Posts: 64
Topics: 21

PostPosted: Wed Dec 11, 2002 12:36 am    Post subject: Reply with quote

thanks kolusu....i will try this
_________________
Rajib
Back to top
View user's profile Send private message
RonB
Beginner


Joined: 02 Dec 2002
Posts: 93
Topics: 0
Location: Orlando, FL

PostPosted: Wed Dec 11, 2002 9:42 am    Post subject: Reply with quote

The reference that Kolusu points out is not used in direct assembly code. As the reference points out, "The substring notation can be used only in conditional assembly instructions." ( i.e. in assembler macros ). In direct code, substring notation is accomplished by coding the correct offset and length into the instruction itself, e.g.
Code:
MVC  TARGET+4(6),SOURCE+3

which would be equivalent to COBOL statement
Code:
MOVE SOURCE(3:6) TO TARGET(4:6)
Back to top
View user's profile Send private message
Bill Dennis
Advanced


Joined: 03 Dec 2002
Posts: 579
Topics: 1
Location: Iowa, USA

PostPosted: Wed Dec 11, 2002 10:44 am    Post subject: Reply with quote

Because Assembler offsets are relative to zero, the comparison should really look like this:
Code:
Code:
MVC  TARGET+3(6),SOURCE+2


which would be equivalent to COBOL statement
Code:
Code:
MOVE SOURCE(3:6) TO TARGET(4:6)


Regards.
Bill
Back to top
View user's profile Send private message
RonB
Beginner


Joined: 02 Dec 2002
Posts: 93
Topics: 0
Location: Orlando, FL

PostPosted: Wed Dec 11, 2002 12:30 pm    Post subject: Reply with quote

Right you are Bill. Thanks for the correction.

Ron
Back to top
View user's profile Send private message
nxn00
Beginner


Joined: 02 Dec 2002
Posts: 18
Topics: 0
Location: US

PostPosted: Wed Dec 11, 2002 5:51 pm    Post subject: Reply with quote

Rajib,

Could you please post the COBOL statement that you want to convert? Also the Working Storage definition of the fields being used.

If we see that, we can probably give you the BAL instruction to do the same thing.
_________________
Natalie
Back to top
View user's profile Send private message Send e-mail
Bill Dennis
Advanced


Joined: 03 Dec 2002
Posts: 579
Topics: 1
Location: Iowa, USA

PostPosted: Thu Dec 12, 2002 10:18 am    Post subject: Reply with quote

8) Another fun thing is using the EXecuted form of the instruction so you can vary the length of the compare by setting a value in a register.

Click on this link to read about the EXecute instruction.

Bill
Back to top
View user's profile Send private message
DaveyC
Moderator


Joined: 02 Dec 2002
Posts: 151
Topics: 3
Location: Perth, Western Australia

PostPosted: Thu Dec 12, 2002 10:37 am    Post subject: Reply with quote

Bills right, EX is the way to go for variable length strings.

A simple assembler program to convert character digits to a binary integer. The program is naturally re-entrant and expects a control block style work area to be passed.

Code:

CVB      CSECT                                                         
CVB      AMODE 31                                                       
CVB      RMODE ANY                                                     
         SAVE  (14,12)            .Save callers registers               
         LR    R12,R15            .R12=base                             
         USING CVB,R12            .Addressability                       
         ICM   R4,15,0(R1)        .-> Work area                         
         BZ    FAIL               .Null pointer !                       
         USING WORKAREA,R4        .Map the work area                   
         ICM   R2,15,STRLEN       .String length                       
         BZ    FAIL               .Br if null string                   
         L     R3,CNVSTR          .Start of string                     
         BCTR  R2,0               .Dec length by 1 for EX instr         
         EX    R2,PACK            .Convert number to decimal           
         CVB   R15,DWORD          .Convert number to long integer       
         B     EXIT               .Finsihed                             
FAIL     SR    R15,R15            .R15=>Null                           
EXIT     RETURN (14,12),RC=(15)   .Return converted integer             
PACK     PACK  DWORD,0(*-*,R3)                                         
*----------------------------------------------------------------------
WORKAREA DSECT ,                  .Input structure mapping             
CNVSTR   DS    A                  .->String to convert to an integer   
STRLEN   DS    F                  .Length of input digit string         
DWORD    DS    D                  .Double word work area for PACK       
*----------------------------------------------------------------------
         YREGS ,                  .Register equates                     
         END                                                           

_________________
Dave Crayford
Back to top
View user's profile Send private message Send e-mail
RonB
Beginner


Joined: 02 Dec 2002
Posts: 93
Topics: 0
Location: Orlando, FL

PostPosted: Thu Dec 12, 2002 11:08 am    Post subject: Reply with quote

Execute IS the way to go, but if you are not using fixed base+displacements for the source/target fields, it requires that you set registers to the actual addresses of the source/target base+displacement values before invoking the EXecute instruction. That's why I didn't mention it in my first post.

Ron
Back to top
View user's profile Send private message
DaveyC
Moderator


Joined: 02 Dec 2002
Posts: 151
Topics: 3
Location: Perth, Western Australia

PostPosted: Thu Dec 12, 2002 11:36 am    Post subject: Reply with quote

RonB,

Of course you're quite right. For fixed length buffers using EXecute is an inefficiency.
_________________
Dave Crayford
Back to top
View user's profile Send private message Send e-mail
RonB
Beginner


Joined: 02 Dec 2002
Posts: 93
Topics: 0
Location: Orlando, FL

PostPosted: Thu Dec 12, 2002 4:04 pm    Post subject: Reply with quote

While efficiency is not unimportant, readability and maintainability are more important ( in application code, that is - "blackbox" code that may be executed millions of times per run is quite another story ).
My rule-of-thumb is: if the LENGTH of the move/compare is VARIABLE ( i.e. determined at EXECUTION time), I use EXecutes; if the LENGTH of the move/compare is FIXED ( i.e. known at ASSEMBLY time ), I use direct code. Direct code is probably "clearer" to the reader, since it's "in-line", but EXecutes shouldn't be a foreign construct to an able programmer.

Ron
Back to top
View user's profile Send private message
Mervyn
Moderator


Joined: 02 Dec 2002
Posts: 415
Topics: 6
Location: Hove, England

PostPosted: Thu Dec 12, 2002 6:04 pm    Post subject: Reply with quote

Dave, you must be psychic! I identified a need for just that subroutine this afternoon! Thanks a bunch.

By the way, why do you use *-* in the length for the Pack? I would have used zero, but I have to admit that *-* is a good eyecatcher.

Cheers,
Merv
Back to top
View user's profile Send private message
DaveyC
Moderator


Joined: 02 Dec 2002
Posts: 151
Topics: 3
Location: Perth, Western Australia

PostPosted: Fri Dec 13, 2002 2:25 am    Post subject: Reply with quote

You are quite right, it's an eyecatcher. I probably copied it from a piece of code that I knocked up feeling a bit slack. Like this:

Code:

         BCTR  R4,0                  .Dec for "EX"                   
         PACK  DW,0(*-*,R5)          .Pack for "EX"                   
         EX    R4,*-6                .Convert number to Packed Decimal


I put the PACK just before the EXecute so I don't have to go searching for it. I'm not saying it's good programming practice but it's alright for Quick and Dirty... Of course, it costs you an extra instruction that does nothing !

Cricket's not too good mate. You can imagine the stick I'm having to face!!
_________________
Dave Crayford
Back to top
View user's profile Send private message Send e-mail
Mervyn
Moderator


Joined: 02 Dec 2002
Posts: 415
Topics: 6
Location: Hove, England

PostPosted: Fri Dec 13, 2002 5:01 pm    Post subject: Reply with quote

I'm lucky enough to have missed most of it. It's on the telly when I'm either in bed or at work. I'm so thankful our Rugby team beat the three Southern Hemisphere teams in successive weekends.

Your son must be having a great time though?
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic   printer-friendly view    MVSFORUMS.com Forum Index -> Application Programming All times are GMT - 5 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


MVSFORUMS
Powered by phpBB © 2001, 2005 phpBB Group