View previous topic :: View next topic |
Author |
Message |
raj051076 Beginner
Joined: 05 Dec 2002 Posts: 64 Topics: 21
|
Posted: Tue Dec 10, 2002 10:44 pm Post subject: Assembler - substring |
|
|
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 |
|
|
kolusu Site Admin
Joined: 26 Nov 2002 Posts: 12368 Topics: 75 Location: San Jose
|
Posted: Tue Dec 10, 2002 11:22 pm Post subject: |
|
|
raj051076,
Substring Notation
Hope this helps...
cheers
kolusu |
|
Back to top |
|
|
raj051076 Beginner
Joined: 05 Dec 2002 Posts: 64 Topics: 21
|
Posted: Wed Dec 11, 2002 12:36 am Post subject: |
|
|
thanks kolusu....i will try this _________________ Rajib |
|
Back to top |
|
|
RonB Beginner
Joined: 02 Dec 2002 Posts: 93 Topics: 0 Location: Orlando, FL
|
Posted: Wed Dec 11, 2002 9:42 am Post subject: |
|
|
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 |
|
|
Bill Dennis Advanced
Joined: 03 Dec 2002 Posts: 579 Topics: 1 Location: Iowa, USA
|
Posted: Wed Dec 11, 2002 10:44 am Post subject: |
|
|
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 |
|
|
RonB Beginner
Joined: 02 Dec 2002 Posts: 93 Topics: 0 Location: Orlando, FL
|
Posted: Wed Dec 11, 2002 12:30 pm Post subject: |
|
|
Right you are Bill. Thanks for the correction.
Ron |
|
Back to top |
|
|
nxn00 Beginner
Joined: 02 Dec 2002 Posts: 18 Topics: 0 Location: US
|
Posted: Wed Dec 11, 2002 5:51 pm Post subject: |
|
|
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 |
|
|
Bill Dennis Advanced
Joined: 03 Dec 2002 Posts: 579 Topics: 1 Location: Iowa, USA
|
Posted: Thu Dec 12, 2002 10:18 am Post subject: |
|
|
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 |
|
|
DaveyC Moderator
Joined: 02 Dec 2002 Posts: 151 Topics: 3 Location: Perth, Western Australia
|
Posted: Thu Dec 12, 2002 10:37 am Post subject: |
|
|
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 |
|
|
RonB Beginner
Joined: 02 Dec 2002 Posts: 93 Topics: 0 Location: Orlando, FL
|
Posted: Thu Dec 12, 2002 11:08 am Post subject: |
|
|
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 |
|
|
DaveyC Moderator
Joined: 02 Dec 2002 Posts: 151 Topics: 3 Location: Perth, Western Australia
|
Posted: Thu Dec 12, 2002 11:36 am Post subject: |
|
|
RonB,
Of course you're quite right. For fixed length buffers using EXecute is an inefficiency. _________________ Dave Crayford |
|
Back to top |
|
|
RonB Beginner
Joined: 02 Dec 2002 Posts: 93 Topics: 0 Location: Orlando, FL
|
Posted: Thu Dec 12, 2002 4:04 pm Post subject: |
|
|
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 |
|
|
Mervyn Moderator
Joined: 02 Dec 2002 Posts: 415 Topics: 6 Location: Hove, England
|
Posted: Thu Dec 12, 2002 6:04 pm Post subject: |
|
|
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 |
|
|
DaveyC Moderator
Joined: 02 Dec 2002 Posts: 151 Topics: 3 Location: Perth, Western Australia
|
Posted: Fri Dec 13, 2002 2:25 am Post subject: |
|
|
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 |
|
|
Mervyn Moderator
Joined: 02 Dec 2002 Posts: 415 Topics: 6 Location: Hove, England
|
Posted: Fri Dec 13, 2002 5:01 pm Post subject: |
|
|
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 |
|
|
|
|