[HN Gopher] Yes, the 8086 wanted to be mechanically translatable...
       ___________________________________________________________________
        
       Yes, the 8086 wanted to be mechanically translatable from the 8080,
       but
        
       Author : zdw
       Score  : 128 points
       Date   : 2022-07-25 19:35 UTC (3 hours ago)
        
 (HTM) web link (devblogs.microsoft.com)
 (TXT) w3m dump (devblogs.microsoft.com)
        
       | f311a wrote:
       | After reading the title and domain name, I already knew who the
       | author is.
        
         | rjbwork wrote:
         | Lol. My exact thoughts before clicking the link "Let me guess,
         | this is Chen"
        
           | AceJohnny2 wrote:
           | Everybody Loves Raymond
        
         | commonlisper wrote:
         | Exactly! Raymond Chen is doing a great job at sharing
         | interesting stories from a bygone era.
        
           | criddell wrote:
           | Bygone? It's a fairly regular occurrence where I search for
           | some Win32 API and end up on Chen's blog. I get what you are
           | saying about articles like this one though. I can't imagine
           | much new work is happening with the 8086 (or 8088 or '186 or
           | '286 or ...)
        
             | GabrielTFS wrote:
             | I mean even w.r.t. Windows stuff, quite a large part of
             | what he talks about is variations on "here's an interesting
             | old anecdote from 1995" or "You know that thing that's
             | totally useless now and doesn't matter ? Here's why we
             | absolutely needed it in 1989."
        
       | rep_lodsb wrote:
       | IMO the base+index encoding (in 16-bit x86) was a mistake, it
       | should have simply allowed indirection through any _single_
       | register (+ immediate offset), including SP.
       | 
       | * the address calculation would be simple enough to do hardwired
       | even on the original 8086, instead of using slow microcode. The
       | 8086 actually took a different amount of clock cycles depending
       | on the registers used for base and index, because there wasn't
       | enough ROM space to duplicate the code for every combination
       | without using jumps!
       | 
       | * you could use [SP+xxxx] to access local variables (frame
       | pointer omission)
       | 
       | * would be able to emulate the 8080's LDAX/STAX and XTHL in a
       | single instruction
       | 
       | * with so few registers, you really want every one available for
       | memory addressing. Especially AX which is used implicitly by
       | instructions like LODSW and MUL.
        
       | kazinator wrote:
       | > "there was no room"
       | 
       | They were saving it for 286, 386, ... MMX, AVX, SSE, ...
        
       | hacknat wrote:
       | My favorite Chen article:
       | 
       | Why do Windows functions all begin with a pointless MOV EDI, EDI
       | instruction?
       | 
       | https://devblogs.microsoft.com/oldnewthing/20110921-00/?p=95...
        
         | mFixman wrote:
         | I don't understand the reasoning behind this. Why do you need 5
         | bytes of unexecuted patch space before the program _and_ 2
         | bytes of patch space at the beginning of the program?
         | 
         | Wouldn't it be the same to have a single 5-byte effectless
         | operation to patch a single long jump instead of needing space
         | for two jumps?
        
           | saagarjha wrote:
           | 5 bytes of nops takes longer than 2 bytes?
        
             | jahewson wrote:
             | Longer _time_ to execute.
        
           | layer8 wrote:
           | The article explains why a MOV is used instead of two NOPs.
           | Five NOPs would obviously be even worse.
        
             | mFixman wrote:
             | But isn't there a 5-byte single instruction that has no
             | effect, like `NOP DWORD ptr [EAX + EAX*1 + 00H]`?
             | 
             | I thought that multibyte NOPs were executed in a single
             | instruction?
        
               | layer8 wrote:
               | I'm pretty sure it would be slower, if only by taking up
               | more space in the instruction cache (in the common case
               | where no hotpatch is applied).
        
               | MBCook wrote:
               | They may not have been coalesced at the time the decision
               | was made.
        
             | colejohnson66 wrote:
             | But NOPs aren't even executed. They're swallowed by either
             | the decoder or dispatcher.
        
               | wvenable wrote:
               | The article states that it's one cycle and slot per NOP.
        
               | colejohnson66 wrote:
               | Modern x86 processors decode multiple instructions per
               | clock. By "slots", I'm assuming he means entries in the
               | dispatcher or reservation stations. But NOPs don't even
               | make it to there. As I said, the decoder that encounters
               | it will probably swallow it and emit nothing.
               | 
               | Besides, it sounds like premature optimization. This
               | isn't the 1980s; An extra clock cycle per function call
               | is not going to make or break your program.
        
               | MBCook wrote:
               | Modern.
               | 
               | There is a very good chance this dates back to 16-bit
               | Windows. Even Windows 98 supported the 486 which was not
               | capable of independent execution (that's P5) or separate
               | decode from execution (P5Pro there).
               | 
               | Those processors weren't dead until Windows XP.
        
               | avianlyric wrote:
               | Because you can't atomically replace the NOPs. So there's
               | nothing to prevent you from inserting your patch while a
               | thread partway through consuming the NOPs, resulting in a
               | portion of your patch being decoded out of order.
        
         | omnibrain wrote:
         | It's such a shame that they killed (twice now?) all the
         | comments in the blog.
        
           | mananaysiempre wrote:
           | There is a more-or-less comprehensive archive[1] up to 2019
           | (which should probably be scraped and hoarded). The article
           | in question is there, comments included[2].
           | 
           | Side note: Michael Kaplan's blog, which Microsoft took down
           | in a remarkably shameful manner, has also been archived[3],
           | while Eric Lippert reposted (most of?) his old articles on
           | his personal WordPress instance[4].
           | 
           | [1] http://bytepointer.com/resources/old_new_thing/index.htm
           | 
           | [2] http://bytepointer.com/resources/old_new_thing/20110921_2
           | 26_...
           | 
           | [3] http://archives.miloush.net/michkap/archive/
           | 
           | [4] https://ericlippert.com/
        
             | omnibrain wrote:
             | Larry Osterman's Blog seems to be gone too...
        
               | mananaysiempre wrote:
               | It's technically there[1], but I remember that a good
               | portion of the articles from the 2000s are just ...
               | silently missing. Not time periods, just sporadic one-in-
               | three or -four mortality (as far as links from other
               | blogs can be considered to be faithful sampling).
               | 
               | To add insult to injury, the comments are there. The
               | bloody _comments_ are just _there_ , like the we-could-
               | not-be-arsed-to-properly-GDPR-ocalypse was very strictly
               | localized to only _some_ of the blogs.
               | 
               | I'm not even expecting malice, really, I'm just appalled
               | at the blatant disregard for (what is effectively if not
               | officially) historical record.
               | 
               | (There are other blogs that were lost in the migration,
               | just not this one. Hell, the entirety of the MSJ and a
               | good portion of the MSDN Magazine are completely gone.)
               | 
               | [1] https://docs.microsoft.com/en-
               | us/archive/blogs/larryosterman...
        
           | password4321 wrote:
           | Yes, I miss my weekly-ish from Raymond's arch nemesis Yuhong
           | Bao.
           | 
           | For this specific blog post there's an HN discussion1 and
           | archive.today2 (beware!?3) did grab comments while the
           | Internet Archive does not load them:
           | 
           | 1 https://news.ycombinator.com/item?id=3022224
           | 
           | 2 http://archive.today/2015.07.08-134638/http://blogs.msdn.co
           | m...
           | 
           | 3 https://news.ycombinator.com/item?id=31945924#31946453
        
             | m463 wrote:
             | nice use of superscripts
        
           | game-of-throws wrote:
           | They also changed the URL at least once and broke all links
           | to it. His posts deserve better.
        
       | aftbit wrote:
       | >These redundant encodings are used by some assemblers to
       | "fingerprint" their output.
       | 
       | Fascinating! Does anyone have links to more information about
       | this? What purpose might one have for this fingerprinting?
        
         | retrac wrote:
         | If you sell a commercial compiler or assembler, and some
         | company starts selling a product produced with your
         | compiler/assembler, and you know you never sold them a license,
         | you've got yourself someone to sue. For a less
         | successful/commercial product, it could also just be for the
         | joy of finding it used in the wild.
         | 
         | Similar fingerprinting techniques were also used by assembly
         | coders as proof of copyright. When reverse-engineering to a
         | spec, it's not unusual for routines, even long routines, as
         | well as lookup tables, etc. to end up being coded the same, or
         | nearly so, as the original software. This isn't necessarily
         | infringing of copyright -- for example there are only a few
         | sensible ways to check if a character is uppercase in ASCII. It
         | can be hard to tell reverse-engineered and re-implemented code,
         | from disassembled and reshuffled code (which _is_ copyright
         | infringement). If the suspect routine incorporates something
         | like an idiosyncratic sequence of NOPs that serve no particular
         | purpose, coincidence is a lot harder to argue.
        
         | bell-cot wrote:
         | One example (scroll down to 'Code fingerprint') -
         | https://en.wikipedia.org/wiki/A86_(software)
        
         | csense wrote:
         | When I first got into assembly language programming, I used MS-
         | DOS DEBUG as my assembler, since it was included on basically
         | every PC in those days.
         | 
         | I was _extremely frustrated_ because my textbook 's later
         | chapters used MASM as the assembler, which at the time cost
         | some ghastly amount of money (somewhere around $180 if I recall
         | correctly, which was a truly staggering number of birthday and
         | Christmas presents).
         | 
         | Anyway, my point is, in 2022 everyone takes for granted that an
         | assembler for any system that matters can be downloaded for
         | free from the Internet -- or if it doesn't, one will soon be
         | written by some enthusiast and posted on Gitlab.
         | 
         | But back in the 1980's and well into the 1990's, assemblers
         | were expensive products that companies actually got away with
         | charging a lot of money for. Presumably they made a significant
         | amount of revenue from those sales.
         | 
         | So the use case that immediately springs to my mind is being
         | able to prove a particular commercial binary was assembled by
         | your assembler, in order to make a successful accusation of
         | software piracy and extract a monetary settlement from its
         | developer.
        
           | jacquesm wrote:
           | Yes, this is very much true. For the first three systems I
           | owned I wrote my own assembler, just to save some money
           | (which was incredibly tight in those days, as in: that was
           | three months worth of food or so).
           | 
           | Time was worth relatively little in comparison and I figured
           | I will at least know the instruction set inside-out.
        
             | rightbyte wrote:
             | How did you do that?
             | 
             | Did you bootstrap it with hand-assembled code or some
             | Basic? Did you assemble the assembler with itself?
        
               | dhosek wrote:
               | When I was in high school, I hand-assembled my 6502 code.
               | I'd write it longhand out on graph paper, then write down
               | addresses in the leftmost column, opcodes in the middle &
               | finally I'd type in all the hex from the Apple Monitor.
               | It was slow, painstaking and error-prone, but it made for
               | clear thinking about how the program worked before I sat
               | at the computer.
        
               | jacquesm wrote:
               | It probably also really honed your ability to simulate a
               | CPU in your head. That's invaluable when looking at code,
               | to build up a mental model of what it really does (rather
               | than what the comments say it does).
        
               | jacquesm wrote:
               | Getting it to the point where it would assemble itself
               | was pretty much the goal of the whole exercise. Hand
               | assembly with Leventhal's book (which I still have :) )
               | to get it to work, usually one subroutine at the time.
               | And then once it work things got much quicker, the bigger
               | problem then was a proper editor.
               | 
               | https://www.amazon.nl/Assembly-Language-Programming-
               | Lance-Le...
               | 
               | Memory management was a tricky part and macro expansion
               | only got done after the whole thing worked (that would
               | have saved a lot of time but I couldn't see the wood for
               | the trees at that point).
               | 
               | The nasty part was that instructions were variable length
               | so you could get into these weird errors where your
               | initial guess for a jump target was too small, which
               | would then move everything else as well, which might lead
               | to other jumps becoming too small. I don't have the code
               | any more but I think I fixed that by making all the jumps
               | long jumps initially. A bit wasteful but that way I could
               | at least get it to work in one pass. Later on when I got
               | better at assembly that sort of thing got fixed.
               | 
               | The end product was endless 'data' statements that were
               | poked into memory at 48K and up, right over the basic
               | interpreter, which we had figured out a way to page out
               | and replace from software. This later led to an annotated
               | version of the basic that came with that computer (a
               | version of MS Basic) and subsequently a replacement
               | interpreter with a lot of built in goodies (double speed
               | tape interface, a whole raft of new statements and
               | functions). Good times!
               | 
               | Shout out to my friend Henri G. who did at least half of
               | that work, we had identical home computers (Dragon 32)
               | and worked together a lot on this. He probably still has
               | his in working order :)
        
           | ars wrote:
           | > $180 if I recall correctly, which was a truly staggering
           | number of birthday and Christmas presents
           | 
           | I had the same problems, only I was programming a Laser 128
           | (an Apple II clone) that had a built in System Monitor, which
           | let you directly change memory addresses, but no assembler.
           | 
           | So I photocopied the Assembly to Machine Language chart in a
           | book I got from the library, and did it manually - I learned
           | quite a lot. I remember writing a layout and edge detection
           | routine for a Tetris clone I tried to write (never finished
           | it). Basic was too slow for those critical parts, so I called
           | out to the routine, but did most of the code in Basic.
           | 
           | I remember been utterly wowed that Linux came with a free
           | compiler - I could only dream of having software like that
           | back then.
        
             | dhosek wrote:
             | When OS/2 bundled a C/C++ compiler _and_ a visual interface
             | builder, I was sure there had to be a catch.
        
             | krallja wrote:
             | At least the 6502 has a fairly easy to remember ISA!
        
           | alfiedotwtf wrote:
           | Holy shit thanks for the nostalgia blast... I totally forgot
           | about MS-DOS debug.exe!
        
       | Linda703 wrote:
        
       ___________________________________________________________________
       (page generated 2022-07-25 23:00 UTC)