I'm working on an assembler for the 8086 . My question is how do you convert the hex opcodes to an executable file like .EXE,.ELF,.COM,a.out etc .Looking for links/resources for this and should the assembler do the linking process or is it done by the OS automatically?
It's fairly complicated, and usually involves two steps:
- The assembler reads in assembly code, figures out the corresponding machine code, and writes it into an object file along with some other info that varies depending on the object file format you're using
- The linker takes a set of object files and merges them together into an executable that can actually be run
Thus the assembler will generally not output executable files; you need to pick an object file format and read up on how to generate that. In theory, as long as you output a valid object file in a given format, any linker should be able to do the actual linking process, but usually assemblers and linkers come as a set, so I'm not sure how well it will actually work in practice (for example, the GNU assembler (gas) outputs GNU-specific relocations and sections that the GNU linker (ld) knows how to handle, so you can't use gas-generated object files in any other linker)
ELF is documented in section 4 of the SV ABI, although you'll need to read your processor's addendum too. COFF is documented as part of the PE spec, although I can't find it hosted on the Internet anywhere; if you need it I can post it somewhere
Here's an article that discusses some executable formats. It should get you started, assuming you're on Windows.
http://en.wikibooks.org/wiki/X86_Disassembly/Windows_Executable_Files