The Stack Protocol 01 ; Subroutine for carrying out the PUSH and POP functions. This 02 ; program works with a stack consisting of memory locations x3FFF (BASE) 03 ; through x3FFB (MAX). R6 is the stack pointer. R0 contains the data. 04 ; 05 PUSH ST R1,SaveR1 ; R1 is needed by PUSH routine 06 LD R1,FULL ; FULL contains -(x3FFB) 07 ADD R1,R1,R6 08 BRz Fail_exit ; SP=x3FFB (no room on the stack) 09 ; 0A ADD R6,R6,#-1 0B STR R0,R6,#0 ; R0 gets PUSHed onto the stack 0C BR Success_exit 0D ; 0E POP ST R1,SaveR1 ; R1 is needed by POP routine 0F LD R1,EMPTY ; EMPTY contains -(x4000) 10 ADD R1,R1,R6 11 BRz Fail_exit ; SP=x4000 (nothing on the stack) 12 ; 13 LDR R0,R6,#0 ; Top of stack gets POPped to R0 14 ADD R6,R6,#1 15 ; 16 Success_exit AND R5,R5,#0 ; Success code: R5=0 17 LD R1,SaveR1 18 RET 19 Fail_exit AND R5,R5,#0 1A ADD R5,R5,#1 ; Fail code: R5=1 1B LD R1,SaveR1 1C RET 1D FULL .FILL xC005 1E EMPTY .FILL xC000 1F SaveR1 .BLKW 1