# You may have to edit this file to delete header lines produced by # mailers or news systems from this file (all lines before these shell # comments you are currently reading). # Shell archive made by dwjones on Thu Mar 28 03:43:23 PM CDT 2024 # To install this software on a UNIX system: # 1) create a directory (e.g. with the shell command mkdir stuff) # 2) change to that directory (e.g. with the command cd stuff), # 3) direct the remainder of this text to sh (e.g. sh < ../savedmail). # This will make sh create files in the new directory; it will do # nothing else (if you're paranoid, you should scan the following text # to verify this before you follow these directions). Then read README # in the new directory for additional instructions. cat > README <<\xxxxxxxxxx README FOR DEMO STACK ABSTRACTION this project will demonstrate a stack to show how big programs can be managed TO BUILD THE PROJECT run make stackdemo see the makefile for the relationship between the project components xxxxxxxxxx cat > Makefile <<\xxxxxxxxxx # Makefile for the project demonstrating a stack # Make uses sh, not bash, so we need to install the hawk and hawklink commands; # these definitions are lifted from the aliases in .bashrc # (If you try to use this makefile on a different system, you will need # to change the file names to where hawk and hawklink are installed there.) smal=~dwjones/bin/smal32 -P 45 -U ~dwjones/lib/hawk hawklink=~dwjones/bin/hawklink hawk=~dwjones/bin/hawk ########## # primary make target stackdemo.o: main.o stack.o $(hawklink) -o stackdemo main.o stack.o ########## # other make targets main.o: main.a stack.h $(smal) main.a stack.o: stack.a stack.h $(smal) stack.a ########## # Make utilities # demonsrate the program demo: stackdemo.o $(hawk) stackdemo.o # remove object and listing files clean: rm -f *.o *.l # create a shell archive of the project stackdemo.shar README Makefile main.a stack.a stack.h: shar README Makefile main.a stack.a stack.h > stackdemo.shar xxxxxxxxxx cat > main.a <<\xxxxxxxxxx TITLE "main.a -- main program to demo stacks" USE "hawk.h" USE "stdio.h" USE "stack.h" INT MAIN S MAIN ; AR for main program ;RETAD = 0 ARSIZE = 4 MAIN: STORES R1,R2 ADDSI R2,ARSIZE LEA R3,TEXTB ; -- parameter LIL R1,PUSH JSRS R1,R1 ; push( textb ) LEA R3,TEXTA ; -- parameter LIL R1,PUSH JSRS R1,R1 ; push( texta ) LIL R1,POP JSRS R1,R1 ; -- parameter pop() LIL R1,PUTSTR JSRS R1,R1 ; putstr( pop() ) -- texta = hello LIL R1,POP JSRS R1,R1 ; -- parameter pop() LIL R1,PUTSTR JSRS R1,R1 ; putstr( pop() ) -- textb = world ADDSI R2,-ARSIZE LOADS PC,R2 TEXTA: ASCII "hello ",0 TEXTB: ASCII "world",0 END xxxxxxxxxx cat > stack.a <<\xxxxxxxxxx TITLE "stack.a -- placeholder for missing code" USE "hawk.h" STACKSIZE= 10 ; stack size in words COMMON MYSTACK,STACKSIZE<<2 COMMON MYSP,4 ; address of free word above stack top LCSAVE = . . = MYSP ; -- initialization at assembly time W MYSTACK ; mysp = ^mystack . = LCSAVE ;========== INT PUSH ; push a word on the stack ; given R3 -- word to push ; returns nothing ; wipes out R3-R7 PUSH: STORES R1,R2 LIL R4,MYSP ; -- address of mysp LOADS R5,R4 ; -- value of mysp STORES R3,R5 ; *mysp = word to push ADDSI R5,4 ; mysp ++ STORES R5,R4 ; -- put mysp back LOADS PC,R2 ; return ;========== INT POP ; pop a word from the stack ; given nothing ; returns R3 -- a word popped from the stack ; wipes out R4-R7 POP: STORES R1,R2 LIL R4,MYSP ; -- address of mysp LOADS R5,R4 ; -- value of mysp ADDSI R5,-4 ; mysp -- LOADS R3,R5 ; return value = *mysp STORES R5,R4 ; -- put mysp back LOADS PC,R2 END xxxxxxxxxx cat > stack.h <<\xxxxxxxxxx ; stack.h ; definitions used by all users of the one and only stack EXT PUSH ; push a word on the stack ; given R3 -- word to push ; returns nothing ; wipes out R3-R7 EXT POP ; pop a word from the stack ; given nothing ; returns R3 -- a word popped from the stack ; wipes out R4-R7 xxxxxxxxxx