I'm creating a virtual machine and I'm encoding the instructions into byte code. The instructions are hexadecimal numbers like this: 0x1064
, this instruction means load the value of 100 (hexadecimal 64) into register 0 and the number of the load instruction is 1. My question is, if I wanted to load a larger number I would change the 64
to a larger number 3E8
for example (1000 in hexadecimal) the instruction would be 5 characters long, is it possible to keep the instructions the same length some how?
Asked
Active
Viewed 146 times
0

Seki
- 11,135
- 7
- 46
- 70

user3318845
- 301
- 4
- 15
-
1Either make your instructions long enough to hold the whole 32-bit or 64-bit operand, or provide instructions for loading the upper and lower half (or individual bytes) separately. Or have an instruction to "shift left by 8 bits and shift 8 more bits (immediate value) in". – mihi Mar 10 '14 at 19:46
1 Answers
1
It is certainly possible to keep the instructions the same length. In fact, it is possible to having a turing complete language using only one instruction! The question is what you want to do.
For simplicity of decoding, you may just decide to have all the instructions be the same length. It increases the size of the code, but either way it doesn't really matter. Just do whatever you think is the best.

Antimony
- 37,781
- 10
- 100
- 107