0

I'm making a virtual machine in C and I was told that by converting the "assembly" code into hexadecimal or binary, I could speed up the execution. My question is, if I have a string and I encode it to numbers, how can it be faster than not encoding it when it adds and extra step to the execution in the VM?

--EDIT-- An example of the VM assembly is:

push 10 # Push the value 10 to the top of the stack
print # Print the value at the top of the stack

The encoded instructions look like this:

010a 0c

But the part I don't get is how encoding the assembly into instructions can be faster than not doing it because you have to decode them again. Please let me know if I'm wrong though.

Seki
  • 11,135
  • 7
  • 46
  • 70
user3318845
  • 301
  • 4
  • 15

1 Answers1

2

Yes, encoding is better in the case on the re-use of the code.

Keep in mind that a function or piece of code is called many times, and so you loose little times for the first conversion and after you gain a lot of time when you start interpret the same code.

alk
  • 69,737
  • 10
  • 105
  • 255
SRedouane
  • 498
  • 5
  • 10