How should I generate bytecode to reference variables X and Y? Then to
assign the values of 3 and 2 to each variable respectively?

And finally, when the print/printf statement is executed, there is a string
involved that has to come from some place. Someone has mentioned in the past
to encode it as part of the opcode stream and another option is to use a
symbol table and reference it from there.

Could someone help me put together a quick opcode stream that would use
variables and strings like the above to help me grasp how I should generate
opcode sequences for a virtual machine?

[ shortly later he added: -John]

Assuming we're dealing with a language simliar to BASIC with the following
program, I have come up with the following BYTECODE stream:

Now, in the above, I took a few things for granted that has to be done
before the virtual machine can ever begin executing any of these
statements. Something has to tell the virtual machine to advance the
stack pointer by the number of local variable storage slots that are
needed. This again could just be a simple opcode like:

Another option would be to assume a maximum number of slots for local
vars like the java virtual machine does of 255. Is there any PROs to
this? I would see this as being wasteful, especially for the case
where only a handful of variables are being used like the above
example. More memory would have to be allocated for the unused stack
slots that necessary. It could be the job of the compiler to look at
the symbol table for each code block and determine the number of slots
needed for that frame. Then, just use either:

This all makes sense to me so far. :-) Now so far I've assumed working
with numbers and these numbers are encoded in the opcode bytestream as
operands to the opcodes that use them.

Now, time for my questions ~~ I just wanted to illustrate my
understanding thus far in case there is some misunderstanding so that
someone can clarify for me.

Lets now assume we have the following source code:

Dim s as String = "Test"

I have several options on how I could implement this. I could use a
special opcode that says, the following byte stream represents a
string of ASCII characters which is terminated by the first NULL byte
found. Take this stream, allocate a memory pointer for it and put the
stream in the memory location. Then store the pointer on the stack.

OPCODE 54 65 73 74 00

Or, I could simply this to permit NULL bytes in the stream by using something
like:

OPCODE [2 byte length] 54 65 73 74

Or another alternative approach would be a special opcode that tells the VM to
go to a special block of storage in the BYTECODE file known as the DATA BLOCK
and extract X number of bytes and store these in memory and also push the
memory pointer on the stack.