SPO_JakaFurlan/ass1/fact.asm
2025-11-08 17:05:13 +01:00

66 lines
No EOL
703 B
NASM

prog START 0
JSUB sinit
LDA #5
JSUB fact
halt J halt
.fakulteta
fact COMP #1
JGT rec
LDA #1 .base case
RSUB
rec STL @stkp
JSUB spush
STA @stkp
JSUB spush
STB @stkp
JSUB spush
RMO A, B .shrani n v B
SUB #1 .n-1
JSUB fact .fact(n-1)
MULR B, A .n * fact(n-1)
JSUB spop
LDB @stkp
JSUB spop
.LDA @stkp da ne povozimo odgovora?
JSUB spop
LDL @stkp
RSUB
.rutine za sklad
sinit STA stkA
LDA #stkRESW .inicializiraj stkp
STA stkp
LDA stkA
RSUB
spush STA stkA
LDA stkp .poveca stkp za 3
ADD #3
STA stkp
LDA stkA
RSUB
spop STA stkA
LDA stkp .zmanjsa stkp za 3
SUB #3
STA stkp
LDA stkA
RSUB
.podatki za sklad
stkp WORD 0
stkA WORD 0
stkRESW RESW 1000
END prog