Take the 2-minute tour ×
Programmers Stack Exchange is a question and answer site for professional programmers interested in conceptual questions about software development. It's 100% free, no registration required.

I'm trying to do the following: take a single IA32 instruction in the Intel syntax (such as ADD EAX, EBX) and produce the corresponding machine code for this instruction. Is there some small library, preferably open source, that can do this for me?

share|improve this question
    
You could probably extract that part from, say, NASM, and turn it into a library -- but I don't know of one that's already built to do exactly that (and it's not clear how it would work in some cases, such as jmp instructions, which normally need a series of instructions so the assembler can compute the offset to the target). –  Jerry Coffin Apr 5 '12 at 8:14
    
Jerry, for JMPs I'd like to be able to specify the target address and the resulting object code should imply include the address verbatim. –  Frederick Apr 5 '12 at 9:15
    
Do you want to write a small assembler, or do you need to have an assembler in your program? –  user1249 Apr 5 '12 at 9:59
    
@Thorbjørn I need the assembler inside my program. –  Frederick Apr 5 '12 at 11:22
add comment

1 Answer

up vote 1 down vote accepted

You can do it with FASM.
There is a sample GUI application distributed with FASM DLL
Or, you can use Python interpreter, with Python binding for FASM DLL

share|improve this answer
    
Exactly what I needed. Thanks :) –  Frederick Apr 5 '12 at 9:13
    
Is there a version for linux too, Abyx? –  Frederick Apr 5 '12 at 11:21
    
@Frederick, DLL? You can try Wine. –  Abyx Apr 5 '12 at 12:24
    
I guess I could use Wine if nothing else works. But I think I should try and hack NASM into a library first. Thanks anyway :) –  Frederick Apr 5 '12 at 17:13
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.