|
(Continued from previous)
allows the compiler to generate the string "CC" as the source or destination operand of an instruction.
Memory offsets assigned to variables declared in the source program must begin after the memory that has been reserved in the data section. If the compiler will be declaring three variables in the data section then the first available offset that can be assigned to a source program variable is 3 (since 0, 1, and 2 are already taken by the variables in the data section). There is no way to increase the amount of memory allocated to the data section at runtime.
Memory required at runtime must be allocated on the stack with the alloc instruction. The alloc instruction doesn't actually allocate memory (and free doesn't actually release any memory) it simply increases the stack frame pointer in the interpreter. If a subroutine is called then the interpreter knows not to overwrite those memory locations with the next stack frame. Memory in the stack frame may still be accessed even if no alloc has been generated, but these memory locations will be overwritten is a subroutine is called.
Variables declared in the source program will typically be assigned offsets into the current stack frame. The easiest way to do this is to maintain a counter which is set to zero every time the parser moves into a procedure or function definition. Then, after the subroutine has been parsed the generated code can be wrapped with PROCBEGIN, and alloc (the prologue) and free and PROCEND (the epilogue).
Addressing Modes
Most CPUs support several addressing modes to simplify memory access. Unfortunately (or fortunately, depending on your point of view) most of those are unavailable in TVI. TVI supports two basic addressing modes that allow us to address either an absolute memory location or an offset into the current stack frame:
%5 ; offset 5 bytes into the current ; stack frame _3 ; an absolute memory address
There are also two additional modifiers that can be used with these addressing modes to allow pointer operations. They are:
@%5 ; gets the absolute address of the
(Continued on next page)
|
|