[comp.arch] Booleans

firth@sei.cmu.edu (Robert Firth) (05/07/87)

Please permit me to agree with John Mashey concerning
the representation of Booleans and the use of branches
involving comparisons against zero.

A BEQZ/BNEZ instruction is very useful, because a large
number of comparisons involve tests against zero.  This
includes not merely integer tests, but things like

	IF b THEN...
	IF ch = NUL THEN...
	IF ptr = NIL THEN...

or the equivalent in other languages. All of these become
a test of a variable against binary (all zero).  A quick
check though some systems code showed that these idioms
together outnumbered tests on the sign bit of an integer.

Given such an operation, it is clearly better to represent
Boolean values by (FALSE=>0, TRUE=>something else), and
the best value for TRUE is 1, since that is what C, Pascal
and Ada expect.  This also allows an orthogonal treatment
of Boolean arrays: the extract delivers the bit at the right
of the destination word, just as a byte or bit-field extract
would.

Of course, it is a different question whether to provide a
complete set of branches; but if only some branches are to
be provided, then a test against zero seems preferable to a
test against the top bit.