Stack Operations

R

Stack Operations

Although the PicoBlaze microcontroller has a CALL/RETURN stack, it does not have a dedicated data stack. In some controller architectures, register values are preserved during subroutine calls or interrupts by pushing them or popping them onto a data stack. The equivalent operation is possible in the PicoBlaze microcontroller by reserving some locations in scratchpad RAM.

In the example shown in Figure 5-4, the my_subroutine function uses register s0. The value of register s0 is preserved onto a “stack”, which is emulated using scratchpad RAM. When the my_subroutine function completes, the preserved value of register s0 is restored from the stack.

NAMEREG sF, stack_ptr ; reserve register sF for the stack pointer

;Initialize stack pointer to location 32 in the scratchpad RAM LOAD sF, 20

my_subroutine:

;preserve register s0 CALL push_s0

;*** remainder of subroutine algorithm ***

;restore register s0

CALL pop_s0

RETURN

push_s0:

STORE s0, stack_ptr ; preserve register s0 onto “stack”

ADD stack_ptr, 01 ; increment stack pointer

RETURN

pop_s0:

SUB stack_ptr, 01 ; decrement stack pointer

FETCH s0, stack_ptr ; restore register s0 from “stack”

RETURN

Figure 5-4:Use Scratchpad RAM to Emulate PUSH and POP Stack Operations

FIFO Operations

In a similar vein, FIFOs can be created using two separate pointers into scratchpad RAM. One pointer tracks data being written into RAM; the other tracks data being read from RAM.

See also:

“STORE sX, Operand — Write Register sX Value to Scratchpad RAM Location,” page 112.

“FETCH sX, Operand — Read Scratchpad RAM Location to Register sX,” page 98.

PicoBlaze 8-bit Embedded Microcontroller

www.xilinx.com

47

UG129 (v1.1.2) June 24, 2008

Page 47
Image 47
Xilinx UG129 manual Stack Operations, Fifo Operations