13

The assembly language for many processors use the phrase "arithmetic shift" to represent the bitwise shift of a signed value, and "logical shift" for an unsigned value. The two types of shift are the same when shifting leftward, filling the least-significant bits with 0. However, a rightward logical (unsigned) shift fills the most-significant bits with 0, whereas a rightward arithmetic (signed) shift fills the upper bits with a copy of the old sign bit (MSB).

What was the first use of the terms "arithmetic" and "logical" for shifts? When and by whom did this occur? Was there any reason given why these terms were chosen instead of "signed" and "unsigned"? Please support answers with sources, rather than speculating.


Related: What was the main purpose of bitshift instructions in CPU?

8
  • 2
    Speculation :-) The shifts were thus named following a convention for distinguishing 'arithmetic' and 'logical' values in general. 'Unsigned' is somewhat of a strange concept in hardware; the accumulator has a sign bit. Feb 22 at 12:25
  • 3
    Very roughly, the distinction between arithmetic shifts and logical shifts happened in the same time frame as the adoption of twos complement arithmetic. For a twos complement machine, the right shift is division by a power of 2 if the sign bit propagates into the next bit over. This is arithmetic shift. Feb 22 at 14:39
  • 1
    @WalterMitty: Sometimes. (-1) >> 1 is -1; however, (-1) / 2 is 0 according to the C99 standard. However, C89 left the result implementation-defined.
    – DrSheldon
    Feb 22 at 17:57
  • 4
    There can be a subtle difference between left logical/arithmetic shift. On the 68k, ASL sets the V overflow flag if the MSB/sign changes; LSL always clears the V flag. Feb 22 at 18:25
  • @WalterMitty I do not have a reference handy, but I am pretty sure one's complement machines had arithmetic shift operations as well, and that on a one's complement machine the arithmetic left shift operation inserted copies of the sign bit on the right.
    – njuffa
    Feb 23 at 1:54
12

The 1955 manual for the IBM 704 on page 7 talks about data representation in the computer.

When a word is interpreted as numerical data, the zero position acts as the sign of the word. (…) When a logical operation is performed on a word, the word is interpreted as a 32-bit signless number. As an algebraic (signed) binary number, a word can represent (…)

In addition, there is a section, around page 19 on 'logical operations' in general, which include for example the obvious case of AND and OR, and the less-obvious (to me) CAL, clear and add logical word.

I conclude that focusing on the shift instructions is somewhat misplaced. The distinction is about the datatype and how the programmer intends to use it. Once you have that focus, then naming the shift instruction naturally follows.

Curiously, though, the 704 has a Logical Left shift but no Logical Right shift. Logical Left is distinguished from Long Left Shift by whether the sign bit of the MQ is involved (it is for Logical Left, it is not for Long Left).


Footnote: the 709 instruction set seems somewhat strange to me. In a 36-bit machine the accumulator has 38 bits: 35 "operand bits", a sign bit S, and the so-called P and Q bits.

The strangeness is in part due to the 709 being a sign-and-magnitude machine. "Arithmetic" operands are loaded into S and 1-35 as you might expect; P and Q are cleared. Thus a signed 36-bit operand is lengthened into 38 bits signed. Arithmetic operations may overflow into P and Q, but not further into S.

"Logical" operands are loaded into P and 1-35; Q and S are cleared. An unsigned operand is lengthened into 38 bits unsigned.

For shifts, the sign bit is not involved. Single-length shifts in the AC involve P, Q, and 1-35. There's no arithmetic/logical distinction. The only difference is double-length shifts involving the MQ. "Long left shift" does not involve the MQ's S bit; bits leaving MQ 1 end up in AC 35. "Logical left shift" include MQ S. MQ 1 goes to MQ S, and MQ S goes to AC 35.

6
  • 2
    @user3840170 While you're replacing ... with …, you might also consider replacing ASCII minus signs with U+2010 HYPHEN in all non-arithmetic contexts, as in "36-bit".
    – Leo B.
    Feb 23 at 2:32
  • 1
    Is that typo ("bnary") present in the original document? Or is it a transcription error? Feb 23 at 15:32
  • Transcription. I had to retype it, couldn't cut and paste, I assume the doc is just an image but did not look closely, Fixed now. Thanks. Feb 23 at 23:52
  • I updated my footnote after studying the 709 instruction set a little more closely. Feb 24 at 2:20
  • 1
    Another way of describing the "logical" instructions of the 709 is to think of different parts of the hardware being used for different datatypes: For signed "arithmetic" datatypes, the MSB is the sign bit, and stored in S. For unsigned "logical" datatypes, the MSB is stored in P. "Arithmetic" instructions involve S, "logical" instructions invole P. P also doubles as carry for arithmetic instructions. And it gets a bit more wierd since ACL ("add and carry logical") uses an end-around carry. I guess all of this is enough material for its own Q&A...
    – dirkt
    Feb 24 at 6:56
5

(Another "what was the first" question where it's basically impossible to answer it unless one goes through all computer instruction sets ...)

One example of the usage of "logical" is the IBM 7090 (1959), as one can verify in the manual where the shift instructions are listed starting on page 31:

ALS  Accumulator Left Shift
ARS  Accumulator Right Shift
LGL  Logical Left Shift
LGR  Logical Right Shift

No mentioning of "arithmetic", though. And the definition of the actual operation is somewhat different from the current usage ("logical" operations treat AC and MQ as a pair, but don't duplicate the sign bit as in the "accumulator" operations).

As the IBM 7090 is a transistorized version of IBM 709 (1957), I would assume it also applies to the IBM 709 (though I have not seen an instruction set list for this one).

The term "logical" is also used in other places to distinguish "arithmetic" operations (adding etc.) from logical (bitwise) operations.

You can derive the obvious "speculations" how this kind of naming came into existence from that.

2
  • 3
    I’ve seen old documents refer to “logical” v. “signed” shift as well, with no mention of “arithmetic” (I don’t have the references handy to check). Feb 22 at 12:23
  • 4
    Could you please remove the snarky "basically impossible to answer it unless one goes through all" sentence? Because it appears you asked "Fastest non-emulated CP/M Z80-based computer ever built?" which is basically impossible to answer it unless one goes through it all.
    – DrSheldon
    Feb 23 at 6:54

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.