tags:

views:

35

answers:

3

Just curious, if open a hex editor and type opcodes manually and save it. Such as move 1 to register 1 move 2 to register 2 then call add, would that give me working program? Or does some how automating this gives me crappy compiler?

EDIT: Forgot about OS, I have Mac OS X and Linux at my disposal, x86's as the CPU.

A: 

As long as you have the proper file format for the binary then yes.

Old DOS .com files were just this - the raw program serialized out to disk. .exe files and unix ELF files have a structured format to them which includes (among other things) relocation information.

Aaron
+1  A: 

As I noted in the comments, the OS/platform is important here. Most platforms will expect some sort of structure to an executable (if only a header etc.). e.g. see the a.out format as used by older versions of Unix.

As you've indicated you have Mac OS X, check out the Mach-O format.

Beware that typing 'A0 A1'... etc. is different from putting the actual bytes (in this case 160/161) in the file.

Brian Agnew
i am thinking of writing a script to do the writing or do it with a hex editor. But does it need to be structured? or would it still work?
Hamza Yerlikaya
The OS will expect some sort of format
Brian Agnew
A: 

Only if the file is a properly formatted executable binary file. See references on the COFF and ELF formats, for example.

You could also dump the contents of a small executable file using od if you're curious about what a particular executable file looks like.

Loadmaster