[HN Gopher] Undocumented 8086 instructions, explained by the mic...
       ___________________________________________________________________
        
       Undocumented 8086 instructions, explained by the microcode
        
       Author : kens
       Score  : 58 points
       Date   : 2023-07-16 21:06 UTC (1 hours ago)
        
 (HTM) web link (www.righto.com)
 (TXT) w3m dump (www.righto.com)
        
       | djmips wrote:
       | Offtopic: this is an excellent series on the 8086! Do you have
       | plans to give a similar treatment to the Motorola 68000?
        
         | kens wrote:
         | When I'm done with the 8086, I might look at the 68000 but I
         | don't have any specific plans.
        
       | EvanAnderson wrote:
       | Based on AMM using CORD for the division operation will D4 00
       | generate the same division by zero error as a DIV with a zero
       | divisor? (I can't think of any reason this would be useful but I
       | do like thinking about edge cases and how things break.)
        
         | kens wrote:
         | My transistor-level simulator shows that the 8086 will generate
         | a divide by 0 interrupt if you give the AAM instruction a
         | divisor of 0. But I haven't tried this on a real chip.
        
       | quickthrower2 wrote:
       | Aside: If you are writing stuff this good (and this niche) I
       | would say ditch the ads. They really will turn off the audience
       | you want to attract. Or at least use one of the developer-focused
       | ad networks that just inline ads not pop them up.
        
         | djmips wrote:
         | Data point: I browsed without an adblocker on phone in Chrome
         | and didn't see any ads.
        
         | EvanAnderson wrote:
         | I'm on iOS and the ad was unobtrusive. I'm very happy to
         | support Ken. Unless the ads are more disruptive on other
         | platforms I'd say leave 'em in.
        
         | unnouinceput wrote:
         | What ads? Didn't seen any ads when visiting the page. Are you
         | browsing the web without uBlock Origin by any chance?
        
           | lloydatkinson wrote:
           | I am always amazed how many tech orientated people don't use
           | any kind of ad blocking
        
             | [deleted]
        
             | flockonus wrote:
             | Having AdBlock extension, but like all my extensions also
             | have "This can read and change site data > when you click
             | the extension" while turn on to any domain that "misbehave"
             | with sticky ads, videos or whatever annoying flashing
             | things. Otherwise I'm just hurting content creators for no
             | good reason. I would not enable an extension on any domain
             | i input my email, password, or otherwise have sensitive
             | private information.
        
       | bruce343434 wrote:
       | Where can one learn more about microcode, how it's implemented in
       | silicon? As I understand it most machine code is actually "VM
       | bytecode", and the "real" cpu is the microcode processor?
        
         | kens wrote:
         | A computer architecture book such as Hennessy and Patterson
         | will describe microcode in detail.
         | 
         | It's a bit confusing because microcode has changed meaning a
         | bit over time. "Classical" microcode, such as the 8086,
         | replaces hard-wired control logic with micro-instructions. The
         | processor steps through the appropriate micro-instructions,
         | which are decoded to generate control signals.
         | 
         | The Pentium Pro introduced a new model, where machine
         | instructions are broken down into independent micro-ops, which
         | are handed off to the core processor engine and processed
         | independently, in parallel. At the end, the micro-ops are
         | "retired" in a sequential order, so your program appears
         | sequential.
         | 
         | Most micro-ops are generated by decoders that convert a machine
         | instruction into a small number of micro-ops. However,
         | complicated machine instructions are converted into micro-ops
         | by microcode. This is similar to classical microcode, except
         | it's not executing micro-instructions but generating micro-ops
         | that then get run by the underlying processor.
        
         | pests wrote:
         | Ben Eater on YouTube has recreated an 8-bit computer on
         | breadboards.
         | 
         | https://www.youtube.com/watch?v=dXdoim96v5A
         | 
         | That is the start of the videos where the control logic gets
         | microcoded. Its pretty basic but over the next few videos he
         | comes up with about 10 different OPCODES and programs their
         | microcode (a series of control logic activations). Its pretty
         | amazing to see it all come together and work in the end.
        
       | Emily56 wrote:
       | [dead]
        
       | colejohnson66 wrote:
       | A lot of the undocumented instruction "match" bits make sense,
       | such as POP CS at [0F]. However, it's clear that the authors of
       | the microcode _deliberately_ made every opcode match to some
       | routine, as evidenced by Jcc being mirrored into the [60..6F]
       | region, LOCK into [F1], group 2  /6 into /7, etc. It wouldn't've
       | "cost" anything extra to make Jcc only match on its documented
       | [70..7F] region (and others) like later processors do. What's the
       | advantage of matching on undefined byte sequences?
       | 
       | Also, SALC is still _technically_ undocumented by Intel (AMD
       | documents it, though). It doesn 't have a dedicated section in
       | the SDM (would be in Volume 2, Chapter 4), and in the opcode map
       | (Volume 2, Appendix A), there's a blank there. One actually has
       | to go to Volume 3, Chapter 23 "Architecture Compatibility",
       | Section 15 "Undefined Opcodes" (of version 080 from June) to see
       | it mentioned. It's weird. They even call it out as SALC "when not
       | in 64-bit mode" and that it performs "IF (CF=1), AL=FF, ELSE,
       | AL=0", but refuse to officially document it.
        
         | kens wrote:
         | There's a reason why every 8086 opcode matches something. If an
         | instruction didn't match anything, I think the microcode engine
         | would spin idle and the instruction would never terminate. (You
         | need a RNI micro-instruction to end microcode processing.)
         | Having your processor lock up due to a bad opcode is something
         | that the designers presumably explicitly avoided.
         | 
         | The 6502 on the other hand, didn't take such precautions. There
         | are opcodes that cause the internal timing state machine to
         | sort of fall off the end, causing the CPU to lock up and even
         | an interrupt won't rescue you. You need a RESET signal.
        
           | greenyoda wrote:
           | Also the 6800, with its famous HCF (Halt and Catch Fire)
           | instruction:
           | 
           | > _With the advent of the MC6800 (introduced in 1974), a
           | design flaw was discovered by programmers. Due to incomplete
           | opcode decoding, two illegal opcodes, 0x9D and 0xDD, will
           | cause the program counter on the processor to increment
           | endlessly, which locks the processor until reset. Those codes
           | have been unofficially named HCF. During the design process
           | of the MC6802, engineers originally planned to remove this
           | instruction, but kept it as-is for testing purposes. As a
           | result, HCF was officially recognized as a real instruction._
           | 
           | https://en.wikipedia.org/wiki/Halt_and_Catch_Fire_(computing.
           | ..
        
       | chx wrote:
       | > The undocumented C9 opcode is identical to the documented CB,
       | far return instruction.
       | 
       | I _remember_ this.
       | 
       | Once ... gosh, it's hard to believe how long ago that was now,
       | but once I knew the entire Z80 opcode table off head. I could
       | read the Z80 machine code and disassemble it. High school crowded
       | that stuff out of my head, I went to a special math school, it
       | was very very hard. Except... C9 was RET (and the Z80 is an
       | extension of the Intel 8080). That has burned into me so deep I
       | still remember, across more than 35 years. I will be 30 ;) years
       | old in two weeks.
        
         | gnat wrote:
         | I'm the same with LDA immediate = A9 in 6502 machine code, from
         | my C64 days. It's disturbing how strongly burned-in those
         | neurons are ...
        
       ___________________________________________________________________
       (page generated 2023-07-16 23:00 UTC)