Search code examples
stringvirtual-machinebytecodeembedding

How are strings embedded in binary files?


I'm writing my own bytecode and virtual machine (on .NET) and one thing i can't figure out is how to embed strings into my bytecode. Any ideas now how i should do it?


Solution

  • Apparently you're defining your very own byte code. this has nothing to do with the syntax/grammar of .NET CIL, right ?

    If so, and if you concern is how to encode strings (as opposed to other instructions such as jumps, loops, etc.), you can just invent your own "instruction" for it.

    For example, hex code "01xx" could be for a string containing xx bytes (0 -255). Your language interpreter would then be taught to store this string on the stack (or whereever) and move to decode the following byte code located xx bytes further down the bytecode stream.

    If you concern is how to mix character data and numeric data in whatever storage you have for the bytecode, please provide specifics and maybe someone can help...