Avatar of Brad Brett
Brad Brett
Flag for United States of America asked on

Creating EXE from Assembly Code

I want to create .EXE file from assembly code, I want a method or class to do that, for example:

push("MOV A, B")
push("CMP A, B")
push("CMP A, B")
CreateEXE("C:\");

Open in new window

C++CAssembly

Avatar of undefined
Last Comment
stefan73

8/22/2022 - Mon
Hugh McCurdy

I'm not confident that I fully understand your question but this might be an answer.

http://www.bloodshed.net/faq.html#16

16. How to use assembly with Dev-C++ ?

The assembler uses AT&T (not Intel). Here's an example of such a syntax :

// 2 global variables

int AdrIO ;
static char ValIO ;

void MyFunction(..........)
{
__asm("mov %dx,_AdrIO") ; // loading 16 bits register
__asm("mov %al,_ValIO") ; // loading 8 bits register

/*
Don't forget the underscore _ before each global variable names !
*/
__asm("mov %dx,%ax") ; // AX --> DX
}
Brad Brett

ASKER
I am creating a compiler, so basically, I will generate assembly code, I want to use this assembly code to create a software (.EXE file).
SOLUTION
Hugh McCurdy

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
GET A PERSONALIZED SOLUTION
Ask your own question & get feedback from real experts
Find out why thousands trust the EE community with their toughest problems.
SOLUTION
Hugh McCurdy

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
⚡ FREE TRIAL OFFER
Try out a week of full access for free.
Find out why thousands trust the EE community with their toughest problems.
SOLUTION
CinnamonSynonym

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
⚡ FREE TRIAL OFFER
Try out a week of full access for free.
Find out why thousands trust the EE community with their toughest problems.
Dave Baldwin

@Medo3337, you should really go look at the source code for actual compilers.  GCC collection is available here: http://gcc.gnu.org/   There are many others available as open source.
Experts Exchange is like having an extremely knowledgeable team sitting and waiting for your call. Couldn't do my job half as well as I do without it!
James Murphy
Brad Brett

ASKER
I need to know the basic idea, looking at the source code will not be a good idea to understand how it works.
SOLUTION
Dave Baldwin

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
⚡ FREE TRIAL OFFER
Try out a week of full access for free.
Find out why thousands trust the EE community with their toughest problems.
Brad Brett

ASKER
I am writing something like a programmer language, so I will need to parse then compile, so I need two methods, one method to set the assembly code and another to create the EXE file from the assembly code.
Hugh McCurdy

I didn't get e-mail that you posted, for some reason.

I still think that you should write the code to produce the assembly code and then use a pre-existing assembler to convert the assembly code to machine code and make the exe file.

The only good reason I can think of for not doing it that way is because this is an academic project and you are required to write all the code.  In that case, I would study the source code of open source assemblers and read any accompanying documentation you can find.
⚡ FREE TRIAL OFFER
Try out a week of full access for free.
Find out why thousands trust the EE community with their toughest problems.
F. Dominicus

I propose you take an assembler and learn how to use it. You then simply generate the proper code for this assembler and use it to generate an executable form this assembler.

Masm is one Assembler you can use.  Because there is a nice book about it I propose
you have a look at HLA Or the book The art of assembly langauge.
SOLUTION
ambience

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
⚡ FREE TRIAL OFFER
Try out a week of full access for free.
Find out why thousands trust the EE community with their toughest problems.
ASKER CERTIFIED SOLUTION
stefan73

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
⚡ FREE TRIAL OFFER
Try out a week of full access for free.
Find out why thousands trust the EE community with their toughest problems.