Retro video games delivered to your door every month!
Click above to get retro games delivered to your door ever month!
X-Hacker.org- TMS320C2x DSP - provisions have been made on the tms320c2x for extending the http://www.X-Hacker.org [<<Previous Entry] [^^Up^^] [Next Entry>>] [Menu] [About The Guide]
      Provisions have been made on the TMS320C2x for extending the
      hardware stack into data memory. This is useful for deep subroutine
      nesting or stack overflow protection.

      The hardware stack is accessible via the accumulator using the PUSH
      and POP instructions. Two additional instructions, PSHD and POPD,
      are included in the instruction set so that the stack may be
      directly stored and recovered from data memory.

      A software stack can be implemented by using the POPD instruction
      at the beginning of each subroutine in order to save the PC in data
      memory. Then before returning, a PSHD is used to put the proper
      value back onto the top of the stack.

      When the stack has three (TMS32020) or seven (TMS320C25) values
      stored on it and two or more values are to be put on the stack
      before any other values are popped off, a subroutine that expands
      the stack is needed, such as follows:

*  THIS ROUTINE EXPANDS THE STACK WHILE LETTING THE MAIN
*  PROGRAM DETERMINE WHERE TO STORE THE STACK CONTENTS OR FROM
*  WHERE TO RECOVER THEM.
STACK       LARP  2     ; USE AR2.
            BNZ   PO    ; IF POPD IS NEEDED, GOTO PO.
            POP         ; ELSE, SAVE PROGRAM COUNTER
            RPTK  6     ; LOAD REPEAT COUNTER.
            PSHD  *+    ; PUT MEMORY IN STACK.
            BACC        ; RETURN TO MAIN PROGRAM.
PO          POP         ; SAVE PROGRAM COUNTER.
            MAR   *-    ; ALIGN STACK POINTER.
            RPTK  6     ; LOAD REPEAT COUNTER.
            POPD  *-    ; PUT STACK IN MEMORY.
            MAR   *+    ; REALIGN STACK POINTER.
            BACC        ; RETURN TO MAIN PROGRAM.

      In this example, the main program stores the stack starting location
      in memory in AR2 and indicates to the subroutine whether to push
      data from memory onto the stack or pop data from the stack to
      memory. If a zero is loaded in the accumulator before calling the
      subroutine, the subroutine pushes data from memory to the stack. If
      a one is loaded into the accumulator, the subroutine pops data from
      the stack to memory.

      Since the CALL instruction uses the stack to save the program
      counter, the subroutine pops this value into the accumulator and
      utilizes the BACC (branch to address specified by accumulator)
      instruction to return to the main program. This prevents the program
      counter from being stored into a memory location. The above
      subroutine uses the BANZ (branch on auxiliary register not zero)
      instruction to control all of its loops.

See Also: subroutines hardware stack

Online resources provided by: http://www.X-Hacker.org --- NG 2 HTML conversion by Dave Pearson