Page 1 of 2

Send a String to another variable

PostPosted: Tue Jul 17, 2012 6:55 pm
by utpalpal07
Hi Guys,

I have a string:
2768 IS A EVEN NO

I want to send 2768 in another variable using assembler prog.

how to do?

please help

regards
utpal

Re: string

PostPosted: Tue Jul 17, 2012 7:40 pm
by BillyBoyo
You mean you have some rule for obtaining a "sub-string" from a "string"?

Re: string

PostPosted: Tue Jul 17, 2012 7:42 pm
by utpalpal07
Hi Billy
I want to unstring the string.

Re: string

PostPosted: Tue Jul 17, 2012 8:34 pm
by BillyBoyo
I'm sure the "traditional" way still works. Use a byte-location field to wander along the contents of your "string" looking for a space. Once located, the length of the sub-string is known. Repeat until end-of-string.

Re: string

PostPosted: Tue Jul 17, 2012 11:05 pm
by utpalpal07
hi,
can you give an example how to compare upto space and save first part in a variable ?

regards
utpal

Re: string

PostPosted: Tue Jul 17, 2012 11:49 pm
by steve-myers
Well, I'm certainly not going to write any code for you considering how badly the "requirement" is documented, but you can use TRT to scan a string for a blank using this table -

FINDBLNK DC 0XL256'0',(C' ')X'00',X'04',(256-(*-FINDBLNK))X'00'

TRT will leave the address of the first blank in register 1. You have to prepare for the case where there are no blanks in the string, which I will leave as an exercise for you. With the address of the first blank in register 1, it is a simple matter to compute the length of the substring and copy the substring to another storage area using MVCL or by using the EX instruction to execute an MVC instruction.

FWIW, in some of my work in the last few months I have encountered this exact problem and used this technique to extract the substring.

Re: string

PostPosted: Wed Jul 18, 2012 12:06 am
by utpalpal07
Hi Guys,

Thanks for reply


       WORD='4567 IS A NUMBER'
       LA R14,WORD
       LA R15,L'WORD
LOOP   CLI 0(R14),C' '
      BE NEXT

*WHAT INSTRUCTION SHOULD I USE HERE
*SO THAT I CAN INSERT EACH DIGIT 1 BY 1

NEXT   LA R14,1(,R14)
      BCT R15,LOOP



Please help me:
which instruction should i use in the commented part so that i can insert digits 1 by 1.
It will solve my problem

Thanks & regards
utpal

Re: string

PostPosted: Wed Jul 18, 2012 12:23 am
by steve-myers
WORD='4567 IS A NUMBER' is not exactly Assembler!

To answer your question, check out MVC.

More often than not, I use reg 0 for the BCT counter register rather than reg 15 as you used. Reg 0 is not useful as an address register, so this is a good use for a register that is not used all that often.

Re: string

PostPosted: Wed Jul 18, 2012 12:26 am
by utpalpal07
Hello Steve,

I can use MVC once only. How to use it as a array/stack. So that until i get space MVC can insert a value into variable.

Thanks

Re: string

PostPosted: Wed Jul 18, 2012 5:58 am
by steve-myers
You have reg 14 that points to a byte that you have just tested. You will need a second register that points to a byte in the data area that will receive the byte. So you do

MVC 0(1,output-register),0(14)

after you have tested for the end of the substring.

Between NEXT and the BCT you will update the output register just like you update reg 14 in the NEXT instruction.

As I said earlier, and I think others have implied, more experienced Assembler programmers copy the substring in a single move after the end of the substring has been located. What you propose is certainly acceptable code, though slower than doing the block move.