This is a working Hello World program exe for Windows x64 manually written in binary. No, not assembly. No compiler, no assembler, no linker.
Of course I couldn't directly write the actual bits. Instead, I wrote the 0 and 1 characters into a text file and used a Python script to create a new .exe file and copy the 0s and 1s as actual bits.
Take a look at the text file! I added comments to not go fully insane, so maybe you can figure out what bits do what and change them!
Most of the file is just padding bytes and headers. The actual program code can be found on lines 136-150.
I had to learn the actual binary structure for x86-64 codes, and now I understand why people like RISC-V so much.
I also had to manually calculate the memory displacements every time I changed the code. I will hopefully never do this again.
This is kind of useless, and I don't recommend programming like this, but I learned a lot, and assembly seems a lot easier now that I understand what it actually does. Oh, and I am now one of the few people who can list binary as one of their programming languages...
- PE format documentation: https://learn.microsoft.com/en-us/windows/win32/debug/pe-format
- x86 encoding documentation: https://wiki.osdev.org/X86-64_Instruction_Encoding
- Intel x86 reference: https://www.felixcloutier.com/x86/
- x64 calling convention: https://learn.microsoft.com/en-us/cpp/build/x64-calling-convention?view=msvc-170