68000 Stack and Queue:
68000 Stack and Queue – 68000 supports stack and queue data structures with the address register indirect position direct and predecrement addressing modes. A stack operates on the principle of Last In First Out (LIFO) and, queue operates on the principle of First In First Out (FIFO). When data is added to a stack or queue, it is “pushed” onto the structure and when it is removed it is “pulled” from the structure.
Stack:
System Stack : The 68000 has two stack pointers to point stack in user mode and supervisor mode. When 68000 Stack and Queue is operating in supervisor mode, the user stack cannot be referenced and vice-versa. The system stacks pointed by user stack pointer and supervisor stack pointer are filled from high memory to low memory i.e. stack is decremented when data is added (pushed) to the stack and incremented when it is removed (pulled) from the stack.
In addition to stack pointer (SP), all seven address registers A0-A6 can be used as stack pointers by using appropriate addressing modes. Subroutine calls, traps and interrupts automatically use the system stack pointer. Subroutine calls push the program counter onto the stack, while RTS pops program counter from the system stack. Traps and interrupts push both program counter and status register onto the stack, while RTE pops program counter and status register from the system stack.
User Stack : User stack can be implemented and manipulated by employing the address register indirect with post increment and pre decrement addressing. The user may implement stack which can be filled either from high memory to low memory or vice versa.
The important things to remember are,
- Using predecrement, the register is decremented before its contents are used as the pointer into the stack.
- Using postincrement, the register is incremented after its contents are used as the pointer into the stack.
Queues:
A queues is an ordered collection of items/elements from which items may be removed at one end (called the front of the queue) and items/elements may be inserted at the other end (called the rear of the queue).
Queues are used to store data in the order in which they will be used. User 68000 Stack and Queue are implemented and manipulated with the address register indirect with post increment or predecrement addressing modes. Using a pair of address register (any two registers from A0-A6) the user can implement queues. These two registers are used to store two pointers in queues, put pointer and get pointer. Usually link lists are used to implement queues. Each entry in the linked list contains the address to the next entry in the list, along with data for each element. An advantage of linked list is that elements in the list need not be stored in memory in a sequential order, since each element includes the pointer to the next element. Addition, deletion and insertion of elements is easier with linked lists.