Assist Question



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

Assist Question

Postby Susansuth » Fri Oct 17, 2014 5:11 am

Hello!

I am a student in an Assembler language class and we are using Assist for the programming.

I've had some confusion when working on my assignments on using L, LR, LA and ST for storing/loading and C/CR for comparing. The book isn't really clear on these insofar as what is used when in a program, and I seem to constantly having my debugging errors coming back to how I'm using these commands incorrectly.

This is what I'm understanding, based on what I've been taught in class and what I've read in the book.

ST R1, D(X,B) - This stores the contents of R1 into the fullword indicated at D(X,B).

So if my R1 had the number 12 in it, and I was storing it at an address labeled STORE, store would then have the value of 12, but it would still retain its original address, right?

So if I did a command like ST R1, 0(R2), R2 would contain 12, but it would have the same address as it did before.

I think that's my biggest confusion. I'm trying to use registers as pointers in my program. I want the register to remain pointing at the address where it's pointing, but I want the value that is in that pointed address to change in some way.

How do the different commands work in that regard?

I understand LA is "load address".

If I have a command, LA R2, R3, R2 would now point to R3, which would mean that its "value" or the contents would be the value/contents of R3. But what about L 2,0(3)? Is that loading the address or the value?

It's very confusing to me for some reason, and I keep putting the wrong thing in the program and I get abends or very weird results. :D

I'm currently working on a selection sort, and I'm trying to differentiate between pointers and the values they point to so that I can work through the sort. While I can get it to compile, it's not running properly and giving me correct results. I figure it has to do with these commands again.

Any help would be very appreciated to help me understand it better. I do want to get through the homework assignment, of course, but I actually want to understand and learn so that I won't continue to have problems as I go forward.

Thanks in advance!

Susan
Susansuth
 
Posts: 15
Joined: Tue Oct 07, 2014 8:36 am
Has thanked: 9 times
Been thanked: 0 time

Re: Assist Question

 

Re: Assist Question

Postby steve-myers » Fri Oct 17, 2014 7:25 am

Issue 1

You have, I presume
         ST    R1,STORE
         ...
STORE    DS    F

After the instruction completes, the contents of STORE should match the contents of register 1. The contents of register 1 will not change. I don't understand what you mean by "... it would still retain its original address, right?" The address of STORE? No, that will not change.

Issue 2

ST R1,0(R2) with the contents or R2 = 12.

This is the same as

ST R1,0(R2,0)

The result will be an ABEND almost 100% of the time. The computer attempts to compute an address by adding 0 (the displacement in the instruction) to the contents of register 2 and it then attempts to store the contents of register 1 in that address. In most systems storage location 12 is protected from being updated by most programs, so your program will be abnormally terminated.

Issue 3

"I'm trying to use registers as pointers in my program."

That's fine. The register must have a valid address. Let's combine issues 1 and 2.
         LA    R2,STORE
         ST    R1,0(R2)
The LA instruction computes the address of STORE and stores the address in register 2. The ST instruction stores the contents of register 1 in STORE because register 2 has the address of STORE..

Issue 4

I'm not sure what you mean by "LA R2, R3, R2" Do you mean LA R2,R3(R2)? In some ways "Load Address" is a misnomer. It really should be "Do arithmetic." Unfortunately, too, is a beginner can easily confuse R3 as being "register 3." It is nothing of the sort. It is just a value - usually 3. It is a register only if it is used in an instruction where a register is being specified. In R3(R2), R3 is just a value , 3, that will be added to the contents of register 2. By the way, most programmers would use 3(R2), not R3(R2).

These users thanked the author steve-myers for the post:
Susansuth (Fri Oct 17, 2014 10:10 am)
steve-myers
Global moderator
 
Posts: 1885
Joined: Thu Jun 03, 2010 6:21 pm
Has thanked: 4 times
Been thanked: 197 times

Re: Assist Question

Postby Susansuth » Fri Oct 17, 2014 7:39 am

Thank you so much for trying to help me with my rambling not-making-too-much-sense question. :D I really appreciate it!

I think the thing that is confusing me the most is this one.

I've got a register pointing to an address in a table. I want to keep that register pointing to that particular address.

But I want to switch the value inside the address it is pointing to to a different value. Doing a swap of the values between two registers but not losing the addresses to which they are pointing.

I've tried a couple of different things, but I'm not sure it's working.

If I do this:

ST 2, SWAP

Will it store the address of 2 into swap or the value of what 2 is pointing to?

And if I do this:

L 2, SWAP

Will it load SWAP's address into 2 or will it load the value in SWAP into 2? And will 2 continue to point to the address it was pointing to before SWAP was loaded into it?

