5 ms·
SubX: A minimalist assembly language for a subset of the x86 ISA (2019)
- akkartik 6y agoNot sure what's going on with this website, but I'm happy to see interest in my project: https://github.com/akkartik/mu#readme https://github.com/akkartik/mu#readme OP is an old version of the Readme from a year ago. Here's the current page on SubX: https://github.com/akkartik/mu/blob/main/subx.md https://github.com/akkartik/mu/blob/main/subx.md
- jiofih 6y agoThanks for that. This article is nearly impossible to read on mobile due to word wrapping and riddled with ads. My first thought was “can this lead to easier implementation of a higher level language” and it seems Mu is exactly that? What’s performance like?
- akkartik 6y agoYeah! Most statements translate to a single instruction, and you have to pick registers, so even though performance hasn't been a priority I think it'll tend to be pretty good. It does have some simplifications for safety and clarity rather than optimization. For example, setting a register to zero generates a copy with a 32-bit immediate rather than the xor trick most Assembly programmers would use.
- ant6n 6y agoI’m having the same problem reading the website (wordbreaks, ads). I wonder: * is there a list of instructions that are included? * is it possible to target this x86 subset with some C compiler?
- akkartik 6y agoList of supported instructions: https://github.com/akkartik/mu/blob/main/subx_opcodes https://github.com/akkartik/mu/blob/main/subx_opcodes I haven't tried to implement C, but can't immediately think of a reason why not. Forks strongly encouraged; if you decide to try to implement one, I'd love to contribute.
- dang 6y agoHmm - I've changed the URL to that from https://www.mdeditor.tw/pl/2ZsX https://www.mdeditor.tw/pl/2ZsX. (Thanks!) Was that latter copying your content from somewhere? Also - if you want a different title we can change it.
- akkartik 6y agoThe title seems fine! > Was that latter copying your content from somewhere? It had occurred to me that it might be a Markdown editing service. Maybe somebody tried it out with just the closest Markdown they happened to have on hand? However, looking closer at the Mu history, this seems like the closest version: https://github.com/akkartik/mu/blob/61b8fe6b18c6314268ed24d79bf99de6f55be63b/subx/Readme.md https://github.com/akkartik/mu/blob/61b8fe6b18c6314268ed24d7... The prose isn't identical. I think somebody was rearranging the prose as they made sense of it. So more like notes, maybe? I'm very flattered <3 I'd be ok with either the original link or my link above for precision. And the title could also have a "(2019)".
- drudru11 6y agoNeat approach. I like how you are trying to simplify the problem.
- userbinator 6y agoWith the description of "minimalist" I was expecting something more like http://www.terse.com/ http://www.terse.com/ but this turns out to be even more verbose than regular Asm, more like writing pure machine code. Also, I'm puzzled at the author calling opcode cd syscall --- that's "int imm8", and the real syscall instruction resides on the second page (0f 05). If you're going to write x86 machine code, then memorising the instruction set is far easier in octal: https://gist.github.com/seanjensengrey/f971c20d05d4d0efc0781f2f3c0353da https://gist.github.com/seanjensengrey/f971c20d05d4d0efc0781...
- akkartik 6y agoThe stuff after / is often just comments. 'syscall' feels more accurate for int 80 than 'interrupt', but the language doesn't encode the name. I only found out about the octal after I started on SubX. I considered switching to it, but thought it might be useful to keep the same opcodes as the Intel manual.
- akkartik 6y agoThanks for the pointer to terse! I hadn't seen it before. I think of concise as "expressive" or "cryptic". "Minimalist" usually connotes small implementation. Like chibicc or something.
- jart 6y agoHere's another octal x86 reference for comparison: https://justine.lol/blinkenlights/8086.html https://justine.lol/blinkenlights/8086.html
- akkartik 6y agoOh I'd missed that page on the blinkenlights site. Thanks!
- jart 6y agoI hope you enjoy it! Since you mentioned chibicc earlier in this thread, and you've written an assembler of your own, this might be of interest to you: https://github.com/jart/cosmopolitan/blob/master/third_party/chibicc/as.c https://github.com/jart/cosmopolitan/blob/master/third_party... Your work was brought to my attention maybe a year and a half ago and I think what you're doing is pretty cool. Feel free to reach out by email if there's anything I can do to help.
- fernly 6y agoSorry, I find this quite confusing. I'm familiar with more than one assembly language and SubX -- to the extent I can follow the docs -- seems excessively complicated and inconsistent, compared to a conventional one. Actually this may just be bad documentation. Turning to the list of opcodes[1], which exactly are the opcodes in, 01: add r32 to rm32 (add) 03: add rm32 to r32 (add) 05: add imm32 to EAX (add) ....etc Is "01:" the opcode? Meaning we should memorize the hex values that it is the normal assembler's job to produce? And how does something like bb: copy imm32 to EBX (mov) relate to the example code bb/copy-to-ebx 1/imm32 If "bb" is the opcode, why does it need to be repeated as text (metadata?) saying the same thing, only in a different order to the table? If the way to write a "bb" instruction is the above, what is the way to write an "0f" instruction? 0f 86: jump disp32 bytes away if lesser or equal (addr, float), if ZF is set or CF is set (jcc/jbe/jna) I mean I'm guessing it would start "0f/" but after that, how much gets repeated and with what metadata? [1] https://github.com/akkartik/mu/blob/main/subx_opcodes https://github.com/akkartik/mu/blob/main/subx_opcodes
- akkartik 6y agoYeah, OP is probably not the best place to understand what the purpose of this project is. The list of opcodes is just a list for consulting. It's only about the opcodes, it says nothing about the expected arguments and so on. To understand how to invoke an opcode you'd have to read either the forbidding Intel manual or something terser like https://c9x.me/x86 https://c9x.me/x86 as cited at the bottom of OP. The '/copy-to-ebx' after the slashes is just my way of helping the reader understand what the instruction does. I don't want the reader to have to consult the Intel manual for every instruction, even if I'm forcing the writer to do so. So why am I forcing the writer to do so? Mu's goal is to build a computer where compound things can be understood in terms of their constituent parts. Most assemblers are implemented in C, and if you wanted to understand what a line of C does, in a specific context, you might imagine expanding the C into.. its generated Assembly. Now you're in a circular situation where you need to understand Assembly to understand Assembly. So I started out with the goal of implementing an assembler in machine code. And Assembly is surprisingly complex. There's a reason nobody builds it in C anymore. So I ended up on my current trajectory, of making the code writer do more work just so the code reader doesn't have to deal with cycles. With hindsight, it all feels quite inevitable and fore-ordained. You can read more in a 2-part blog post that starts at http://akkartik.name/post/mu-2019-1 http://akkartik.name/post/mu-2019-1, and there's also an academic paper at http://akkartik.name/akkartik-convivial-20200607.pdf http://akkartik.name/akkartik-convivial-20200607.pdf that goes into some of my sociopolitical goals (in a sentence: "everybody should spend some time auditing the software (and laws) that run their society". For a paragraph-length exposition see the top of https://github.com/akkartik/mu#readme https://github.com/akkartik/mu#readme.)