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.
Joined: 14 Jan 2008 Posts: 2504 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 -
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 -
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 -