0

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.

Lance Roberts
  • 22,383
  • 32
  • 112
  • 130
Hamza Yerlikaya
  • 49,047
  • 44
  • 147
  • 241

3 Answers3

1

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
  • 268,207
  • 37
  • 334
  • 440
0

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
  • 9,123
  • 5
  • 40
  • 38
0

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.

David R Tribble
  • 11,918
  • 5
  • 42
  • 52