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
 

 

Some Queries on Assembler-

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

Active User


Joined: 11 Apr 2008
Posts: 144
Location: Jamshedpur

PostPosted: Sun Sep 04, 2011 9:11 am    Post subject: Some Queries on Assembler-
Reply with quote

Hi All,

I am trying to learn assembler. I have following questions -

1. ST R15,8(,R13)
This statement means, store the content of R15 to a address which is 8 bytes from R13. Please confirm, if my understanding is incorrect

2. LR & ST both copies the content of one operand to another. Why do we have two codes for same operation. Is there more to LR & ST than just copying content?

3. Suppose, I execute a Assembler program which has wrong housekeeping code(which copies the existing values of registers before executing the main business logic) in that case, what will happen?
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: Sun Sep 04, 2011 9:54 am    Post subject:
Reply with quote

Hello,

For questions 1 & 2 read here (Principles of Operations):
http://publibz.boulder.ibm.com/cgi-bin/bookmgr_OS390/BOOKS/DZ9ZR003/CCONTENTS
Suggest you at least bookmark this (and possibly even download it so you have a working copy). Keep in mind that the online documentation may be changed and the local copy will not. . .

For question 3 - the results may be unpredictable. Most organizations that permit the use of assembler have "standard linkage" defined (often a cojple of macros) that are to be used in every program. You should use the standard linkage used on your system and not change it. . .
Back to top
View user's profile Send private message
Bill Woodger

DFSORT Moderator


Joined: 09 Mar 2011
Posts: 7236

PostPosted: Sun Sep 04, 2011 12:19 pm    Post subject: Reply to: Some Queries on Assembler-
Reply with quote

