🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

5 total messages Started by Tim Rentsch Mon, 12 Oct 2026 08:46
Re: two's complement and Flags (Re: arithmetic and endian history)
#50
Author: Tim Rentsch
Date: Mon, 12 Oct 2026 08:46
28 lines
2736 bytes
John Levine <johnl@taugh.com> writes:

> According to Tim Rentsch  <tr.17687@z991.linuxsc.com>:
>
>>> There's more but you get the idea.  I still do not understand why
>>> [the 704] subtracted rather than adding the index registers, but they
>>> definitely did a two's complement subtraction.
>>
>> I offer a possible (plausible?) explanation.  The decision to use
>> subtraction was made in conjunction with how looping worked.  If
>> we want to go through an array in ascending order, by basing
>> indexed accesses on the end of an array, effective addresses are
>> ascending while the index value is decreasing.  Doing that lets
>> the end-of-loop test be a comparison against zero rather than a
>> comparison to some (non-zero) upper bound.
>>
>> I think this proposed explanation is consistent with the example
>> given on page 10 (which doesn't talk about looping) and with the
>> description of the "Transfer on Index" instruction give on page 25
>> (which clearly is meant to be used with looping). ...
>
> That's certainly one of the more common guesses people have made.
> On the other hand, the TIX instruction adds its decrement field
> to an index register, but since the decrement is the same size as
> the index, if you want to count down you just make the decrement
> two's comp -1. [...]

Did you misread the description of the TIX instruction?
Re: two's complement and Flags (Re: arithmetic and endian history)
#59
Author: John Levine
Date: Mon, 12 Oct 2026 17:37
28 lines
2434 bytes
According to Tim Rentsch  <tr.17687@z991.linuxsc.com>:
>>> I think this proposed explanation is consistent with the example
>>> given on page 10 (which doesn't talk about looping) and with the
>>> description of the "Transfer on Index" instruction give on page 25
>>> (which clearly is meant to be used with looping). ...
>>
>> That's certainly one of the more common guesses people have made.
>> On the other hand, the TIX instruction adds its decrement field
>> to an index register, but since the decrement is the same size as
>> the index, if you want to count down you just make the decrement
>> two's comp -1. [...]
>
>Did you misread the description of the TIX instruction?

Oh, whoops, I confused it with TXI.

Either way, the fact that Fortran stored its arrays backwards
suggests that whatever they had in mind turned out not to be useful.

I sure wish SOMEONE had written down what the motivation was.  The
mixture of sign-magnitude arithmetic in most places and two's
complement subtraction for indexing is quite peculiar.


-- 
Regards,
John Levine, johnl@taugh.com, Primary Perpetrator of "The Internet for Dummies",
Please consider the environment before reading this e-mail. https://jl.ly
Re: two's complement and Flags (Re: arithmetic and endian history)
#91
Author: Thomas Koenig
Date: Tue, 13 Oct 2026 21:57
84 lines
5026 bytes
John Levine <johnl@taugh.com> schrieb:
> According to Tim Rentsch  <tr.17687@z991.linuxsc.com>:
>>>> I think this proposed explanation is consistent with the example
>>>> given on page 10 (which doesn't talk about looping) and with the
>>>> description of the "Transfer on Index" instruction give on page 25
>>>> (which clearly is meant to be used with looping). ...
>>>
>>> That's certainly one of the more common guesses people have made.
>>> On the other hand, the TIX instruction adds its decrement field
>>> to an index register, but since the decrement is the same size as
>>> the index, if you want to count down you just make the decrement
>>> two's comp -1. [...]
>>
>>Did you misread the description of the TIX instruction?
>
> Oh, whoops, I confused it with TXI.
>
> Either way, the fact that Fortran stored its arrays backwards
> suggests that whatever they had in mind turned out not to be useful.

It certainly makes sense for a language like Fortran to store the
arrays on the order for the indexing.  Putting in the arrays in
ascending order, with code like

      DO 10 I=1,10
        A(I) = B(I) + C(I)
 10   CONTINUE

would have required negating the index registers for the array
indices.

Whatever they had in mind for the negative indexing was something
aimed at assembler or machine code programmers (assemblers still
were considered a luxury in those days).  The 704 was introduced
in 1954, and Backus wrote his famous FORTRAN memo late in 1953,
when an optimizing compiler was still a wild idea.

This makes the usual explanation quite likely but, as you
correctly pointed out, that is not proof.

> I sure wish SOMEONE had written down what the motivation was.  The
> mixture of sign-magnitude arithmetic in most places and two's
> complement subtraction for indexing is quite peculiar.

The 704 was the successor of the 701, which was also sign-magnitude,
There, the 36-bit adder (despite ripple carry, compounded by
end-around carry) could do its job in 5 microseconds.  Using the
same number representation made a lot of sense, both from the
engineering and the customer standpoint.  So, quite possibly a
legacy issue.

For the index register, they chose a solution that was simple.
The "Architecture of the IBM System/ 360" article by Amdahl,
Blaauw and Brooks notes that two's complement is better
for addressing modes.  They wrote

"For the fixed-point arithmetic
system, which is binary,the two’s complement representa-
tion for negative numbers was selected. The well-known
virtues of this system are the unique representation
of zero and the absence of recomplementation.These
substantial advantages are augmented by several properties
especially useful in address arithmetic, particularly in the
large models, where address arithmetic has its own hard-
ware. With two’s complement notation, this indexing
hardware requires no true/complement gates and thus
works faster. In the smaller, serial models, the fact that
high-order bits of address arithmetic can be elided with-
out changing the low-order bits also permits a gain in
speed."

(One thing that they did not mention was that, for machines which
did the addition piecewise like the 360/30 did, an end-around carry
would have required a second carry propagation trip by microcode.)

This was later, but Amdahl was also involved with the
704, and two's complement subtraction *is* cheaper.

Some things cannot be explained logically, only chronologically.

-- 
This USENET posting was made without artificial intelligence,
artificial impertinence, artificial arrogance, artificial stupidity,
artificial flavorings or artificial colorants.
Re: two's complement and Flags (Re: arithmetic and endian history)
#103
Author: Anton Ertl
Date: Wed, 14 Oct 2026 07:50
36 lines
2842 bytes
Thomas Koenig <tkoenig@netcologne.de> writes:
>John Levine <johnl@taugh.com> schrieb:
>> Either way, the fact that Fortran stored its arrays backwards
>> suggests that whatever they had in mind turned out not to be useful.
>
>It certainly makes sense for a language like Fortran to store the
>arrays on the order for the indexing.  Putting in the arrays in
>ascending order, with code like
>
>      DO 10 I=1,10
>        A(I) = B(I) + C(I)
> 10   CONTINUE
>
>would have required negating the index registers for the array
>indices.

Given that FORTRAN was developed for the IBM 704, it's interesting
that they did not design their loops to count down.

Although, thinking about it some more, storing the arrays backwards is
easier than storing them forwards, using and incrementing
implementation for a counter that semantically decrements, and
indexing the arrays with that counter, and converting the counter to
the semantic value when using it in a non-indexing context.

Another more hardware-centric way would have been to actually specify
the arrays to have indexes from -N to 0 or so and to let A(I) access
the element with index -I.  But I guess that that would have run
counter to the intention of "Formula translator", and storing the
arrays backwards is actually easier than explaining these semantics in
the manual, and letting the prorgammers work around it.

- anton
-- 
'Anyone trying for "industrial quality" ISA should avoid undefined behavior.'
  Mitch Alsup, <c17fcd89-f024-40e7-a594-88a85ac10d20o@googlegroups.com>
Re: two's complement and Flags (Re: arithmetic and endian history)
#125
Author: Lawrence D’Oliveiro
Date: Wed, 14 Oct 2026 23:08
8 lines
1641 bytes
On Wed, 14 Oct 2026 07:50:54 GMT, Anton Ertl wrote:

> Given that FORTRAN was developed for the IBM 704, it's interesting
> that they did not design their loops to count down.

That’s what made it a “high-level language”.

;)
Thread Navigation

This is a paginated view of messages in the thread with full content displayed inline.

Messages are displayed in chronological order, with the original post highlighted in green.

Use pagination controls to navigate through all messages in large threads.

Back to All Threads