145 points · by a1a106ed5 · 4y ago · 49 comments
All of these are features inherited from the 8080/8085/Z80.
Here are the corresponding opcode tables in octal:
https://dercuano.github.io/notes/8080-opcode-map.html
http://www.righto.com/2013/02/8085-instruction-set-octal-tab...
Astonishing to think that we can see traces of the 8008 still today and that it wasn’t actually an Intel designed ISA (came from CTC / Datapoint).
The Datapoint 2200 documentation gave the opcodes in octal, so they were clearly thinking in octal. The 8008 documentation, however, didn't use octal or hexadecimal. The opcodes were given in binary, but grouped in 3 bits, octal style, e.g. 10 111 010. (They didn't specify opcodes in octal or hex!) I think the 8008 was right at the time where octal was on the way out and hexadecimal was taking over. (The 8008 assembler manual uses both octal and hexadecimal, but hexadecimal primarily.)
The Intel 8080 still specified the instruction set in binary, not octal or hexadecimal. The 8085 had opcodes in binary in a 1983 manual, but now split with a line into 4-bit chunks (i.e. hexadecimal-style). And then an appendix gave the opcodes in hexadecimal.
(Just some random history.)
Also, after using the Xerox Alto, which uses 16-bit words, I realized that octal is terrible. The problem is that if you're looking at two bytes in a word, the values make no sense in octal. For example, the characters "AB" form the hex word 0x4142, while "BA" forms 0x4241; the two letters are clear. But in octal, "AB" is 0o40502 and "BA" is 0o41101; the two letters turn into unrecognizable numbers.
Extracting the alu function from bits 4-6 means that you can group together the implementation of add, or, adc, sbb, and, sub, xor, to and from memory, for bytes and words into one function.
The code's not as fast as the "one code block per instruction" approach of something like DosBOX but at least it doesn't cause me dread to look at.
[1] http://bitsavers.org/pdf/datapoint/2200/
[2] http://bitsavers.org/pdf/datapoint/2200/2200_Programmers_Man...
My notes on the 8080 are at https://dercuano.github.io/notes/8080-opcode-map.html.
The "core" (non-E/VEX, non-SSE, etc.) x86 encoding is wonderfully clever and terrible by modern standards, and Volume 2 of Intel's SDM is a great reference for how x86 manages to pack remarkably complicated addressing, operand, etc. semantics into just a handful of bytes. The result is a format that's remarkably hard to decode correctly, meaning that just about every software decoder for x86 is saturated with bugs[1] (FD: my project).
(Even then, there's a lot of waste in the "legacy" prefix bytes, and I've always wondered who hacked those into the ISA instead of designing something more compact.)
Historical note: the 286 was the first to have the second page.
That's a backwards way of saying it. I'd rather say, given the hardware structure of the bit fields of the opcode register, the binary opcodes are perhaps better described by octal notation rather than hexadecimal.
I wouldn't say there's any "conflict". Who needs to know the detailed hardware structure? Compiler writers maybe, but they experience and order of magnitude more conflicts then.
I think this Usenet posting was written in the early 1990s, when a large number of people were probably still using macro assemblers to write large programs, and may have also been writing binary patches for those programs back when that was easier (no relocations to worry about!). It's definitely more of a "cool fact" than something you'd immediately apply, but it's the kind of thing I could see being useful to an assembly programmer of the period.
For my N=1 experience: I've written compact x86 decoders in HDLs before, and this octal mapping of the opcode structure was extremely useful in helping me determine an optimal (in terms of minimal gate counts) decoder structure. But that is indeed a very niche use case.
A more agile way to think of it in your head is not as "octal vs hex vs decimal", but bit patterns. For example, if you decompose a byte into subfields and use a subfield of 3 bits to refer to one of 8 registers, you're going to naturally use octal. chmod on the unix command line is still easiest to use in octal because of the 3 rwx bits for ugo. It's not octal, it's bits and how many do you have.
A generation of programmers from the 1960s and earlier were trained to use the octal notation. This can be seen in the original Unix assembler - all numbers were assumed to be octal by default, no prefix is needed. It's also why the C programming language uses a single "0" to detonate octal numbers because it was considered convenient.
The IBM S/360 (1964) was the first major computer systems to break this pattern, switching to a 32-bit system with hexadecimal as its preferred notation, all the official documentation was only written in hexadecimal. This extremely successful machine was highly influential, and was likely the first exposure to hexadecimals to many. The standardization of ASCII in the mid-60s also marked the beginning of this transition from a 6-bit byte, which was the previous status quo, to an 8-bit byte. Then in the 1970s, several popular 16-bit and 32-bit minicomputers started to dominate the market. PDP-11, for example, was a 16-bit machine. Although octal was still its officially preferred number system due to habit and the fact that its instruction encoding was designed with 3-bit subfields, but the departure from 36-bit and 18-bit meant the days of octals was numbered (no pun intended), hexadecimals are simply more natural for dealing with integers.
The final death blow of octal was the microcomputer revolution. After 8-bit and 16-bit CPUs started to dominate the computing world in the late 70s and early 80s, the octal notation has gone and mostly fell out of favor. The x86 was a natural product of this era - it's officially documented in hexadecimal (although, like the PDP-11, octal was natural for its instruction encoding).
This is cool: https://dercuano.github.io/notes/8080-opcode-map.html
It also feels like how the 'hidden' instructions get found.
Is there currently any good public way to search usenet archives?
no, you just hope google groups is nice to you (it wasn't the last time you and i had this discussion on hn).
but this time it is:
the posted copy is of the message https://groups.google.com/g/alt.lang.asm/c/bl21J0NYzBY/m/BjP... from "Jan 31, 1995, 7:17:40 AM".
it references an earlier, much shorter post https://groups.google.com/g/alt.lang.asm/c/ZNZp2K-SqhY/m/plK... from "Jul 5, 1992, 8:13:26 PM"
so the (1992) is not wrong, but most precisely it's (1995).
also, a mention on hn that came up whilst looking into this: https://news.ycombinator.com/item?id=12596371
https://web.archive.org/web/20200114164700/http://www.dabo.d...
That one shows up in HN comment search, perhaps for sufficient levels of nerdery this the equivalent of adding 'reddit' at the end of your google search.
could be a good vanity project for another fts startup like algolia?
the mboxes are all here: https://archive.org/details/usenethistorical