HP3000-L Archives

August 2003, 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:
Walter Murray <[log in to unmask]>
Reply To:
Walter Murray <[log in to unmask]>
Date:
Mon, 4 Aug 2003 14:47:16 -0500
Content-Type:
text/plain
Parts/Attachments:
text/plain (89 lines)
 "Peter Smithson" <[log in to unmask]> wrote in message
news:MPG.19986d14d7e54b35989778@news.cis.dfn.de...
> I'm an MPE novice. (warning!)

Don't worry.  Experienced MPE programmers have been confused, and rightfully
so, on this point.

[snipped - questions about testing the condition code after an intrinsic
call in COBOL]

> So what's happening?  Does the COBOL interface re-define "2" to be "0" ?
> What else does it do?

What you're seeing is the COBOL idiom for testing the condition code.  I'll
try to explain, from a historical perspective.

On the classic 3000 there was a two-bit register called the condition code
register, which could be accessed programmatically as bits 6 and 7 of the
status register.  It was used for a number of purposes.

If you think of the condition code register as a two-bit unsigned binary
field, then its possible values are 0, 1, 2, and 3.  The value 0 is called
CCG.  The value 1 is called CCL.  The value 2 is called CCE.  The value 3 is
reserved.

One use of the condition code register was to indicate the result of an
arithmetic operation.  For example an ADD instruction would automatically
set the condition code to CCL, CCE, or CCG, depending on whether the result
was less than, equal to, or greater than zero.  Likewise, a CMP (compare)
instruction would set the condition code to CCL, CCE, or CCG, depending on
whether operand1 was less than, equal to, or greater than operand2.  You
could directly test the condition code using the BCC (Branch on Condition
Code) instruction.  You never actually had to know the numeric values used
for the three possible states of the condition code.

SPL provided syntax to access the condition code, so the SPL programmer
didn't need to know the numeric values either.

Because it was so efficient to set and test the condition code, many
intrinsics used it as a quick way to return pass/fail information.  For each
intrinsic, you could look in the intrinsics manual and see the meaning of
CCL, CCE, or CCG.  If you look at an intrinsics manual from those days,
you'll see that it doesn't even give the numeric equivalents for those three
possible values.  Nobody needed to know them.

To allow the COBOL programmer to test the condition code (which should be
done only in a simple IF statement immediately after returning from an
intrinsic call), the following convention was adopted.

Assign a name (for example, C-C) to the feature name CONDITION-CODE.
To test for CCL, write:
     IF C-C < 0
To test for CCE, write:
     IF C-C = 0
To test for CCG, write:
     IF C-C > 0

Looks pretty natural, doesn't it?  The COBOL programmer didn't have to know
that when testing:
     IF C-C = 0
the program was actually testing for a value of 2 in the condition code
register (binary 10 in bits 6:2 of the status register).

But other languages used different approaches for testing the condition
code.

In FORTRAN/3000 you used an arithmetic IF statement and tested ".CC.".  It
tested less than, equal to, or greater than zero, to signify CCL, CCE, or
CCG.

In FORTRAN 77, you call the CCODE function, which returns -1, 0, or 1 to
indicate CCL, CCE, or CCG.

In Pascal and C you also call a function named ccode, but it returns 1, 2,
or 0 to indicate CCL, CCE, or CCG.

The numeric values shown in current intrinsics manuals correspond to the
Pascal and C conventions and are there to confuse COBOL programmers.

I think I submitted an SR requesting that the documentation be improved.  If
I'm reading my notes correctly, it's SR 5003107565.

Hope this trip down memory lane was enjoyable and/or enlightening to a few.

Walter

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

ATOM RSS1 RSS2