completed stack and fac.asm
This commit is contained in:
parent
d7ab158796
commit
8c8a68cb89
2 changed files with 99 additions and 0 deletions
66
ass1/fac.asm
Normal file
66
ass1/fac.asm
Normal file
|
|
@ -0,0 +1,66 @@
|
||||||
|
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
|
||||||
33
ass1/stack.asm
Normal file
33
ass1/stack.asm
Normal file
|
|
@ -0,0 +1,33 @@
|
||||||
|
prog START 0
|
||||||
|
JSUB sinit
|
||||||
|
LDT #4
|
||||||
|
STT @stkp
|
||||||
|
JSUB spush
|
||||||
|
JSUB spop
|
||||||
|
CLEAR T
|
||||||
|
LDT @stkp
|
||||||
|
|
||||||
|
halt J halt
|
||||||
|
|
||||||
|
.rutine za sklad
|
||||||
|
sinit LDA #stkRESW .inicializiraj stkp
|
||||||
|
STA stkp
|
||||||
|
RSUB
|
||||||
|
|
||||||
|
spush LDA stkp .poveca stkp za 3
|
||||||
|
ADD #3
|
||||||
|
STA stkp
|
||||||
|
RSUB
|
||||||
|
|
||||||
|
spop LDA stkp .zmanjsa stkp za 3
|
||||||
|
SUB #3
|
||||||
|
STA stkp
|
||||||
|
RSUB
|
||||||
|
|
||||||
|
.podatki za sklad
|
||||||
|
stkp WORD 0
|
||||||
|
stkRESW WORD 1000
|
||||||
|
|
||||||
|
END prog
|
||||||
|
|
||||||
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue