> Date: Fri, 25 Mar 2005 00:43:52 -0700
> From: James Giles <[log in to unmask]>
> robin wrote:
> >> Date: Wed, 23 Mar 2005 17:39:06 -0700
> >> From: James Giles <[log in to unmask]>
> ...
> >> Before C the most common "under the hood" implementation
> >> of logicals I came across was negative means .true. and positive
> >> means .false. That's because almost all hardware had a conditional
> >> branch based on the sign bit of an operand register.
> >
> > Hardware also had conditionals based on zero/non-zero,
> > and thus 0 = false and 1 = true is equally possible,
> > and more convenient, particularly when logical hardware
> > instructions are used (e.g., for x .or. y, and x .and. y
> > etc.) [...]
>
> The sign bit is *exactly* as convenient.
That's an interesting thought. Some ones complement machines generate
a word of ones for certain arithmetic operations (e.g. 5 + (-5) equals -0 ),
so that 'zero' tests as a negative number.
> Logical hardware
> instructions operate on the sign bit too (and all the other bits).
Some do, some don't. Take the TM instruction on the IBM System 390.
(A numeric comparison on the same machine sets a condition
code register.)
(BTW, was it the B5000 series that was bit addressable?)
> As correctly pointed out by another, the canonical representation
> and the testing method are somewhat independent. Assuming two's
> complement integers, the canonical representation that travels best
> is -1 for true and 0 for false.
No it's not.
1. Negative 1 presents problems when it is desired to convert
logical to integer. Logical stored as 0 and 1 convert easily to numeric 0 and 1.
Which is what the orginal enquirer wanted to do.
2. Negative 1 is not typically a number that machines universally
generate simply or economically.
But positive 1 is more convenient to generate as a constant.
3. Machines treat comparisons in quite different ways.
There was at least one machine that used a logicize instruction
to produce 0 and 1 following a comparison. (Is the purpose
obvious?)
Others rely on setting condition code registers.
4. A statement such as A = B .GT. C produces either positive,
or negative, or zero, when B and C are subtracted. If such a value
were used as the logical result, that value would be neither negative 1
nor zero for most cases.
> With that pair of canonical values,
> you can use hardware branches based on sign, zero/nonzero, even/odd,
> or any other bit you like. And the hardware AND, OR, XOR and
> such all operate just fine.
> --
> J. Giles
|