I'm trying to implement in C an integer java virtual machine taking as example the IJVM described by Andrew Tanenbaum in "Structured Computer Organization" -> IVJM . Until now I was able to execute some instruction such as GOTO, IFEQ, IADD, etc. by adjusting the right value of the program counter or/and pushing/popping values or constants (from pool area) onto stack, I've created the stack as a global array. My intentions is to call some methods and pass the parameters to it (onto stack), but I have a blocking point regarding how to implement local variable frame for each function. I know that the method area first contains two shorts (2 byte numbers), the first one signifying the number of arguments the method expects, and the second one being the local variable area size. The local variable area size helps me a lot, but:
- -> the local variable should be located also in the array used for stack (operands)?
- -> the main function doesn't have a local variable area size, how to prevent overlapping with values pushed into stack?
- -> what is the best approach to implement the local variable frame?