Thanks very much for your help! I'm sorry I wasn't very clear in my questions. I've been working on this assignment for the better part of the day and my brain's a little fried. :)

Susan
Susansuth
 
Posts: 15
Joined: Tue Oct 07, 2014 8:36 am
Has thanked: 9 times
Been thanked: 0 time

Re: Assist Question

Postby steve-myers » Fri Oct 17, 2014 8:40 am

Susansuth wrote:... I've got a register pointing to an address in a table. I want to keep that register pointing to that particular address. ...
For the most part, a register is not altered unless your program executes an instruction to alter the register. There are a few exceptions. TRT (Translate and Test) may alter registers 1 and 2. EDMK (Edit and Mark)may alter register 1. LM x,y,address will alter registers with an intermediate value between x and y. In other words, LM 2,5,address will alter registers 3 and 4 as well as registers 2 and 5.

L 2,SWAP will load the contents of SWAP into register 2.

LA 2,SWAP
L 2,0(2)

The LA instruction will compute the address of SWAP and store it in register 2. The L instruction will load the contents of SWAP because register 2 has the address of SWAP.

These users thanked the author steve-myers for the post:
Susansuth (Fri Oct 17, 2014 10:10 am)
steve-myers
Global moderator
 
Posts: 1885
Joined: Thu Jun 03, 2010 6:21 pm
Has thanked: 4 times
Been thanked: 197 times

Re: Assist Question

Postby Susansuth » Fri Oct 17, 2014 8:53 am

That does make sense. Thank you so much for the speedy reply!

I just want to clarify something.

If R2 is pointing to the first fullword in TABLE (a storage of fullwords in memory) and you do this:

L 2,SWAP

Will R2 still be pointing to TABLE after the L command is performed? And the first fullword in TABLE will now be what was in SWAP?

Another thing I'm curious about is the C/CR commands.

CR R7,R8 compares the contents of register 7 and 8, correct?

Can you do this: C 7,0(8) and compare the addresses 7 & 8 are pointing to? Or does C not work that way?

Thanks again for your help and answering me so quickly. This really is helpful. :)

Susan
Susansuth
 
Posts: 15
Joined: Tue Oct 07, 2014 8:36 am
Has thanked: 9 times
Been thanked: 0 time

Re: Assist Question

Postby steve-myers » Fri Oct 17, 2014 9:54 am

Last one for today.

Issue 1 -

L 2,SWAP

will replace the contents of register 2 with the contents of SWAP. Any previous data will be lost.

Issue 2 -

CR R7,R8 compares the contents of register 7 with the contents of register 8. The condition code will reflect the result of the compare as documented in Principles of Operation.

Issue 3 -

Can you do this: C 7,0(8) and compare the addresses 7 & 8 are pointing to? Or does C not work that way?


No, it does not work that way.

The C instruction uses 0(8) to compute a storage address. It then compares the contents of register 7 with the contents of the storage location.

If you want to compare storage addresses you do something like this -

LA 0,address1
LA 1,address2
CR 0,1

The LA instructions compute the storage addresses and store them in registers. The CR instruction then compares the addresses as though they are data.

These users thanked the author steve-myers for the post:
Susansuth (Fri Oct 17, 2014 10:10 am)
steve-myers
Global moderator
 
Posts: 1885
Joined: Thu Jun 03, 2010 6:21 pm
Has thanked: 4 times
Been thanked: 197 times

Re: Assist Question

Postby Susansuth » Fri Oct 17, 2014 10:11 am

That clarifies things for me a lot.

I really really appreciate you getting back to me so quickly so many times! :)

I am going to try some of your suggestions tomorrow. Hopefully, they will work for me and my code!!

Susan
Susansuth
 
Posts: 15
Joined: Tue Oct 07, 2014 8:36 am
Has thanked: 9 times
Been thanked: 0 time

Re: Assist Question

Postby steve-myers » Sat Oct 18, 2014 12:46 am

Your questions make me think you're trying to do a "bubble" sort. I shouldn't, but I'll give you a freebie, along with a few questions you'll have to try to answer.
         LA    4,4           
         LA    5,TABEND       
         LA    2,TABLE       
SORT0100 LR    3,2           
         BXH   3,4,SORT0400   
SORT0200 L     0,0(,2)       
         L     1,0(,3)       
         CR    0,1           
         BNH   SORT0300       
         ST    1,0(,2)       
         ST    0,0(,3)       
SORT0300 BXLE  3,4,SORT0200   
         BXLE  2,4,SORT0100   
         DC    H'0'           
