26

The Intel 8080 has two pairs of instructions for rotating the value of the accumulator -- RLC/RRC and RAL/RAR.

One of them shifts the 8 bits in the accumulator circularly, writing out into the carry flag the value of the bit that moved from one side of the byte to the other. The other instead acts on a 9-bit buffer, using the carry flag as the 9th bit and attaching it to the side being rotated in.

My first thought when looking at the mnemonics was that the RA* ones were the regular rotation (standing for Rotate the Accumulator Somewhere), and the R*C ones were through the carry flag (for Rotate Somewhere with Carry). I was surprised to discover that it's actually the opposite: the operations with a C in them do not involve the carry flag.

This means that both my reasoning and intuition were wrong, and this seems to also go counter to Intel's later products, like the 8086 and the x86 assembly in general, having ROL/ROR for regular rotate and RCL/RCR being the through-carry rotate.

What historical reason is there for these instructions being called that?

4
  • 5
    You are asking an historical justification. I can't provide an answer. The mental state of those creating the assembler mnemonics isn't something I can say. But I can say, learning the 8080 assembly code (beginning in 1975), it never crossed my mind to care. I just took the instructions for what they were and went from there. At the time we had a long history of rotating the accumulator together with the carry as an N+1 rotate, as it is necessary for multi-word operations. And I had no problem accepting the idea that in shifting R or L we may want a copy of the interesting bit in the process.
    – jonk
    Jul 2, 2022 at 6:15
  • 2
    So there's no argument about the need for such instructions. They are useful. Period. End of story. The only issue you present is why these mnemonics and not others. The PDP-8 used RAL and RAR for 'rotate through carry -- a 13-bit operation'. Perhaps that is what drove them? It's true enough that the PDP-8 was the first commercially successful minicomputer. So, perhaps? But I don't know.
    – jonk
    Jul 2, 2022 at 6:20
  • 3
    The PDP-8 relevation is the only plausible option among the whole bunch of answers now :)
    – lvd
    Jul 4, 2022 at 3:41
  • As you point out in the question, both these operations DO use carry, just in slightly different ways. The rrc for example is rotate right with branch carry, meaning the accumulator is rotated but with the low bit also entering carry flag for the purposes of branching.
    – paxdiablo
    Jul 4, 2022 at 14:34

3 Answers 3

37

What historical reason is there for these instructions being called that?

"Historical Reason" is the right key word here, as ...

TL;DR: It's Piled Up Heritage

The 8080 inherited the mnemonic names from the 8008, which in turn is based on the Datapoint 2200 designed in 1969, way before terminology settled. From there on, it was a combination of keeping known names and adding new ones without violating design restrictions. It was up to Mr. Stephen Morse who did the instruction level design of the 8086 to straighten naming and adjust it to by-1976/77-settled terminology.

Terminology is a constant problem when looking into the past (*1). It needs time to settle into (mostly) canonical form. Words/phrases from before that consensus is reached may not always fit today's way of thinking. Likewise what seems settled today may sound wrong a few years from now.


The Long Read:

Intel neither invented nor named these instructions for the 8080, but carried them over from the 8008, which already featured all 4 of them. The 8008 in turn is the single chip implementation of Datapoint's 2200 terminal CPU; thus Intel inherited most names and mnemonics.

Granddaddy 2200

The Datapoint 2200 featured two of the four, RRC and RLC, or as they called them SRC and SLC:

enter image description here

(Taken from the August 1971 "Datapoint 2020 PROGRAMMERS' MANUAL")

Being designed in 1969/70, the 2200's CPU predates any modern microprocessor as well as today's canon of assumptions when trying to make sense of mnemonics. (*1)

They called 'Shift Circular' what today might commonly be called 'Rotate'. 'Shift Right (or left) Circular' follows more natural English grammar than 'Shift Circular Right', doesn't it? These instructions were mostly intended to allow serialization of bytes and bit tests, due to being fast single byte instructions with a direct testable result in carry.

Papa 8008

When Intel created the 8008 in 1970/71, they added two more instructions, now rotating through carry, allowing code to 'carry' shifting/rotating operations over multi byte values. At the same time they changed language from 'Shift' to 'Rotate'.

enter image description here

(Taken from the "8008 8-BIT PARALLEL (*2) CENTRAL PROCESSING UNIT USERS MANUAL" Rev.2 of November 1972)

