Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What compiler would I use to write machine language?

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.

like image 408
Riess Howder Avatar asked May 25 '11 17:05

Riess Howder


2 Answers

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.

like image 125
bdonlan Avatar answered Sep 19 '22 14:09

bdonlan


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

like image 30
Earlz Avatar answered Sep 21 '22 14:09

Earlz