views:

175

answers:

6

I'm writing an 8086 assembler for a college project . I've gone through some material on compiler design on the internet and am reading the 'dragon book' of compilers . But the problem is I couldn't find much about the assembling (generating object code) part here . Are there any good books or links for assembler design . Where do I start ?, I've gone through lexical analysis,parsing and intermediate code generation .

+4  A: 

Can you just punt and generate a .COM file? It is loaded into a code segment at :0100 and executed with CS, DS, ES, and SS all pointed to that segment.

If you could do that, then generating code gets a LOT easier.

Your test program would be simple

mov dx, 110
mov ah,9
int 21h
mov ax,4c00
int 21

at address 110:
"Hello, World!" 0d 0a 24
Mike Warot
Hmm. Memories from the past just passed by in my mind while reading your code. It has been a long time...
Yves M.
@Yves: Same here, written the same program in 80886, z80, 6301, 6502 and 1802 over the years, but none in the last decade.
Shane MacLaughlin
@Mike, great answer, but you should perhaps point out that the above example requires either MS-DOS or an MS-DOS shell under Windows. God only knows where int 21 would take you in other OS's
Shane MacLaughlin
+1  A: 

You need a mapping between mnemonic instructions like MOV and opcodes see OpcodeMap. Besides that you need the information how many arguments (and width of operators) a instruction requires (encoded in bit fields, that will save you much time if you get this right).

I doubt that the dragon book will help you much.

The Art of ASSEMBLY LANGUAGE PROGRAMMING is a good reference.

stacker
A: 

The dragon book is totally the wrong source because an assembler is not a compiler. The "grammer" of an assembler line is extremly simple (regular grammer - not context sensitive).

The code generation part for an assembler is almost non existing. Get a good reference book about the opcodes of your target CPU and just generate the bytes as explained.

There a few nice simple assemblers out there and you should look at them. Learning by code reading is a very effective way for a college project. You will need it because the Intel Assembler code is extremely ugly at least if you want target some of the extensions as well.

Lothar
A: 

unfortunatelly there's just one proper assembler book:

The Art of ASSEMBLY LANGUAGE PROGRAMMING

google for it. and Mike Warot, wtf is that? 16 bit registers with interrupts - 15 years old code, don't paste something you've just googled.

john
A: 

try to use llvm compiler infrastructure.

http://llvm.org/ProjectsWithLLVM/

plan9assembler