HP3000-L Archives

May 2004, Week 1

HP3000-L@RAVEN.UTC.EDU

Options: Use Monospaced Font
Show Text Part by Default
Show All Mail Headers

Message: [<< First] [< Prev] [Next >] [Last >>]
Topic: [<< First] [< Prev] [Next >] [Last >>]
Author: [<< First] [< Prev] [Next >] [Last >>]

Print Reply
Subject:
From:
Bill Cadier <[log in to unmask]>
Reply To:
Bill Cadier <[log in to unmask]>
Date:
Wed, 5 May 2004 16:21:56 -0600
Content-Type:
text/plain
Parts/Attachments:
text/plain (81 lines)
Ray asks an interesting technical question:

> Hi all,
>
> Given the following WS:
>
>
> 01  TEST-RANGE-SW                       PIC X(1).
>       88  TEST-RANGE                             VALUE "B" THRU "Y".
>
> Does the compiler generate code that determines (binary search, etc.) that a variable (or
constant)
> is out of the acceptable range, or does the >compiler actually generate code that would result
in an
> evaluation  of each condition one at a time?
>
> For example, I could create the self explanatory manual code:
>         IF "A" < "B"
>           PERFORM FOUND-IT.
>
> Or I could do this, but would the code have to check for every value of "B" through "Y" to
determine
> that "A" was not in TEST-RANGE?
>         MOVE "A" TO TEST-RANGE-SW
>        IF NOT TEST-RANGE
>         PERFORM FOUND-IT.
>
> TIA for your time,
>
> Ray Shahan

COBOL is only checking the boundary values of an 88 item using "thru" and not checking
each value in the range. To determine this I added

CALL INTRINSIC "DEBUG".
IF NOT TEST-RANGE ...

This is the code emitted by the COBOL 85 compiler for that statement is:

000051c4  thrutest+$4c     43740060  LDB      48(sr0,r27),r20
000051c8  thrutest+$50     34150084  LDO      66(r0),r21
000051cc  thrutest+$54     82b44012  COMBT,<,N r20,r21,thrutest+$64
000051d0  thrutest+$58     43760060  LDB      48(sr0,r27),r22
000051d4  thrutest+$5c     340100b2  LDO      89(r0),r1
000051d8  thrutest+$60     8036604a  COMBT,<=,N r22,r1,thrutest+$8c
000051dc  thrutest+$64     { code here executed if the value is not in TEST-RANGE }

A brief and probably unnecessary explanation of this is:

The LDB is a load byte and r27 is architected "SP" or the stack pointer so the value being
compared against the 88 range is at sp+48. The "LDO" instructions are just "moves" of the
boundary values of the range, 66 ("B") and 89 ("Y"). The COMBT instructions are "compare
and branch if true" with different completors < (less than) and <= (less than or equal) and
with different destinations. So the 6 statements above equate to something like this

Load sp+48 into r20
Move 66 ("B") to r21
If r20 < r21 ("B") Then GO TO offset 0x64
Load sp+48 into r22
Move 89 ("Y") to r1
If r22 <= r1 ("Y") Then GO TO offset 0x8c else fall thru to offset 0x64

Or even more simply

If (sp+48 < 66) OR (sp+48 > 89) Then sp+48 is not in range of the 88 level item.

By the way, the ",N" in both comparisons specifies nullification. In the case of taken forward
branches or failed (not taken) backward branches the instruction following the compare is
nullified or in English... just skipped.

hth,

Bill
hp/vCSY
===========================================
  Reply to: bill . vcsy -at- comcast . net
===========================================

* To join/leave the list, search archives, change list settings, *
* etc., please visit http://raven.utc.edu/archives/hp3000-l.html *

ATOM RSS1 RSS2