Question

I'm planning on creating a virtual machine for a language I'm creating and I can't understand how converting my assembly into my own instruction set can make execution faster. If I make the VM understand my assembly, is that not exactly the same as making my VM understand my byte code? Obviously the byte code will have less characters than the assembly would that really make that big of a difference? For example, if I make my own byte code, then I have to show my virtual machine how to understand it, and if the virtual machine reads assembly directly then I still have to show it how to understand the assembly so how can one be faster than the other?

--EDIT--

So if I get my virtual machine to interpret the code below directly, it should be just as faster as the code below it?

add r1, r2, r3 ; Add the values of reg2 and reg3, store the result in reg1
print r1

Encoded byte code:

c5 7c 8c d8 c8 d7

The byte code and the assembly code above are just examples of what I think it will look like.

Was it helpful?

Solution

Parsing is notoriously difficult and slow.

If you use your assembler instructions as you have specified, you have to parse the instructions, parse the arguments, strip the comments. A lot of parsing code, string comparisons, converting arguments to register offsets or values, etc.

Executing the byte code is a simple switch statement, a simple integer comparison. Register arguments can be pre-defined as offsets into a register array. Much faster.

You can still think of it as assembler -- just compile your assembler into byte code. A byte code to assembler display tool would be useful also.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top