Re:Compiling to Assembly from Scratch [free to read online]
by eterps on Monday September 23, 2024 @04:21AM
(#41623674)
You should definitely look at: https://github.com/akkartik/mu/blob/main/subx.md
[ Parent
| on HN ]
Re:Compiling to Assembly from Scratch [free to read online]
by eterps on Monday September 23, 2024 @04:24AM
(#41623699)
Also, running machine code directly can be done like this:
Re:Compiling to Assembly from Scratch [free to read online]
by alok-g on Monday September 23, 2024 @04:34AM
(#41623774)
This is cool! This is how I used to do also by embedding hand-written machine code within a BASIC program and calling it to run natively.
Re:Compiling to Assembly from Scratch [free to read online]
by eterps on Monday September 23, 2024 @07:18AM
(#41624816)
> This is how I used to do also by embedding hand-written machine code within a BASIC program and calling it to run natively
Me too; that's also the reason why I wanted that possibility back.
Re:Compiling to Assembly from Scratch [free to read online]
by alok-g on Monday September 23, 2024 @04:35AM
(#41623785)
SubX seems like an assembly language itself following a subset of x86 32-bit instructions. Would looking into this help me understand how to translate from assembly to machine code manually? Thanks.
Re:Compiling to Assembly from Scratch [free to read online]
by akkartik on Monday September 23, 2024 @10:30AM
(#41626539)
SubX is a weird thing (I built it) that is somewhere between machine code and Assembly language. You have to type in the opcodes directly, which people typically associate with machine code. But it smooths some aspects of programming in machine code. You'll get nice errors if you accidentally write invalid machine code, it won't just go off and run data as code or something like that.
I'd be happy to support you if you choose to try it out! Ask as many questions as you like.
Even if you choose not to, you might like the cheatsheet in the repo (from https://net.cs.uni-bonn.de/fileadmin/user_upload/plohmann/x8...)
Re:Compiling to Assembly from Scratch [free to read online]
by alok-g on Monday September 23, 2024 @02:03PM
(#41628809)
Thanks! I understand better now.
And that cheat sheet PDF is cool, exactly what I was looking for. Any chance you are aware of something similar for x64? Thanks.
Re:Compiling to Assembly from Scratch [free to read online]
by akkartik on Monday September 23, 2024 @03:38PM
(#41629706)
No, sorry. Honestly I spent a long time going to the source of the 3-volume Intel manual. (There's link to them as well in my Readme.) I think that's really what you need to do for machine code, if you're not using Assembly or Assembly-ish that has done that work for you. But then any Assembly language will have its own manual you need to bone up on.. That's mostly why I built SubX: the manual is like 10 pages, and I distilled down the parts of the Intel manual you need to know. But yeah, only for 32-bit. I always found x64 very hacky with the register bits split up between bytes and whatnot. 32-bit is a legitimately nice ergonomic machine.