SORT0400 ...
TABLE    DC    F'50,1,0,-2'   
TABEND   EQU   *-L'TABLE
The code uses the BXH and BXLE instructions, which most beginners avoid like the plague. Or considering current events, perhaps I should say Ebola!

The code starts by setting register 2 to the address of TABLE, register 4 to the length of each entry in TABLE, and register 5 to the address of the last entry in TABLE. Registers 4 and 5 are not altered after they are set.

SORT0100 copies the address in register 2 to register 3. The BXH instruction does three things.
  1. It adds the contents of register 4 to the contents of register 3.
  2. It compares the contents of register 5 with the contents of register 3
  3. If the contents of register 3 are greater than the contents of register 5, the instruction branches.
Now that wasn't so hard, was it? If you understand this BXH, the BXLE instructions shouldn't be too hard to understand.

Now for some questions.
  1. TABEND defines the address of the last entry in TABLE. The two keys to how it works are how the Assembler interprets *, and how it interprets L'TABLE. You will probably have to dig around HLASM V1R6 Language Ref to find the answers, but try. Since you probably don't know how to find these manuals online, I've given you the hyperlink, too. I think Assist follows the rules in the manual.
  2. The DC H'0' after the second BXLE is an invalid instruction, but it is never executed because the BXLE always branches. Why does the BXLE always branch? I'll give you a BIG hint: the BXH after SORT0100.
  3. You don't really have to answer this, but try it anyway. The instruction names for BXH and BXLE are Branch on IndeX High and Branch on IndeX Low or Equal. I think these names were designed to fool programmers coming from the IBM 704/709/7040/7044/7090/7094 series of computers. These computers had three "index" registers and were much more important in programming than general purpose registers being used as "index" registers in System/360. A better name for the instructions should be "Branch on Value High" and "Branch on Value Low or Equal." In my example, registers 2, 3 and 5 represent addresses, not indexes. What changes to the program would be required to uses registers 2 and 3 as index registers? It's not really as much as you might initially think!

These users thanked the author steve-myers for the post:
Susansuth (Sat Oct 18, 2014 1:49 am)
steve-myers
Global moderator
 
Posts: 1885
Joined: Thu Jun 03, 2010 6:21 pm
Has thanked: 4 times
Been thanked: 197 times

Re: Assist Question

Postby Susansuth » Sat Oct 18, 2014 1:49 am

Wow! Thank you very much! I appreciate the example and the questions to go digging for! I will try to work on those questions and see what I can come up with. I probably cannot use #1 in my code since we have not gone over that in class or in the book to this point. But I am going to read about it and see what that's about. Thank you for the link to the manual, because you're right. My attempts to find documentation and help online have been pretty futile. I was pumped to find this forum! :)

Our assignment is actually a selection sort. I'm working off some pseudo code I have on our assignment for the selection sort and trying to convert it into real code. The added complication is that the sort is a subroutine. So, we have a table defined in Main, we build it one routine, print it in another, and then sort it in a third, calling the print routine again to print out the sorted table.

So all my table references are back in main, which I can access through two registers I import into the routine from main. I'm allowed a beginning table reference and an end of the table reference to import. Everything else is all me. *smile*

I've got build and print working. Sort compiles and apparently runs, but right now, it's repopulated the entire table with the same number--a number that isn't on the list of the input file numbers we were provided. *G* So I have no idea what I'm doing wrong. I figure, since most of the code is pretty straightforward, it has to do with my loading/storing/comparing of numbers. I had errors on those sorts of things on my last assignment as well, which, when fixed, had the program fall in place pretty rapidly. So I've determined I really want to sit down and figure out why I keep writing those commands incorrectly or, rather, using them incorrectly so I won't keep spending 5-6 hours unable to find my errors and having to ask for help to point out where I'm going wrong. :)

I really appreciate your taking time to help me out. I have to tackle the assignment before tomorrow, so I'm going to work on that now, but once I get that done, I'm going to play with your questions and see if I can't find good answers! :)

Susan
Susansuth
 
Posts: 15
Joined: Tue Oct 07, 2014 8:36 am
Has thanked: 9 times
Been thanked: 0 time

Re: Assist Question

Postby steve-myers » Wed Oct 22, 2014 4:26 pm

D(X,B)

This is the common notation in Principles of Operation for the computation of a storage address for a group of instructions collectively call RX instructions.
steve-myers
Global moderator
 
Posts: 1885
Joined: Thu Jun 03, 2010 6:21 pm
Has thanked: 4 times
Been thanked: 197 times

Next

Return to Assembler

 


  • Related topics
    Replies
    Views
    Last post