SRC/SLC became RRC/RLC. The new one became RAR/RAL. Unfortunately they no longer gave a plain text translation for the mnemonic. The descriptive text is at best hinting. What seems clear is that RRC/RLC are continuations of Datapoint's terminology, easing the switch from that. 'C' was therefore still assigned as 'Cyclic', so it could not mean Carry. Intel adhered to the carried-over meaning where other manufacturers had the freedom of clean sheet designs.

For the new ones, RAR/RAL, they had more freedom. Except, it was bound by

  1. Using 3 and only 3 letters
  2. Start with 'R' as they are now 'Rotates'
  3. Include the direction
  4. Not using a single 'C' as that was reserved for 'Cyclic'

Solutions that would add another 'C' for carry would invalidate #1, as it would need a 4th character for the direction (RRCC/RLCC) (*3). In the end, only one letter was replaceable, which was the C. They did go with an A, which may mean Accumulator, but as seen, it's not spelled out.

Another reason may have been orientation on existing/known machines. At that time (~1970) the DEC's PDP-8 line (and its offspring) was rather well known, which used the RAL/RAR mnemonics for Rotating Accumulator Left/Right. It was explicitly named that way. Except for the PDP-8 handling a 12 bit accumulator, that is.

Our Hero 8080

With the 8080, the instructions became renumbered, but mnemonics were kept. A dedicated cleartext meaning was added in the Programmer's Manual, one not really resembling the mnemonic:

enter image description here

(Taken from the "Intel 8080 Assembly Language Programming Manual" Rev.B of 1975)

The Great Reset 8086

Last, when the 8086 mnemonics were done by Mr. Stephen Morse, the whole set was overhauled, dropping most of the accumulated ballast and renaming them in a more consistent manner and rather close to what was canonical terminology by 1976/77.


Ignorance is Bliss

In the end it doesn't matter if a mnemonic makes sense to everyone or anyone at all. Its sole purpose is to uniquely identify a certain instruction/working, without writing a novel. It may be nice to 'read' them meaningfully, maybe even helpful, but that's lower priority. Thinking too much about that just ties up even more brain cells without anything to gain ... a straight way to depression :)


*1 - An issue that's quite obvious here on RC:SE, where many questions as well as answers run into the trap of assuming that terminology is consistent over time - or even fit to describe items before it has been coined.

*2 - Interesting side-note: Intel explicitly advertised the 8008 as a parallel CPU, which unlike today isn't a hint about parallel processing, but the fact that it's not a serial implementation.

Another example of a shift in common terminology, isn't it?

*3 - Zilog did go that way, albeit by completely breaking the 8008/Datapoint heritage, naming them RLA/RRA and RLCA/RRCA, creating a quite logical system:

  • Rx -> Rotate Right/Left register or memory (*4)
  • RxA -> Rotate L/R Accumulator
  • RxC -> Rotate L/R Carry and register or memory (*4)
  • RxCA -> Rotating L/R Carry and Accumulator.

Zilog also added shifts, named as SxA, where A finally stands for Arithmetic.

Redesigning the mnemonics was eventually one of the most beneficial additions Zilog did - so good that even direct 8080 descendants, like the Gameboy's LR35902, can be rightfully described as a Z80 "inspired" CPU.

*4 - Since Rx and RxC also work with A, this may seem like a renaming of RxA/RxAC, but both are really new, slower opcodes in addition to the ones inherited from the 8080.

4
  • 3
    I'm happy to conclude that "C" was for "circular" and "A" was for "arithmetic" and that they finally described it in other terms for added clarity. I only ever learned Z80 and m68k and I'm sure I remember "A" being "arithmetic" because you used them for math on numbers bigger than a register. I think choice of mnemonic does matter in that "mnemonic" specifically means "memory aid". So they in principle serve to help you remember what they do. Though not all mnemonics turn out to be obvious or even unambiguous. When I finally learned C I couldn't fathom how I could survive without rotates! Jul 2, 2022 at 14:33
  • 2
    @hippietrail Neither Motorola nor Zilog call any rotate 'Arithmetic' as they aren't. Z80Rotates are quite logically maned: Rx -> Rotate Right/Left memory, RxA -> Rotate L/R Accumulator and RxCA -> Rotating R/L Carry and Accumulator. What you may remember are the Shifts, which do come in Arithmetic. SxA -> Shift R/L Arithmetic. in addition there is SRL, Shift Right Logical. It needs no left counterpart, as shift left is the same for logical and arithmetic. Last, but not least, C does only offers shift. Rotate has to be programmed
    – Raffzahn
    Jul 2, 2022 at 15:21
  • Ah yes. These days I sometimes disassemble but haven't coded asm in a long long time. Jul 2, 2022 at 15:29
  • The Z80 does actually have a leftward counterpart for "SRL", but it's undocumented. As I recall is shifts in a 1, regardless of the state of the carry flag. Sometimes it's called "SLI", for Shift Left Illogical :-) Apr 25 at 14:11
