Gmail Calendar Documents Reader Web more »
Recently Visited Groups | Help | Sign in
Google Groups Home
In-memory x86 assembler
There are currently too many topics in this group that display first. To make this topic appear first, remove this option from another topic.
There was an error processing your request. Please try again.
flag
  6 messages - Collapse all  -  Translate all to Translated (View all originals)
The group you are posting to is a Usenet group. Messages posted to this group will make your email address visible to anyone on the Internet.
Your reply message has not been sent.
Your post was successful
 
From:
To:
Cc:
Followup To:
Add Cc | Add Followup-to | Edit Subject
Subject:
Validation:
For verification purposes please type the characters you see in the picture below or the numbers you hear by clicking the accessibility icon. Listen and type the numbers you hear
 
Shasank  
View profile  
 More options Oct 15, 3:24 pm
Newsgroups: comp.lang.asm.x86
From: Shasank <shas...@MUNGED.microcosmotalk.com>
Date: 15 Oct 2009 19:24:11 GMT
Local: Thurs, Oct 15 2009 3:24 pm
Subject: In-memory x86 assembler

Hi.  I'm working on a project that involves translating a proprietary
byte-code language into x86 machine code on the fly.  Currently this
language is interpretted at runtime.  By translating the byte-code
into x86 instructions at compile-time, we can execute the code
natively at runtime using a function pointer to the instructions
stored in data.

Initially I was planning on writing this translation phase myself,
since the instruction set of the byte-code language is fairly simple
and straightforward.  But I wonder, is there an in-memory based x86
assembler available for use that we can build and link into our
product, which takes, as input, a buffer of ascii text representing a
function written in x86 assembly, and returns the machine code in a
separate memory buffer?

There are free x86 assemblers out there, but I would have to modify
the code and build it as a dll.  I would also have to modify the
output generation code to write the data to a memory buffer.  These
are things I can do, but I'm wondering if any of you have done that
already?  Also, this would be for commercial use.  And lastly, an
assembler that has optimization phases built into it would be a
significant plus.

Thanks.

- Shasank


    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
BGB / cr88192  
View profile  
 More options Oct 15, 4:15 pm
Newsgroups: comp.lang.asm.x86
From: "BGB / cr88192" <cr88...@MUNGED.microcosmotalk.com>
Date: 15 Oct 2009 20:15:16 GMT
Local: Thurs, Oct 15 2009 4:15 pm
Subject: Re: In-memory x86 assembler

"Shasank" <shas...@MUNGED.microcosmotalk.com> wrote in message

news:4ad776db$0$5642$9a6e19ea@unlimited.newshosting.com...

> Hi.  I'm working on a project that involves translating a proprietary
> byte-code language into x86 machine code on the fly.  Currently this
> language is interpretted at runtime.  By translating the byte-code
> into x86 instructions at compile-time, we can execute the code
> natively at runtime using a function pointer to the instructions
> stored in data.

yep.

> Initially I was planning on writing this translation phase myself,
> since the instruction set of the byte-code language is fairly simple
> and straightforward.  But I wonder, is there an in-memory based x86
> assembler available for use that we can build and link into our
> product, which takes, as input, a buffer of ascii text representing a
> function written in x86 assembly, and returns the machine code in a
> separate memory buffer?

my assembler can do this (does require that the frontend provide some
callbacks, mostly for allocating the buffer, ...), although typically I have
been using it with its own internal in-memory linker...

it can also produce COFF objects (Win32 and Win64 / x64 variants), ...

> There are free x86 assemblers out there, but I would have to modify
> the code and build it as a dll.  I would also have to modify the
> output generation code to write the data to a memory buffer.  These
> are things I can do, but I'm wondering if any of you have done that
> already?  Also, this would be for commercial use.  And lastly, an
> assembler that has optimization phases built into it would be a
> significant plus.

well, there is mine, and it is here:
http://cr88192.dyndns.org/2009-10-15_bgbasm2.zip

granted, it is LGPL, but if this is a problem, I may be able to provide a
version with the notices "mysteriously" removed (actually, I may or may not
get around to moving my whole VM project to BSD for other reasons).

(note: LGPL is not "sticky" in exactly the same way as GPL, namely, it
doesn't effect code linked to it, but I guess it does have a few other
lesser issues...).

currently, it does produce a DLL, and is currently being built with MSVC +
GNU make (shouldn't be too hard to make a VS project from it, although it
does use a few provided tools for autoheadering and keeping the opcode
listing up to date, which may be an issue with VS...).

