Re: assembler design

George Peter Staplin <georgeps@xmission.com>
13 Jul 2004 12:05:05 -0400

          From comp.compilers

Related articles
assembler design macluvitch@hotmail.com (2004-05-30)
Re: assembler design praseedpai@yahoo.com (2004-06-30)
Re: assembler design georgeps@xmission.com (George Peter Staplin) (2004-07-13)
| List of all articles for this month |
From: George Peter Staplin <georgeps@xmission.com>
Newsgroups: comp.compilers
Date: 13 Jul 2004 12:05:05 -0400
Organization: nil
References: 04-05-100 04-06-131
Keywords: design
Posted-Date: 13 Jul 2004 12:05:05 EDT

on praseed wrote:
> macluvitch@hotmail.com (macluvitch) wrote
>> Well I'm trying to write a simple assembler with intel syntax.
>> I've got a look at gasm source (the gnu assembler) to get an idea on
>> how it's implemented or especially how it translates mnemonics into
>> opcodes, it's so complicated the way he does .
>> it uses a struct table representing the mnemonic token, it's
>> equivalent opcode,
>> how many arguments...
>>
>> for example these following statements haven't the same opcodes
>> mov ah, mem
>> mov mem, h
>>
>> so we have to say invent a way to handle all different possible ways
>>
>> please can anybody clear things up for me
>
> Hi ,
> I feel taking a look at SoftWire Dynamic Assembler Project (
> http://softwire.sourceforge.net/ ) will give u a better idea of how to
> translate the mnemonic sequence into code. The Source code is readable
> ( as it is written in C++ as opposed to C ). I have used the source
> code there to study about instruction encoding for pentium processor.
> ( And has written a
> dynamic compiler for a high level basic like language thanks to that )


Softwire is interesting, but I suspect it will have problems with some
operating systems. The next service pack for Windows XP, as well as
the current OpenBSD, NetBSD (2.0), and others that have a malloc that
allocates memory that isn't PROT_EXEC will segfault if you try to jmp
into a malloc'd region of memory.


The correct way in Windows is to use:
  VirtualAlloc (NULL, s, MEM_COMMIT, PAGE_EXECUTE_READWRITE)
In unix you most likely want something like:
    mmap (NULL, s, (PROT_EXEC | PROT_READ | PROT_WRITE),
    (MAP_ANON | MAP_PRIVATE), -1, 0);




May your bits toggle ...


George


Post a followup to this message

Return to the comp.compilers page.
Search the comp.compilers archives again.