I
I
Insolent Muzzle2020-06-10 12:09:54
Programming languages
Insolent Muzzle, 2020-06-10 12:09:54

How to translate the code into an exe file for a language VM?

Recently, many of my projects have gone down the drain. And now I decided to write my own AP. And right away I ran into a problem. How do I translate the assembler code for my VM into an executable file (exe) and how do I make this exe work with my VM?
There is a code (VM Register if anything)

set a, 3
set b, 7
set c, 5
sum a, b, c to a

In this code, variables a, b, and c are set to 3, 7, and 5, after which the sum command sums all three variables and places them in a. And this code should be translated into exe's (preferably with the help of JS, because the translator will be on JS). After the launch, the exe'shnik should give the appropriate commands to the language VM, and it will execute them.
How to translate this code into an exe using JS, and work with this exe in a VM using C ++?
Ps I know that it's a strange choice of languages, it's just easy to make a translator in JS, and it will be easy to make a VM in C ++.

Answer the question

In order to leave comments, you need to log in

2 answer(s)
S
Saboteur, 2020-06-10
@pluffie

exe is a container for the operating system.
It is not clear what kind of VM you have - each operating system must support some kind of format for executable files and run it, that is,
1. create a new process
2. Load executable code from a file into memory, possibly part of the code, possibly code and some data
3. Transfer control to the entry point
How and what to load - specified in the executable file (exe, elf), or the files are made template (.com).
You are now confusing the functionality of the compiler and the linker.

P
PeeX, 2020-06-10
@PeeX

If all this is easy to do, then what is the question?
In my opinion "easy" means that I know what to do, how to do it and how much to do it.
Well, of course, and you swung the translator. Maybe to start with a simple stack machine?
Well, with your input data, the answer to the question "how to do" does not imply something short

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question