There are a couple of related questions here. Consider a program consisting only of the following two instructions
movq 1, %rax
cpuid
If I throw this into a file called Foo.asm
, and run as Foo.asm
, where as
is the portable GNU assembler, I will get a file called a.out
, of size 665 bytes on my system.
If I then chmod 700 a.out
and try ./a.out
, I will get an error saying cannot execute binary file
.
- Why is the file so large, if I am merely trying to translate two
asm
instructions into binary? - Why can the binary not be executed? I am providing valid instructions, so I would expect the CPU to be able to execute them.
- How can I get exactly the binary opcodes for the
asm
instructions in my input file, instead of a bunch of extra stuff? - Once I have the answer to 3, how can I get my processor to execute them? (Assuming that I am not running privileged instructions.)