News:

MASM32 SDK Description, downloads and other helpful links
MASM32.com New Forum Link
masmforum WebSite

Code generation

Started by ThoughtCriminal, January 08, 2005, 11:41:42 AM

Previous topic - Next topic

ThoughtCriminal

With so many instructions, can someone give me an idea how assemblers construct individual opcodes?

How FASM,MASM,Goasm, or even Softwire do it?  I'm just looking for the general idea.  I plan to come up with my own method.

Thanks.

Randall Hyde

Quote from: ThoughtCriminal on January 08, 2005, 11:41:42 AM
With so many instructions, can someone give me an idea how assemblers construct individual opcodes?

How FASM,MASM,Goasm, or even Softwire do it?  I'm just looking for the general idea.  I plan to come up with my own method.

Thanks.

I cannot speak for those products you've mentioned, but there are two general ways assemblers generate their instruction's opcodes:

1. The assembler constructs the bit fields for the instruction as it parses the fields of the instruction, and then merges (ORs) these bit fields together to produce the final opcode (plus tacking on any displacement or immediate operands).

2. The assembler generates a set of indexes for each of the operands and then uses an n-dimensional index into an array to fetch the opcodes for the instruction.

Both schemes are a bit skewed by "extended opcodes" (e.g., those beginning with $0F).
A few assemblers do the "table lookup" in code. That is, they load immediate values into registers after parsing the statement. That's generally a cumbersome way to do it, though.

Cheers,
Randy Hyde