You might also want to get hold of this as something you can print and have with you (or find the equivalent physical one if you can/don't have it already).

You'll easily see here the different instruction formats. Whilst there might be many instructions "doing the same thing" they are only doing the same thing when poorly described in English, not when considering in full what they actually do.
Back to top
View user's profile Send private message
Robert Sample

Global Moderator


Joined: 06 Jun 2008
Posts: 7913
Location: Bellevue, IA

PostPosted: Sun Sep 04, 2011 5:44 pm    Post subject:
Reply with quote

Quote:
2. LR & ST both copies the content of one operand to another. Why do we have two codes for same operation. Is there more to LR & ST than just copying content?
Understanding the difference in these instructions requires you to understand the difference between a REGISTER and a MEMORY LOCATION. If you do not understand this, you cannot understand Assembler -- at all.
Back to top
View user's profile Send private message
Marso

REXX Moderator


Joined: 13 Mar 2006
Posts: 1219
Location: Israel

PostPosted: Sun Sep 04, 2011 6:30 pm    Post subject: Reply to: Some Queries on Assembler-
Reply with quote

I hope you have already bookmarked this site, which contains useful information.

You should learn about instruction formats:
LR is an RR instruction (Register/Register) and ST is an RX instruction (Register/Memory).

Also, most obviously, LR is LOAD and ST is STORE. Your instinct should tell you these are different things!
Back to top
View user's profile Send private message
Roger W Suhr

New User


Joined: 30 Aug 2010
Posts: 5
Location: Tobyhanna, PA, USA

PostPosted: Tue Oct 04, 2011 9:00 am    Post subject: Re: Some Queries on Assembler-
Reply with quote

saurabh39 wrote:
Hi All,

I am trying to learn assembler. I have following questions -

1. ST R15,8(,R13)
This statement means, store the content of R15 to a address which is 8 bytes from R13. Please confirm, if my understanding is incorrect.


==>This is correct, R15 is a symbolic for Register 15. ST stores the contents of Reg 15 at an offset of 8 bytes from the address currently in Reg 13.

Quote:
2. LR & ST both copies the content of one operand to another. Why do we have two codes for same operation. Is there more to LR & ST than just copying content?

==>LR is Load Register ==> copy one regiater to another
==>ST is Store ==> store the contents of a regiater in storage. Used to save register contents in storage. The opposite of ST is L (Load). L gets the content of a storage location and load it into a register (24 bit only). The high order 8 bits of the register are cleared.
Quote:
3. Suppose, I execute a Assembler program which has wrong housekeeping code(which copies the existing values of registers before executing the main business logic) in that case, what will happen?

==>Unpredictable results may occur, because some registers contain return addres (R14), entry point (R15), address of parameter lit (R1) and the calling programs savearea (R13) on enty. These registers must be preserved right after entry,and restoredbeforrturning control. Any subroutines (e.g,I/O routines of the OS will use those registers and therefore the original contents will be destroyed during executon.

Please refer to z/OS Principles of Operations manual for detailed descriptions of z/OS instructions.

edited to fix the weird formattting
Back to top
View user's profile Send private message
saurabh39
Warnings : 1

Active User


Joined: 11 Apr 2008
Posts: 144
Location: Jamshedpur

PostPosted: Wed Oct 05, 2011 8:15 pm    Post subject: Reply to: Some Queries on Assembler-
Reply with quote

@Roger - Thanks for your reply. But I have one basic question regarding the following reply -

Quote:
==>This is correct, R15 is a symbolic for Register 15. ST stores the contents of Reg 15 at an offset of 8 bytes from the address currently in Reg 13.


But a register is only of 4 bytes, so offset of 8 bytes will be outside the register.
Back to top
View user's profile Send private message
saurabh39
Warnings : 1

Active User


Joined: 11 Apr 2008
Posts: 144
Location: Jamshedpur

PostPosted: Wed Oct 05, 2011 8:21 pm    Post subject: Reply to: Some Queries on Assembler-
Reply with quote

Quote:
==>LR is Load Register ==> copy one regiater to another
==>ST is Store ==> store the contents of a regiater in storage. Used to save register contents in storage. The opposite of ST is L (Load). L gets the content of a storage location and load it into a register (24 bit only). The high order 8 bits of the register are cleared.


but isn't copying one register to another means you are copying the content of one register to another. I think probably LR will load the whole 32 bit as compared to ST which is loading 24 bit. Am i correct?
Back to top
View user's profile Send private message
Garry Carroll

Active Member


Joined: 08 May 2006
Posts: 990
Location: Dublin, Ireland / Edinburgh, Scotland

PostPosted: Wed Oct 05, 2011 8:33 pm    Post subject: Re: Reply to: Some Queries on Assembler-
Reply with quote

saurabh39 wrote:
@Roger - Thanks for your reply. But I have one basic question regarding the following reply -

Quote:
==>This is correct, R15 is a symbolic for Register 15. ST stores the contents of Reg 15 at an offset of 8 bytes from the address currently in Reg 13.


But a register is only of 4 bytes, so offset of 8 bytes will be outside the register.


A register is four bytes which contains a memory address. Offset of 8 bytes is another memory address. Neither address is WITHIN the register - just like a teacher's pointer is not within the blackboard. To move the teacher's pointer from the letter 'A' in the string 'ABCDEFGHI' to the letter 'I' requires incrementing the pointer location from 0 to 8.


LR takes the content of a memory address and loads it into the register. ST stores the contents of the register into a memory location.

Garry.
Back to top
View user's profile Send private message
Robert Sample

Global Moderator


Joined: 06 Jun 2008
Posts: 7913
Location: Bellevue, IA

PostPosted: Wed Oct 05, 2011 9:52 pm    Post subject:
Reply with quote

Tushar, I think you are completely confused at this point. Let's see if an example can help.

Code:
Memory address 1000-1003 contains 00002000
Memory address 2000-2007 contains 0102030405060708

         LA    5,X'1000' erases the previous contents of register 5 and loads X'1000' into register 5
         LR    6,5       erases the previous contents of register 6 and loads it with a copy of register 5
         L     7,0(5)    erases the previous contents of register 7 and loads it with X'2000' -- the CONTENTS of memory address 1000-1003
         L     8,4(7)    erases the previous contents of register 8 and loads it with x'05060708' -- the CONTENTS of memory address 2004-2007
         ST    8,0(5)    erases the previous value in memory address 1000-1003 and replaces it with X'05060708'
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: Wed Oct 05, 2011 11:15 pm    Post subject: Reply to: Some Queries on Assembler-
Reply with quote

Robert,

An LA has a maximum of 4095.

Use LHI instead, which has a maximum of 32767.

Mr. Bill
Back to top
View user's profile Send private message
Roger W Suhr

New User


Joined: 30 Aug 2010
Posts: 5
Location: Tobyhanna, PA, USA

PostPosted: Thu Oct 06, 2011 6:44 am    Post subject: Re: Reply to: Some Queries on Assembler-
Reply with quote

Ok, here is where many new assembler programmers get confused:

There are multiple instructions that are dealing with registers, eac in it'sown special way. Here are some load and store instructions. The are all in the RX instruction format,meaning the first operan is a register, the second is a reference t a storage location. Depending onthe instructions purpose they operate fromlefttoright (STORE#, or fromright toleft #LOAD):

L > LOAD ; e.g. L R1,0(0,r13# Loading the contents of a storage location pointed to by R13 in the lenght of the register #32 bits = 4 bytes#, but only 24 bits are useful for addressing in 24 bit mode. #in this example displacement 0#
any other displacement will be added to the address in R13. The second 0 in the example is an index register which usually not used or 0 #Reg 0#, whic is a special case because r0 contents are never used in that way and are always 0.#

LH > LOAD HALFWORD LH R1,0#0,R13# Loads 4 bytes from the storage location at displacement 0 of the address pointed to by R13 #just as L, but only 2 bytes = halfword#

LA > LOAD ADDRESS R1,0#R13# Loads the ADDRESS of the storage location pointed to by R13 #plus the displacement#, so LA R1,8 wouldbe interpreted as LA R1,8#0# resultingi n 8 being placed into R1. because R0 is always zero in these instructions.#

Also, don'tbe confused by the mnemonic R1, R13 etc. these symbolics have to be established an EQU #EQUATE# assebler instruction before they can be used in this way eg: R1 EQU 1 #This doesn't genereate code, but it tells the assembler to substitute 1 whenever R1 is coded etc.

ST >.STORE ST R1,0#,R13# STORES the whole content of R1 into memory #aka storage# at the location pointed to by R13#

STH > STORE HALFWORD STORES 2 bytes #Halfword# into the mmory location pointed toby R13.

There is NO STORE ADDRESS #no opposite of LA#

There are also LM and STM. These are used to store/load multiple registers

Upon entry the assembler programmer should first store the current registersat a memory location provided by the calling program in R13

Here is a typical code sequence that is often done in a macro,because it's so repetitive.

Code:
PGM1  CSECT
         EQUREG       <=== This macro does the register equates
         STM   R14,R12,12#R13#     SAVE CALLER'S REGS  <Store multiple
* Stores R14,R15,R0,R1 ... R12 intp a savearea provided by the calling
* program at displacement 12 # 3 fullwordsi nto the SA#
         LR    R12,R15             ESTABLISH THIS PGM'S ADDRESSABILITY
* This saves the entry point address in R12
         USING PGM1
* This tells the assembler to use R12 as a base register for this program
         LA    R15,SAVEAREA        ESTABLISH SAVEAREA LINKAGES
         ST    R13,4#R15#
* This stores the current savearea pointer at loction 4 of the new
*   save area
         ST    R15,8#R13#
* This stores new save area pointer at location 8of the old save area
* now you can always back trace each program call in memory,
* all the way to the initial TCB creation.
         LR    R13,R15
* This is done to make R13 point to the current save area #for futue
*  subprogram calls
* Be carefull not to use your base registers AND R13 for anything in your
* program
         ST    R1,PARMPTR          SAVE ORIGINAL PARM ADDRESS
* This stores the pointer to the Parameter list #in R1# in a extra save area
* not really necessary, since you stored all etry registers already,
* but easier to find if you need them later.
         L     R15,0#R1#           Parm  POINTER
* this load the addres of the first parameter into R15
*   This would point to an area where the JCL PARM from the EXEC
*   statement can be found #if program was executed from JCL
*  the format of that would be a 2 byte field for  the lenght (max 100
*  bytes# followed by the parm field


Here is the code to return to caller:

Code:
RETURN   L     R13,4#R13#
* Load address of Higher SA #savearea#
         LM    R14,R12,12#R13#
*  load all registers save at entry
         XR    R15,R15                 Clear R15 #return code 0#
         BR    R14                  return control to caling program
* upon entry the calling programs retiurn address should be in R14
*   #That is usually setup by the calling program using BAL 
*   but that is material for another class

SAVEAREA  DC   18f'-1'  DEFINES AND IITIALIZES A NEW SAVE
* AREA FOR SUBSEQUENT CALLS TO OTHER PROGRAMS         

These are only exampleof how this can be accomplshed, there are as many ways as there are programmers, but the linkage conventions should be observed, or unpredictable results may occur.

uopn entry
Code:
 R1 points to parmlist
                 R13  points to higher save area
                 R14  points to return address
                 R15  points to entry point of the currrent program


before any work in a program is done the followin shouldbe established:

R14 through R12 should be save in the higher save area at displacement 12 #3 fullwords into the SA#

saveareas should be linked to allow back tracing #and to allow restoring te entry registers beforereturnin control#

R13 should be pointing toa new save area aka LSA #lower save area#

R1, R13, R14 and R15 should never be used by the application in the program as they are used by subprograms, I/O routines etc., and are therefore unpredictable. They should only be used for subprogram linkage,but of course you are free to use them for quick intermediate work as long as you don't expect them to stay the way you used them fora longer time.
Many programmes #including IBM# have developed entry and exit macros to standardize this process #Lookup SAVE,RETURN macros in the IBM assembler macro reference#

Really, I cannot retype all the assembler books and principles ofoperations here.
Go to the book store and get yourself a good assembler text book, ad thumb around in PoO. Then go try it out, get a dump and try to find your regs and program storage in te dump. Look carefully at the asseblerlisting as it will show you how each instruction is translaed into machine code.

Good luck
Back to top
View user's profile Send private message
Nic Clouston

Global Moderator


Joined: 10 May 2007
Posts: 1715
Location: UK

PostPosted: Thu Oct 06, 2011 10:00 am    Post subject:
Reply with quote

Would help if you used ( and ) instead of # because I think you sometimes meant #. Perhaps a moderator could edit it?
Back to top
View user's profile Send private message
enrico-sorichetti

Global Moderator


Joined: 14 Mar 2007
Posts: 10203
Location: italy

PostPosted: Thu Oct 06, 2011 10:24 am    Post subject: Reply to: Some Queries on Assembler-
Reply with quote

tried to, but too much work
the post is so badly formatted that even with a cut and paste in a decent editor it will take a long time

it would be wise when posting <semi formatted> <things> to use lines shorter than,
let' s say, 80/100 chars rather then relying on the autoreflow behavior of the <browser>

it makes easier for the moderators to take care of things
usually for a long post it is easier to cut and paste the post into an editor and put it back
( in this case the cut lines are very loooooog )

and since the # need to be changed to ( and ) thingies it must be done by hand rather than with an edit change icon_wink.gif
Back to top
View user's profile Send private message
Nic Clouston

Global Moderator


Joined: 10 May 2007
Posts: 1715
Location: UK

PostPosted: Thu Oct 06, 2011 2:39 pm    Post subject:
Reply with quote

bummer icon_exclaim.gif
Back to top
View user's profile Send private message
Roger W Suhr

New User


Joined: 30 Aug 2010
Posts: 5
Location: Tobyhanna, PA, USA

PostPosted: Thu Oct 06, 2011 5:14 pm    Post subject:
Reply with quote

Nic Clouston wrote:
Would help if you used ( and ) instead of # because I think you sometimes meant #. Perhaps a moderator could edit it?


Sorry about tha. I actually typed "(",but somehow i was replaced by "#".
I didn't want to spend the times to set it back.
Back to top
View user's profile Send private message
enrico-sorichetti

Global Moderator


Joined: 14 Mar 2007
Posts: 10203
Location: italy

PostPosted: Thu Oct 06, 2011 5:19 pm    Post subject: Reply to: Some Queries on Assembler-
Reply with quote

Quote:
I didn't want to spend the times to set it back.

thank You very much for expecting a moderator to waste his time because Your laziness icon_evil.gif
Also Your last post was pretty sloppy !
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 Online Assembler Program Starting point Aditya.Srivastava PL/I & Assembler 4 Fri Jul 08, 2016 6:48 pm
This topic is locked: you cannot edit posts or make replies. MVS Assembler profiles for Pune Locat... shailesh_do Mainframe Jobs 0 Mon Feb 22, 2016 6:21 pm
No new posts ASRA abend calling Assembler from CICS surya8 PL/I & Assembler 13 Thu Sep 10, 2015 7:50 pm
No new posts Is Enterprise PL/I v4.2 compatible wi... sundarkudos PL/I & Assembler 2 Wed Aug 19, 2015 11:15 pm
No new posts Assembler Code to check normal retur... amitc23 PL/I & Assembler 6 Mon Aug 17, 2015 3:52 pm


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