0 item/s in cart
A stack is a section of memory serving for temporaty storage of data (e.g. while calculating complex expressions). Its most important task is keeping the states of significant registers during jumps to subprograms, interrupts, traps, etc. During a jump to a subprogram in this part of the memory are kept the parameter values (if any) at the t ime of calling a function or a procedure, value of the PC register (the place reached during the execution of a program), and the frame register W14. The values of the PC and W14 registers are copied to the stack automatically, increasing the value of the W15 register by 6 (three times by 2). The compiler takes care to copy the parameters to the stack by adding a part of the code required for copying the parameters to the top-of-stack on each user call of a function or a procedure.A stack is a section of memory which is usually accessed sequentially. The access is possible, of course, to any memory location, even to the locations constituting the stack, but such concept is very seldom used. An increase or a decrease of the stack, however, can be done only by a sequential access. When a datum is copied to the stack, it is pushed to the top-of-stack. Only the value from the top-of-stack can be read by the W15 register. Thus a stack is a LIFO (Last In First Out) buffer. In order to know at each moment which address is read or which address is written, one of the registers is reserved as the stack pointer register. This is the W15 register. Therefore, when a datum is copied to the stack, it is written to the location pointed by the W15 register and then the W15 register is increased by 2 to point at the next free location. When a datum is read from the stack, the value of the W15 register is at first decreased by 2 and then the value from the top-of-stack is read. How does this work in practice? The following example gives a program consisting of the main program and one procedure.
program MemoryTest; var m:word; procedure MyProc1(a:Word); var i:word; begin i := a+2; end; begin TRISB :=0; m := 3; nop; MyProc1(m); m := 2; end.The main program begins by executing the instruction TRISB :=0;. After that, variable m is allocated the value 3. Then, the procedure is called. What happens at that moment? The compiler has generated a code for copying to the stack the variable m (Fig. 8-4a) and then jumps to the memory address where the subprogram is located.
program MemoryTest2; var m,n:word; function MyFunc1(a,b:word):Word; var i, j:word; begin i :=a+2; j :=b-1; result:=i+j; end; begin TRISD :=0; m := 3; n := 5; nop; m :=MyFunc1(m, n); LATD := 2; end.The program starts by executing the instruction TRISD :=0;. After that, it allocates the value 3 to the variable m. Then, it calls the function. What happens at this moment? The compiler has generated a code which push to the stack the variables m and n, Fig. 8-5a, and then jumps to the address in the memory corresponding to the subprogram (function).
XMODEN - X space modulo addressing enable bit YMODEN - Y space modulo addressing enable bit BWM<3:0> - Register select for bit-reversed addressing bits YWM<3:0> - Y space register select for modulo addressing bits XWM<3:0> - X space register select for modulo addressing bits
XS<15:1> - X space modulo addressing start address bits
XE<15:1> - X space modulo addressing end address bits
YS<15:1> - Y space modulo addressing start address bits
YE<15:1> - Y space modulo addressing end address bits
BREN - Bit-reversed addressing enable bit XB<14:1> - Bit-reversed modifier bits