View previous topic :: View next topic
|
Author |
Message |
nigelosberry
New User
Joined: 06 Jan 2009 Posts: 88 Location: Ggn, IN
|
|
|
|
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 |
|
|
enrico-sorichetti
Superior Member
Joined: 14 Mar 2007 Posts: 10873 Location: italy
|
|
|
|
out of context You are right
but then You might also use
if BIN2 is defined as an halfword |
|
Back to top |
|
|
nigelosberry
New User
Joined: 06 Jan 2009 Posts: 88 Location: Ggn, IN
|
|
|
|
enrico-sorichetti wrote: |
out of context You are right
but then You might also use
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 |
|
|
dick scherrer
Moderator Emeritus
Joined: 23 Nov 2006 Posts: 19244 Location: Inside the Matrix
|
|
|
|
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 . . . |
|
Back to top |
|
|
Bill O'Boyle
CICS Moderator
Joined: 14 Jan 2008 Posts: 2501 Location: Atlanta, Georgia, USA
|
|
|
|
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 -
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 |
|
|
nigelosberry
New User
Joined: 06 Jan 2009 Posts: 88 Location: Ggn, IN
|
|
|
|
Quote: |
. . . How is R1 used after this code executes?
The code as posted just leaves me scratching my head . . . |
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 |
|
|
enrico-sorichetti
Superior Member
Joined: 14 Mar 2007 Posts: 10873 Location: italy
|
|
|
|
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 |
|
|
|