|Writing my first compiler Yarrago@hotmail.com (2002-03-17)|
|Re: Writing my first compiler firstname.lastname@example.org (Joachim Durchholz) (2002-03-19)|
|Re: Writing my first compiler missoulaleo@DIE_SPAMBOT_DIEearthlink.net (john thrum) (2002-03-19)|
|Re: Writing my first compiler email@example.com (Dobes Vandermeer) (2002-03-21)|
|From:||Dobes Vandermeer <firstname.lastname@example.org>|
|Date:||21 Mar 2002 21:59:25 -0500|
|Posted-Date:||21 Mar 2002 21:59:25 EST|
> front end however the backend is causing me a bit of concern. I want
> my compiler to output 16bit dos exe's. I have several books on the
> it be best if I write an assembler or just integrate this into the
> back end?
Besides macros & labels, the main difference between assembly language and
machine code is the encoding. For example:
or in machine code:
If you already know the instruction you want to emit, it is very easy
to figure out the machine-code equivalent byte-codes (given the intel
instruction set reference, available from intel's web site somewhere).
Assemblers also provide some minor instruction selection services by
choosing the "best" matching instruction with the given name, which
you would have to emulate yourself, probably by making macros for each
op & addressing mode combo you want to use, like: #define
emit_ADD_reg_imm(reg,imm) (if(imm <= 127 && imm >= -128 && reg ==
reg_EAX) printf("\04%c", imm);)
Or somesuch. Its likely you could come up with a better idea than
this, I'm just trying to illustrate that its actually fairly simple.
> help me with this final step in either writing an assembler or adding
> the execute output to the backend of my compiler? Is an assembler
> basically a matter of converting the mnemonics into opcodes and
> linking the file with a header to make it into an execute or is there
> more to it?
If you are using direct interrupts to communicate with the BIOS, and
not linking with any libraries, then that is all you need. If your
curious about the contents of that header you can, of course, compile
a simple (or empty) program with an existing compiler and disassemble
it to see what they put there.
Return to the
Search the comp.compilers archives again.