Pointers - are like integers in the way that they contain addresses, and can be used anywhere where an integer can(LIR has only one type).
What is different is that you cannot create a pointer(that is get a memory address, unless you are extremely lucky!) by yourself.
Thats where alloc instruction comes in.
Alloc - The wiki will give you the more technical information. Alloc is basically like calloc() in C - it allocates a specified amount of space for your usage later, and returns a pointer to it. Hence the instruction format is:
p = alloc sizeIllustration
I will illustrate this with an example straight from jorendorff's desk -
addr = alloc 4;That stores the value 0 at the memory address specified by addr pointer. Now you can load that value into a variable, store another value, etc.
zero = int 0;
st addr = zero ... (that's roughly how it's intended to be used)
Going one step further, if you allocate 8 bytes of memory
addr = alloc 8;Note the offset 4 in the second store. The offset is the number of bytes to be offset from the base, as expected.Now, you can load the two bytes in separate variables, or mess up stuff by specifying an offset not divisible by 4!
zero = int 0;
one = int 1;
st addr = zero;
st addr = one;
Having implemented basic loads and stores today, and consolidated my code which looks much more readable now, I am hoping to get information on:
1. Jumps and labels and how to handle those(Are labels solely the responsibility of the parser?).
2. Subroutine calls.
I will go about them in the above order.