; Test program 2 ; 31V4 Assignment 2 ; Written by : D Budgen ; On : 9 March 1989 ; ; This program simulates the generation and use of ; a stack frame, passing parameters on the stack and ; creating local variables on the stack. ; param1=11002 param2=11004 errmsg=20 ; .start 1000 ; caller: clr r0 ;zero r0 for status return mov #2,-(sp);parameter count mov @#param1,-(sp) mov @#param2,-(sp) ;push parameters jsr pc, proc1 ;call procedure tst r0 bne error1 ;error if non-zero return add #6,sp ;clear stack normal: rts pc ;normal exit route error1: mov #71,-(sp) ;push error code jsr pc, @#errmsg ;call exception handler errret: rts pc ;return after error ; ; proc1 - the actual sub-program ; proc1: cmp -(sp),-(sp) ;make space for two variables mov sp,r5 ;use r5 as index register check: cmp 10(sp),#2 ;check no of params bne errorr ;skip if wrong mov 6(r5),2(r5) ;copy param1 to local1 mov 4(r5),0(r5) ;and param2 to local2 add 0(r5),2(r5) ;add locals add #16,2(r5) ;and add constant test: cmp 2(r5),r4 ;check value bne nonz ;skip if not equal clr r0 ;clear status return clr 6(r5) cmp (sp)+,(sp)+ ;clear stack space ok: rts pc ;return if ok nonz: mov #1,r0 ;set an error code mov 2(r5),6(r5) add #4,sp ;clear the stack rts pc ;and return errorr: mov #2,r0 ;set an error status return add #4,sp ;and clear the stack rts pc .end