as for the assembler, it was originally written to address more-or-less
these same sorts of issues (although it does not presently include a
micro-optimizer, it is assumed that the compiler/JIT produce "reasonably
efficient" code).

also maybe worth looking into is YASM, which I guess includes some similar
functionality (I have not fully investigated it though).

my assembler (BGBASM), NASM, and YASM all use fairly similar syntax,
although "here and there" it is possible that code could run into
differences.

well, hopefully all this is at least some help...


    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Lasse Reichstein Nielsen  
View profile  
 More options Oct 15, 5:39 pm
Newsgroups: comp.lang.asm.x86
From: Lasse Reichstein Nielsen <lrn.unr...@MUNGED.microcosmotalk.com>
Date: 15 Oct 2009 21:39:48 GMT
Local: Thurs, Oct 15 2009 5:39 pm
Subject: Re: In-memory x86 assembler

Shasank <shas...@MUNGED.microcosmotalk.com> writes:

[Generate machine code from byte code]

> Initially I was planning on writing this translation phase myself,
> since the instruction set of the byte-code language is fairly simple
> and straightforward.  But I wonder, is there an in-memory based x86
> assembler available for use that we can build and link into our
> product, which takes, as input, a buffer of ascii text representing a
> function written in x86 assembly, and returns the machine code in a
> separate memory buffer?

You don't need to create ASCII source text. You could create the
machine code directly using the same strategy as (other) JIT'ed
languages, see, e.g., the assembler_x86.cpp file used by Java HotSpot
compiler (available in OpenJDK), or a similar Open Source project
http://code.google.com/p/asmjit/ . They are both made to directly
generate code in a memory buffer.

/L
--
Lasse Reichstein Holst Nielsen
 DHTML Death Colors: <URL:http://www.infimum.dk/HTML/rasterTriangleDOM.html>
  'Faith without judgement merely degrades the spirit divine.'


    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
BGB / cr88192  
View profile  
 More options Oct 15, 11:29 pm
Newsgroups: comp.lang.asm.x86
From: "BGB / cr88192" <cr88...@MUNGED.microcosmotalk.com>
Date: 16 Oct 2009 03:29:03 GMT
Local: Thurs, Oct 15 2009 11:29 pm
Subject: Re: In-memory x86 assembler

"Lasse Reichstein Nielsen" <lrn.unr...@MUNGED.microcosmotalk.com> wrote in
message news:4ad796a4$0$5097$9a6e19ea@unlimited.newshosting.com...

it is not "necessary" to do so, but I can think of a few good reasons to do
so.

one of the more major ones being that ASCII based ASM is far more generic
than API calls, and is also far better at abstracting ones' compiler from
their assembler (thus improving project modularity).

namely:
the codegen can be naturally abstracted from the assembler, since as far as
it is concerned, it is producing text which goes in a buffer.

it is also much more convinient to produce textual ASM, since one can lump
together several opcodes per string, and use a printf-style interface,
rather than having to use an API call per opcode.

more so, some kinds of micro-optimizations, such as knowing when 8-bit jumps
are safe, ... can't be readily done in a single pass, and so multiple passes
may be needed for things like this (otherwise, all jumps need 32-bits).

in other cases, ASM macros may be helpful/convinient.

...

the one (possible) downside, is that there may be an overhead required in
parsing said ASM, but personally I don't know of any real "sane" app design
where this is likely to be a noticable performance bottleneck...

so, as I see it, textual ASM is generally a win.

it is much like producing object files prior to producing the EXE.
it may seem pointless to produce object files and then link them into an
EXE, but there are many subtle advantages to having this seemingly trivial
extra step in the mix.

...


    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
James Van Buskirk  
View profile  
 More options Oct 15, 11:31 pm
Newsgroups: comp.lang.asm.x86
From: "James Van Buskirk" <not_va...@comcast.net>
Date: 16 Oct 2009 03:31:57 GMT
Local: Thurs, Oct 15 2009 11:31 pm
Subject: Re: In-memory x86 assembler

"Shasank" <shas...@MUNGED.microcosmotalk.com> wrote in message

news:4ad776db$0$5642$9a6e19ea@unlimited.newshosting.com...

FASM has a DLL version.  Although it can generate both 32-bit and
64-bit code, the DLL itself is a 32-bit binary.

--
write(*,*) transfer((/17.392111325966148d0,6.5794487871554595D-85, &
6.0134700243160014d-154/),(/'x'/)); end


    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Rod Pemberton  
View profile  
 More options Oct 16, 6:26 am
Newsgroups: comp.lang.asm.x86
From: "Rod Pemberton" <do_not_h...@nohavenot.cmm>
Date: 16 Oct 2009 10:26:02 GMT
Local: Fri, Oct 16 2009 6:26 am
Subject: Re: In-memory x86 assembler

"Shasank" <shas...@MUNGED.microcosmotalk.com> wrote in message

news:4ad776db$0$5642$9a6e19ea@unlimited.newshosting.com...

> [...] is there an in-memory based x86
> assembler available for use that we can build and link into our
> product, which takes, as input, a buffer of ascii text representing a
> function written in x86 assembly, and returns the machine code in a
> separate memory buffer?

Yes...  No.  I thought I saw one recently.  But, this is all I could find.
These don't do exactly what you asked:

"Softx86 Intel 80x86 emulator"
http://softx86.sourceforge.net/

"libx86 - a hardware-independent library for executing real-mode x86 code"
http://www.codon.org.uk/~mjg59/libx86/

"x86 Instruction Set Java Library"
http://code.google.com/p/jx86/

Rod Pemberton


    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
End of messages
« Back to Discussions « Newer topic     Older topic »

Create a group - Google Groups - Google Home - Terms of Service - Privacy Policy
©2009 Google