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?
Joined: 23 Nov 2006 Posts: 19243 Location: Inside the Matrix
Hello,
For questions 1 & 2 read here (Principles of Operations):
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. . .
Joined: 09 Mar 2011 Posts: 7309 Location: Inside the Matrix
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.
Joined: 06 Jun 2008 Posts: 8700 Location: Dubuque, Iowa, USA
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.
Joined: 30 Aug 2010 Posts: 5 Location: Tobyhanna, PA, USA
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.
==>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?
Joined: 08 May 2006 Posts: 1205 Location: Dublin, Ireland
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.
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'
Joined: 30 Aug 2010 Posts: 5 Location: Tobyhanna, PA, USA
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.
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