Just out of interested I would like to write a small program in machine code.
I am currently learning about registers, ALU, buses and memory and I'm slightly fascinated that instructions can be written in binary instead an assembly language.
Would a compiler would need to be used?
Preferably one that runs on OSX.
You would not use a compiler to write raw machine code. You would use a hex editor. Unfortunately, I don't use OSX, so I can't provide you a specific link to one.
If you write machine code, you will need to learn how to write the binary headers required by your OS as well. I would recommend doing so and testing with an assembler in raw output format first; once you understand the binary layout it is a purely mechanical task to hand-assemble this to machine code.
You would use a hex editor. I recommend instead of doing that though, learn assembler first. Assembler is basically a language with a 1:1 correspondence between human readable mnemonics and the machine readable hex bytes. For that, you would probably like to look at http://ref.x86asm.net/ and find an assembler that works on x86 Macs. I believe yasm should work.
Writing anything directly in hex is extremely difficult, and your time would probably be spent learning assembly and the underlying machine code that an assembler generates
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With