tags:

views:

32

answers:

1

Implementing a custom VM and I've come to use registers (these will store pointers and will be NULL when empty). But, I've come to realize that I actually have no idea how to manage register-based memory. Like, what do I do if all my registers are used up and some code wants another? Preferably, without just creating a new one.
This is in C++.

+2  A: 

I don't think this is a problem of the machine, instead it is a problem of the programmer of the machine. What you can do(IMO) is just to provide the means to move the values of the registers into memory back and forth. Problem solved :)

AraK
Agreed, this is a problem of the compiler or assembly writer, not the VM. If the compiler is based on LLVM, there are handy passes you can include which do memory->register and register->memory translations (primarily for SSA), and the output register allocator is good.
Yann Ramin