Dokončal fakulteto in naredil stack (na vajah) tako, da ga uporabljajo lahko tudi drugi programi

This commit is contained in:
Timon 2025-11-09 11:25:11 +01:00
parent 68480249b4
commit f8922139b8
2 changed files with 82 additions and 0 deletions

28
ass1/Rekurzija/cstack.asm Normal file
View file

@ -0,0 +1,28 @@
cstk EXTDEF sinit, spush, spop, stkp
sinit STA stkA
LDA #stk
STA stkp
LDA stkA
RSUB
spush . stkp++
STA stkA
LDA stkp
ADD #3
STA stkp
LDA stkA
RSUB
spop . stkp--
STA stkA
LDA stkp
SUB #3
STA stkp
LDA stkA
RSUB
stkp WORD 0
stk RESW 1000
stkA WORD 0
END cstk

54
ass1/Rekurzija/fak.asm Normal file
View file

@ -0,0 +1,54 @@
prog START 0
+JSUB sinit
LDA #5
JSUB fa
WD #1
halt J halt
fa STL @stkp
JSUB spush
STB @stkp
JSUB spush
. Base case
COMP #2
JLT faExit
RMO A, B
SUB #1
JSUB fa
MULR B, A
faExit JSUB spop
LDB @stkp
JSUB spop
LDL @stkp
RSUB
stkp WORD 0
stk RESW 1000
stkA WORD 0 . Zacasni prostor za shranjevanje registra A
sinit STA stkA
LDA #stk
STA stkp
LDA stkA
RSUB
spush . stkp++
STA stkA
LDA stkp
ADD #3
STA stkp
LDA stkA
RSUB
spop . stkp--
STA stkA
LDA stkp
SUB #3
STA stkp
LDA stkA
RSUB
END prog