10

It can't be helping your intuition that that the official descriptions from the 1975 Intel 8080 Assembly Language Programming Manual, p.21, use the word "carry" in the descriptions only of the longer "non-C" versions:

RLC Rotate Accumulator Left
RRC Rotate Accumulator Right
RAL Rotate Accumulator Left Through Carry
RAR Rotate Accumulator Right Through Carry

I have no sources on why they chose these mnemonics, and such sources may not exist. However for the purposes of remembering how this works, you might think of it this way:

The "standard" for rotation of a register in contemporary microprocessors was to rotate through the carry. See, e.g., the 6800's ROL and ROR instructions (it had no equivalent of Intel's RLC and RRC). This is true of at least some minicomputers as well; the PDP-11's ROL and ROR instructions also rotated through the carry (and again had no equivalent of Intel's RLC/RRC).

Thus, you can assume that, if not specifically designated otherwise rotations always go through the carry.

With the RLC and RRC instructions, however, you should think of the C as meaning "copy" because instead of the rotation going through the carry, one of the bits in the rotation is instead copied to the carry. The mnemonics might be read as "Rotate Left and Copy" and "Rotate Right and Copy."

6
  • 2
    I didn't know that the rotations through the carry were a standard. To my modern sensibilities, the non-carry-rotate seems the more "basic" operation, and the carry-rotate seems a derived operation specifically designed for multi-byte rotations.
    – Danya02
    Jul 2, 2022 at 6:37
  • 4
    @Danya02 Actually, rotate-through-carry is often (possibly more often) used for building single bytes from bits. E.g., if I'm reading from a serial input, I can put each bit I read into the carry and then rotate it into the byte I'm building. If I have only a rotate-without-carry instruction that becomes more work because I have to rotate the current value and then mask the new bit into the current value. And depending on the instruction set, it can be faster to emulate rotate-without-carry using rotate-through-carry than vice versa. (I don't think any of this has changed for modern CPUs.)
    – cjs
    Jul 2, 2022 at 8:10
  • @cjs: Rotate through carry is also used extremely often for purposes of rotating multi-byte regions.
    – supercat
    Apr 25 at 19:39
  • @supercat Yes, I'm well aware of that, having used that technique extensively in some bignum (up to 200-or-so byte integers) routines I wrote for the 6502 a few years ago.
    – cjs
    Apr 26 at 9:10
  • Using rotate-through-carry to build bytes works well if one has a way of getting the bytes in question into carry. On the 8080, I would think (Z80 mnemonics) using something like IN A,xx / AND D / OR E / RLCA / LD E,A / DEC B / JP NZ,xx, and then spinning the value in A afterward if the bit mask wasn't 1 or 128, would seem just as good as rotate through carry.
    – supercat
    Apr 26 at 15:13
4

I think you are confusing the meaning of A in RAL/RAR it does not stand for accumulator but for arithmetic...

RLC/RRC are cyclic bit rotation (used for example for gfx movement by pixels)

and RAL/RAR are arithmetic rotation (the same as arithmetic *=2 and /=2 operations on unsigned integers)...

Some platforms add also signed version of RAR where instead of injecting zero bit (or carry) the MSB is copied ...

In a nuthshell arithmetc shifts does not cycle (does not form a closed loop) between MSB and LSB ...

3
  • 2
    Where did you get "RLA" and "RRA" from? Those are not the mnemonics in the original Intel manual (or the question). Nor do Intel's descriptions anywhere mention "arithmetic" for RAL and RAR; the longer descriptions next to the mnemonic say "Rotate Accumulator Left/Right," as per the quote in my answer.
    – cjs
    Jul 2, 2022 at 8:18
  • 2
    @cjs thx for spotting I repaired it ... I used too many instruction sets in past Its most likely from Z80 ... however the "arithmetic" is commonly used for many iset description from many CPUs and MCUs ...
    – Spektre
    Jul 2, 2022 at 8:26
  • 3
    @Spektre Except, that these are not 'Arithmetic' operations. Only Shifts are 'Arithmetic' and would pull in a Zero for shift left or keep the top bit for shift right. RAR/RAL are rotate instructions which rotate the accumulator thru carry. No Arithmetics.
    – Raffzahn
    Jul 2, 2022 at 10:41

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .