6 ms·
x86 is the worst ISA. If you want to play with assembler without feeling a desire to stab yourself and end it all, I recommend ARM. Or go learn Z80, x86's weir
by qwertyuiop924 10y ago
x86 is the worst ISA. If you want to play with assembler without feeling a desire to stab yourself and end it all, I recommend ARM.
Or go learn Z80, x86's weird, 8-bit cousin (it had a 16-bit version, but it sold poorly), which had a greater emphasis on backwards compatability (you can run code from the original 8080 on a Z80, unchanged), and is nicer to work with (because it wasn't extended in unticipated directions far beyond its original capabilities, while keeping fetishistic backwards compatability by stacking hack on top of hack on top hack. It also didn't have memory segmentation, otherwise known as The Worst Thing.)
There are only two common reasons to learn Z80 assembler, though: to program the Gameboy (which runs on a modified Z80 with all the cool instructions removed), and to program a TI calculator, thus making all highschoolers in your area immensely happy.
TI calculators are a comically overpriced scam, that have only survived because of the College Board, but that's another story.
- umanwizard 10y agoThis is about learning to read, not learning to write. If you're ever in a situation where you need to read assembly, it's typically not up to you what ISA it'll be in. There are two situations where I've had to read assembly: either reverse-engineering a compiled binary or trying to understand the compiler output for a small piece of a program I'm working on in a higher-level language.
- qwertyuiop924 10y agoOh. Well then, yeah. Besides, you don't have to worry about the worst of x86 in those cases. I'm pretty sure everyone has to learn at least that much x86 at some point, like it or not.
- toast0 10y agoI'm not sure everyone has to learn even that much. I've managed to avoid it until very recently and I'm more willing to dive into underlying code than most people I know (I've contributed to a FreeBSD kernel patch in TCP and an OpenSSL key exchange interoperability fix)
- qwertyuiop924 10y agoI haven't jumped into the kernel yet. But I'm only 15. I still have time.
- int_hdlr 10y agoThis is not a piss contest.
- qwertyuiop924 10y agoNever said it was. Actually, it was more along the lines of that being a thing I should do at some point.
- umanwizard 10y agoI don't think that's true. I work at a major software company and certainly not all of my coworkers are interested enough in low-level stuff to ever need to read assembly. It's a good skill to have, and since not everyone has it you will often be able to solve problems that no one else can.
- rzzzt 10y agoMy use case is inspecting a backtrace from a core dump.
- muterad_murilax 10y ago> There are only two common reasons to learn Z80 assembler, though: to program the Gameboy [...] and to program a TI calculator What about the myriad of other (mostly vintage) computer systems and video game consoles out there? ;) Sega Master System and Game Gear, for example.
- qwertyuiop924 10y agoThey're not as common reasons. But yes, if you want to program your TRS-80 (but only the original: later ones were 6502), or your ZX* (How many of you lot know the ZX line? Spectrum? No?), or your Game Gear, or your Master System, or any of the various CP/M machines, you have to learn Z80.
- userbinator 10y agoHow many of you lot know the ZX line? Spectrum? No? The ZX Spectrum and its clones were very popular in the UK, Eastern Europe, and the former USSR.
- qwertyuiop924 10y agoYeah. AFAICT, most of HN (myself included) is US based. So I was curious.
- pjmlp 10y agoThey also ruled in Portugal and Spain. Almost no C64 in sight beyond a few computer magazines.
- mangamadaiyan 10y ago... and for a brief period of time in the late '80s, "popular" in India as well. (I quoted popular because they were bloody expensive. In 7th grade, a kid in my class had one. He was the only one in all of the school to have a computer.).
- qwertyuiop924 10y ago
- blueatlas 10y agoAnother good one for learning is the 6502. Don't forget to buy a copy of Lance A. Leventhal's "6502 Assembly Language Programming". Great book for learning not only assembly, but also the fundamentals leading up to assembly.
- qwertyuiop924 10y agoOf course. Who hasn't wanted to write their own chiptunes? Grab your (emulated) Ricoh 2A03 (and your emulated Konami VRC VI, for some extra fun), and get hacking. And thanks for the book reccomendation.
- _JamesA_ 10y agoAmen. I learned to program on the 6502 based VIC-20 using Lance Leventhal's "6502 Assembly Language Subroutines" as a guide by manually assembling and poking into memory. What a fun time.
- honkhonkpants 10y agoI never felt more like stabbing myself than when trying to cipher out exactly which immediate values are possible on ARM, and which are not. X86 I happen to enjoy. It is not "the worst ISA" by any means. It has wonderful code density, which turns out the be very important. There's a reason that x86 won and continues to win.
- JoeAltmaier 10y agoWhen originally invented the x86 instruction set was efficient - the most-used instructions had shorter byte code sequences. But eventually some instructions got 'left behind' by the compilers. There are a whole host of single-byte instructions that are never, ever used by a compiler - the register exchange instructions for instance (xchg eax, ebx). Compilers just schedule destination registers carefully, never need to swap them around. Also the whole set of exchange-register-with-itself were defined but never used. E.g. xchg ax,ax which does nothing in one byte. In fact that one was considered useful, its used as the 'no-op' instruction (0x90) right? But what about xchg bx,bx, xchg cx,cx and so on? Just wasted single-byte opcodes. Leaving actual common instructions to use longer bytecode sequences. So maybe an executable should begin with an opcode-decode-table that is loaded with the code, that tells the hardware what byte sequences mean what instructions. So each executable code can be essentially compressed, using optimum coding for exactly the instructions that code uses most often. Just thinking out loud.
- qwertyuiop924 10y agoThat would be cool, but I would not want to hand-code assembly on such a platform. That makes memory segmentation look fun.
- JoeAltmaier 10y agoThe table could be created from your assembly automatically? I would never want to code the hex directly in any case.
- 10y ago
- wolfgke 10y ago> x86 is the worst ISA. x86 is clearly not a beautiful ISA, but it is not as black as it is painted. The first thing that one should understand is large parts of the encoding of the instructions make a lot more sense once one writes them down in octal instead of hexadecimal (something even the Intel people who wrote the reference manual seem to have missed): > http://www.dabo.de/ccc99/www.camp.ccc.de/radio/help.txt http://www.dabo.de/ccc99/www.camp.ccc.de/radio/help.txt
- qwertyuiop924 10y ago...that really doesn't help with the issues I have: the instruction set is an absolutely ugly jumble of almost 40 years of religious backwards compatability, odd hacks, and various extensions.
- wolfgke 10y ago> an absolutely ugly jumble of [...] religious backwards compatability, odd hacks, and various extensions Like POSIX, MS-Windows, X11, WinAPI, C++, HTML5, ... ;-)
- qwertyuiop924 10y agoHey, I didn't say it was the only one. Although POSIX and HTML5 hold up a bit better than Win32 and C++, IMHO. Especially POSIX (it's not great, but it works pretty well). But I've heard X11 is absolutely miserable, so the windows folks don't have a monopoly on satanically evil APIs with religious backwards-compatability.
- SeanDav 10y agoIn my day I wrote a fair amount of x86 assembly language. I found it fairly easy and straight forward. There are probably even less reasons to learn it these days but nothing gives you a better idea of how a computer works (arguably, besides microcode, but that is a different kettle of fish).
- qwertyuiop924 10y agoThe simple stuff's alright, but if you want to do anything performant, it gets hairy pretty fast, as you wade through almost 40 years of expansions and ugly hacks.
- gtirloni 10y agoCould you elaborate in which situation you faced this issue?
- qwertyuiop924 10y agoTrying to learn it, at least beyond the basics. Maybe I'm crazy, and I'm definitely inexperienced. So maybe take my opinion with a grain of salt? But yes, so far as I've seen, trying to understand x86 in its present state is a painful experience.
- woofyman 10y ago>It also didn't have memory segmentation The Z80 only has a 16-bit address space. My favorite CISC architecture is the 68000 series.
- qwertyuiop924 10y agoYes. But you could install an MMU. The 68k (and it's 8-bit semi-cousin, the 6809) were very nice. However, unlike the Z80, the 6502, and x86, they're no longer being made, and are increasingly rare.
- RandomOpinion 10y ago68k Macs are easy enough to find on eBay. Grab one of the old Powerbook 1xx series laptops and you have a self-contained development station that's less expensive than many modern microcontroller dev kits.
- emptybits 10y agoThe 68k is still being made in the form of the 680x0-compatible line from NXP. http://www.nxp.com/products/microcontrollers-and-processors/more-processors/coldfire-plus-coldfire-32-bit-mcus/68kmpus-legacy/m680x0:DR68K68KM68X0 http://www.nxp.com/products/microcontrollers-and-processors/... They're in the "legacy" line and labelled "not recommended for new design" but I think that's just design opinion and doesn't imply it's no longer made. I'm sure this video has done the HN rounds before. It's a slow but fascinating watch. "Motorola 68000 Oral History Panel" from original Motorola team members. https://www.youtube.com/watch?v=UaHtGf4aRLs https://www.youtube.com/watch?v=UaHtGf4aRLs
- busterarm 10y agoI'd recommend learning 68k instead. Or MIPS. But definitely Z80 over x86. x86 is pain.
- qwertyuiop924 10y agoI wish 68k, but it's out of production (as is the 6809, its equally awsome 8-bit cousin). MIPS and ARM are fun, though, AFAICT. As is 6502.
- pat_shaughnessy 10y ago(author here) ...FYI I actually learned assembly language for the first time back in the 1970s and 80s using a 6809 inside a Radio Shack "Color Computer." I was super-fun at the time. I don't remember much of it now but I'm sure x86 isn't as clean or fun as 6809 assembly was.
- qwertyuiop924 10y agoSpoiler: it wasn't. I've looked over both, and that's pretty immediately clear.
- Gracana 10y agoIf you want something friendly and CISC-y and modern, check out the Renesas RX600 and friends. They have a nice instruction set and zero-wait-state RAM and ROM, so writing assembly by hand with predictable timing ought to be easy. https://www.renesas.com/en-us/doc/products/mpumcu/doc/rx_family/r01us0032ej0120_rxsm.pdf https://www.renesas.com/en-us/doc/products/mpumcu/doc/rx_fam...
- qwertyuiop924 10y agoHey. Neat. Thanks for the link.
- minimax 10y agoIt also didn't have memory segmentation, otherwise known as The Worst Thing. The examples in the post are clearly x86-64 running in 64 bit mode. I.e. it's running in flat model... there is no segmentation to worry about.
- wolfgke 10y agoThe segment registers fs and gs still exist in x86-64 and are used. Under Windows gs (under x86-32 fs) points to the Thread Information Block (TIB): > https://en.wikipedia.org/wiki/Win32_Thread_Information_Block https://en.wikipedia.org/wiki/Win32_Thread_Information_Block Under Linux gs is used for thread-local storage (TLS). But "as a typical programmer" indeed you only have to worry about the internal details of this if you are an OS developer, otherwise you can simply use the appropriate segment override prefix and otherwise don't care about it.
- qwertyuiop924 10y agoOh. Handy. I didn't know that. Stupid outdated resources...
- CalChris 10y agoGoogle's Native Client uses segmentation to enforce sandboxing. http://static.googleusercontent.com/media/research.google.com/en//pubs/archive/34913.pdf http://static.googleusercontent.com/media/research.google.co...
- EvanAnderson 10y agoI agree that the x86 ISA is pretty warty (though I have a strange fondness for it), but I'd recommend 6502 rather than Z80. There are a lot of fun retro-computer platforms that are 6502-based. Thinking of the zero-page functioning as a register-bank is really fun, too.
- spc476 10y agoFor 8-bits I'd recommend the 6809. Two 8-bit accumulators that can be used as a 16-bit accumulator, 4 16-bit index registers (that can largely be interchanged, except for S which is also the stack register) and you can generate pure relocatable code. And the zero-page isn't restricted to address $0000.
- qwertyuiop924 10y agoYeah, but those are hard to get.
- EvanAnderson 10y agoThis sounds really interesting. I've never taken a look at the 6809 before. I happen to have a working Tandy CoCo I scored in a vintage computer haul. I'll definitely check out 6809 assembler.
- qwertyuiop924 10y agoI know that asxxxx will assemble for the 6809, if you need an assembler.
- DonaldFisk 10y ago> x86 is the worst ISA. I can only assume you've never had to program a Burroughs B90 in assembly language.
- qwertyuiop924 10y agoI haven't. It's probably not fun.
- DonaldFisk 10y agoIt wasn't easy. Very asymmetric, not many registers, and tiny stack. The only things that were written directly in it were the operating system, and the virtual machines for higher level languages such as COBOL and MPL, because it was too hard to compile to. I worked on the virtual machines. After programming in it, I can assure you that programming in other assembly languages (including x86) is a breeze. I should put my cheat-sheet on the web, if I can still find it.
- AlphaSite 10y agoIsn't the high level Burroughs assembly a compertly insane almost high level language? I looked into implementing it into my assembler and just ran in the other direction when I saw how much unnecessary co plexity there was in the language.
- pjmlp 10y agoOn the other hand it allowed for ESPOL and NEWP, two memory safe systems programming languages, with unsafe memory access having to be marked as such.
- DonaldFisk 10y agoB90 was an 8 bit machine and was built at Cumbernauld in Scotland, where I worked. The B900 had similar architecture. There was also a B1900 built in Liège in Belgium, which was a 24 bit machine whose instruction set was designed to run virtual machines (i.e. interpreters). Those systems had a reputation for being slow. I don't know much about them. The Liège plant closed around 1982 and the Cumbernauld plant closed around 1985. Burroughs mainframes (B5000 onwards to A series) may be the ones you're thinking of. These are justifiably praised for being ahead of their time. They were high level stack based machines with 48 bit words + 3 tag bits, and programmed directly in an Algol 60 variant, with additional instructions to enable COBOL to execute efficiently. There was no assembly language needed.
- Annatar 10y agox86 is the worst ISA. If you want to play with assembler without feeling a desire to stab yourself and end it all, I recommend ARM. Yes, intel is really bad, especially for learning, and while ARM is certainly better, it's pretty esoteric, and also backwards (right to left) like intel. If you want a nice, orthogonal ISA to learn assembler on, MC68000 family is a song. The instructions are human readable, the processor is big endian, and the moves are src, dst. It's almost like a high level programming language.
- qwertyuiop924 10y agoI would argue for the 6502 over the 68000. The 6502's a bit less simple to learn, but I'd say it's worth it. It worked its way into many important computers, and is arguably one of the most emulated and most used processors in existence.