Parser done, now I am trying to create the code generation part?

Started by David, April 24, 2010, 10:18:18 PM

Previous topic - Next topic

David

Hi guys, so I finished the parsing part, now I need to convert my assembly code into hex...  Can anybody link me to some good resources on making an assembler for my programming language?

The only operands I am planning on implementing are:

PUSH, POP, CALL, ADD, SUB, and MOV.    I know that jumps will be too hard for me right now, and theres no use adding CMP or TEST if theres no jumps.  So where can I find a good read on doing this?  I would also need to construct the import table.

Basically I am thinking about going about it like this:

Create an EXE file, open it in a hex editor.  Steal it's Hex data, and add hex data to the middle.  But I am pretty confident that is not how it's done.  Anyway, to get back on topic, can anybody please link me to a good read about this?  I already know PE header format, the only problem is I wouldn't know how to create it in hex.

Thanks, David.

dedndave

nothing like reading it from the horses mouth...

http://www.intel.com/products/processor/manuals/

if you are going to employ CALL, JMP shouldn't be that hard
as for conditional branches, there are only 16 basic ones
you can read all about them in the manuals

Slugsnack

the book called "engineering a compiler" was really useful to me when i made a compiler. the code gen is not the hard part, optimization is

joemc

If you make call you might want to make ret too :)
edit: ohh yeah you might just want to call the windows API.
Implementing CMOV might be easier than JMP, atleast i imagine it can be done in one pass instead of two. and it could help with some program flow.

Slugsnack

oh i had mistaken this thread thinking OP was making a compiler. assembler is a different matter. in that case, intel manuals that dave linked to are definitely where you want to be looking.