I am creating a bytecode language for my Virtual Machine to interpret and am wondering how should it be structured. I have looked into stuff and have found it is generally structured how assembly is structured. I have also read in this tutorial(Currently incomplete :( ), which I have based my C++ code off of. It involves organizing the byte-code into different parts. The first nibble identifies the the command id and so on...
However I am still very confused on what I should do. In the tutorial they use a int array to hold the hex but if you are going to be launching from a binary file you need to read it into a char array. I believe they can store hex too but am having trouble reading.
Defining a size and structure for a bytecode language(to be manipulated in C++)
Started by liamzebedee, May 25 2011 10:39 PM
1 reply to this topic
#1
Posted 25 May 2011 - 10:39 PM
|
|
|
#2
Posted 26 May 2011 - 09:08 AM
"Hex" is just a nickname for binary data. (EDIT: To be clear, "Hex" is binary data represented in base 16.) All data types store binary data, the only difference being in how they are interpreted. You can certainly use a char array to store an array of bytes, but the fact that it is a char array only means the C++ compiler will treat them as characters, thus allowing you to perform operations on them as if they were characters. In C++, characters can be treated as integers as well, that is, you can perform arithmetic on them as if they were integers. So if that fits your requirements, you may certainly use that particular data type.
Keep in mind, a char is only 8 bits, so you may want to consider using a bigger data type if your opcodes are going to be longer than that. For instance, if your opcodes are 32 bits long, an int would be a wise choice since int's are 32 bits on most platforms, so you'd only need a single variable to store your opcode, rather than 4 chars.
Keep in mind, a char is only 8 bits, so you may want to consider using a bigger data type if your opcodes are going to be longer than that. For instance, if your opcodes are 32 bits long, an int would be a wise choice since int's are 32 bits on most platforms, so you'd only need a single variable to store your opcode, rather than 4 chars.
Hofstadter's Law: It always takes longer than you expect, even when you take into account Hofstadter's Law.
– Douglas Hofstadter, Gödel, Escher, Bach: An Eternal Golden Braid
1 user(s) are reading this topic
0 members, 1 guests, 0 anonymous users


Sign In
Create Account


Back to top









