views:

258

answers:

4

I am writing a Tiger compiler in F# and I have decided to emit x86 assembly. I know the basics of how a machine is constructed and also a bit of assembly, but not enough to write a good compiler back-end.

What resources can you recommend for learning what I need to know?

Where can I look up information such as calling conventions, etc.?

My plan is to get an inefficient back-end working correctly and then gradually improve it. For the first version I am looking for information about the subset of instructions and registers which I will actually need for a rudimentary back-end. Some kind of tutorial might be nice.

+2  A: 

For x86 and x64 assembly, I suggest the ultimate reference:

Intel® 64 and IA-32 Architectures Software Developer's Manuals

For calling conventions, system calls, etc., you should also consult documents for the OS you're building on.

Mehrdad Afshari
+2  A: 

How about looking at nanojit? It's for JIT compilation, but it creates instruction streams from an intermediate language. You should be able to base your work on it.

You could also look at C-- by Simon Peyton Jones.

plinth
+1 for nanojit instruction set
wuub
A: 

This is not a tutorial, not a reference or something you should do in your code. But taking a look at (non obfuscated) version is worth the time: http://bellard.org/otcc/.

Scary :D

wuub
A: 

Just out of curiosity, what are your design goals? To learn more about computers? Assembly? To make a fast compiler?

If you want to learn about assembly and you're starting from the ground up, x86 or x64 is definitely not where I'd start. It's is a very complicated instruction set (relatively speaking) and is a tough one to start with.

If you want to make something that can generate fast code, maybe emit straight-up C and then call another compiler to compile the C. You should eventually be able to replace your C layer with an assembler layer when your compiler is all put together... Just a thought...

Dave Markle
Based on the previous questions I would say that Jørgen wants to learn as much as he can about inner workings of a compiler. IMO he's doing it pretty well actually, F# + assembly + pragmatic approach :)
wuub
My goal is definitely to learn more about compilers. I figure my prior (limited) knowledge of x86 assembly will help me.
Jørgen Fogh
I guess my only point is that I think before you start writing a compiler, you should write some assembly programs first -- it sounded to me in your question like you were skipping a step :)
Dave Markle
http://en.wikibooks.org/wiki/X86_Assembly
Dave Markle