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
 

 

Why we might need LH here?

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

New User


Joined: 06 Jan 2009
Posts: 88
Location: Ggn, IN

PostPosted: Tue Sep 13, 2011 9:23 pm    Post subject: Why we might need LH here?
Reply with quote

Code:
LH    R1,BIN2
SR    R1,R1     
STH   R1,BIN2


I believe there is no problem if we replace this with:

Code:
SR    R1,R1     
STH   R1,BIN2



Why do we have to load BIN2 into R1 and then subtract R1 from R1. We can directly subtract R1 from R1?
Back to top
View user's profile Send private message

enrico-sorichetti

Global Moderator


Joined: 14 Mar 2007
Posts: 10256
Location: italy

PostPosted: Tue Sep 13, 2011 9:28 pm    Post subject: Reply to: Why we might need LH here?
Reply with quote

out of context You are right
but then You might also use
Code:
         XC    BIN2,BIN2
if BIN2 is defined as an halfword
Back to top
View user's profile Send private message
nigelosberry

New User


Joined: 06 Jan 2009
Posts: 88
Location: Ggn, IN

PostPosted: Tue Sep 13, 2011 9:38 pm    Post subject: Re: Reply to: Why we might need LH here?
Reply with quote

enrico-sorichetti wrote:
out of context You are right
but then You might also use
Code:
         XC    BIN2,BIN2
if BIN2 is defined as an halfword



Yes. That's true.

I saw the piece of code i have pasted above in a program. the program is zeroising the RDW this way and it has used identical code multiple times for different. My first feeling was that the programmer perhaps forgot to remove the LH step and the error propogated through the program via copy-paste. The program looks to be running in production since years.
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: Tue Sep 13, 2011 10:55 pm    Post subject:
Reply with quote

Hello,

Quote:
The program looks to be running in production since years
Thenyou need to make a copy of the code before trying to change it. . .

Make sure that everywhere used, the goal is to zero BIN2 . . . How is R1 used after this code executes?

The code as posted just leaves me scratching my head . . . icon_confused.gif
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 Sep 14, 2011 2:05 am    Post subject: Reply to: Why we might need LH here?
Reply with quote

As you progress, one little "gotcha" that might burn you someday on something completely different (this burned ME a couple of times) -

If BIN were two-bytes (a HWORD) and for some reason was loaded on purpose (by some other means) with X'FFFF', which is decimal 65535 as an unsigned HWORD, when you issue a LH from BIN, the result in the assigned register will be X'FFFFFFFF', or negative one.

To get around this, define -

Code:

FWORD    DS     F

Clear FWORD to X'00's (via an XC instruction) and move BIN to FWORD+2.

Then, load the register from FWORD, using a LOAD instruction and your expected result (decimal 65535), will be in the register as a positive number.

You can also do -

Code:

         XR     R1,R1
         ICM    R1,B'0011',BIN

And the result in R1 will be X'0000FFFF' (65535-same as above).

Internally, Cobol compilers that support COMP-5 (Native Binary), use the ICM and STCM instructions quite often on HWORD's and FWORD's.

You can test BIN for a value that exceeds 32767 (X'7FFF') by using a TEST UNDER MASK instruction on the 1st-byte -

Code:

         TM     BIN,X'80'
         BO     EXCEEDS

HTH....

Mr. Bill
Back to top
View user's profile Send private message
nigelosberry

New User


Joined: 06 Jan 2009
Posts: 88
Location: Ggn, IN

PostPosted: Thu Sep 15, 2011 12:49 pm    Post subject:
Reply with quote

Quote:
. . . How is R1 used after this code executes?
The code as posted just leaves me scratching my head . . . icon_confused.gif


Here's the full code till exit point:

Code:
   
          ...
          ...     
          LH    R1,RDW1     
          SR    R1,R1           
          STH   R1,RDW1     
          LH    R1,RDW2     
          SR    R1,R1           
          STH   R1,RDW2     
          L     R3,SV3       
          L     R4,SV4       
 ROUT1X   DS    0H             
          L     R14,SVROUT1       * go back to mainline
          BR    R14       



Similar code is used in 5 different routines of the program. R1 is not used anywhere else (except during initialisation, parm read etc).
Back to top
View user's profile Send private message
enrico-sorichetti

Global Moderator


Joined: 14 Mar 2007
Posts: 10256
Location: italy

PostPosted: Thu Sep 15, 2011 1:08 pm    Post subject: Reply to: Why we might need LH here?
Reply with quote

well the coding is quite primitive..
there are zillions of alternatives to clear a storage location

if I were given a doctor' s prescription to use a register I would have used a different sequence ( and not R1)
something along the lines of
Code:
         XR   R15,R15
         STH  R15,<VAR1>
         STH  R15,<VAR...>
         STH  R15,<VARn>
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:



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