prog START 0
    +JSUB stackinit    
        
    LDA #5
    +STA @stackptr 
    JSUB stackpush
    
    LDA #6
    +STA @stackptr
    JSUB stackpush

    JSUB stackpop
    +LDA @stackptr

    JSUB stackpop
    +LDA @stackptr

HALT J HALT
    END prog
        
stackinit   STA oldvalue
            CLEAR A
            LDA #stack
            STA stackptr
            CLEAR A
            LDA oldvalue
            RSUB

stackpush   STA oldvalue
            CLEAR A
            LDA stackptr
            ADD #3
            STA stackptr
            CLEAR A
            LDA oldvalue
            RSUB

stackpop    STA oldvalue
            CLEAR A
            LDA stackptr
            SUB #3
            STA stackptr
            CLEAR A
            LDA oldvalue
            RSUB


oldvalue WORD 0 
stackptr WORD 0 
stack RESW 1000
