1 ; Test program 2 2 ; 31V4 Assignment 2 3 ; Written by : D Budgen 4 ; On : 9 March 1989 5 ; 6 ; This program simulates the generation and use of 7 ; a stack frame, passing parameters on the stack and 8 ; creating local variables on the stack 9 ; 10 011002 param1=11002 11 011004 param2=11004 12 000020 errmsg=20 13 ; 14 .start 1000 15 ; 16 01000 005000 caller: clr r0 ;zero r0 for status return 17 01002 012746 mov #2,-(sp);parameter count 000002 18 01006 013746 mov @#param1,-(sp) 011002 19 01012 013746 mov @#param2,-(sp) ;push parameters 011004 20 01016 004767 jsr pc, proc1 ;call procedure 000024 21 01022 005700 tst r0 22 01024 001003 bne error1 ;error if non-zero return 23 01026 062706 add #6,sp ;clear stack 000006 24 01032 000207 normal: rts pc ;normal exit route 25 01034 012746 error1: mov #71,-(sp) ;push error code 000071 26 01040 004737 jsr pc, @#errmsg ;call exception handler 000020 27 01044 000207 errret: rts pc ;return after error 28 ; 29 ; proc1 - the actual sub-program 30 ; 31 01046 024646 proc1: cmp -(sp),-(sp) ;make space for two variables 32 01050 010605 mov sp,r5 ;use r5 as index register 33 01052 026627 check: cmp 10(sp),#2 ;check number of parameters 000010 000002 34 01060 001034 bne errorr ;skip if wrong 35 01062 016565 mov 6(r5),2(r5) ;copy param1 to local1 000006 000002 36 01070 016565 mov 4(r5),0(r5) ;and param2 to local2 000004 000000 37 01076 066565 add 0(r5),2(r5) ;add locals 000000 000002 38 01104 062765 add #16,2(r5) ;and add constant 000016 000002 39 01112 026504 test: cmp 2(r5),r4 ;check value 000002 40 01116 001005 bne nonz ;skip if not equal 41 01120 005000 clr r0 ;clear status return 42 01122 005065 clr 6(r5) 000006 43 01126 022626 cmp (sp)+,(sp)+ ;clear stack space 44 01130 000207 ok: rts pc ;return if ok 45 01132 012700 nonz: mov #1,r0 ;set an error code 000001 46 01136 016565 mov 2(r5),6(r5) 000002 000006 47 01144 062706 add #4,sp ;clear the stack 000004 48 01150 000207 rts pc ;and return 49 01152 012700 errorr: mov #2,r0 ;set an error status return 000002 50 01156 062706 add #4,sp ;and clear the stack 000004 51 01162 000207 rts pc 52 000001 .end symbol table CALLER 001000 CHECK 001052 ERRMSG= 000020 ERRORR 001152 ERROR1 001034 ERRRET 001044 NONZ 001132 NORMAL 001032 OK 001130 PARAM1= 011002 PARAM2= 011004 PROC1 001036 TEST 001112