Nardil stack
This commit is contained in:
parent
522f886eea
commit
68480249b4
3 changed files with 80 additions and 0 deletions
27
ass1/Rekurzija/rek_sum.asm
Normal file
27
ass1/Rekurzija/rek_sum.asm
Normal file
|
|
@ -0,0 +1,27 @@
|
|||
prog START 0
|
||||
JSUB sinit
|
||||
LDA #5
|
||||
JSUB sum
|
||||
|
||||
halt J halt
|
||||
|
||||
stkp WORD 0
|
||||
stk RESW 1000
|
||||
|
||||
sinit . nastavi stkp na zacetek sklada
|
||||
|
||||
|
||||
rsum COMP #2
|
||||
STL rsumL . Base case
|
||||
JLT rsumExit
|
||||
RMO A, B
|
||||
SUB #1 . recursive case
|
||||
JSUB rsum . rsum(n-1)
|
||||
ADDR B, A
|
||||
|
||||
rsumExit LDL rsumL
|
||||
RSUB
|
||||
|
||||
rsumL WORD 0
|
||||
|
||||
END prog
|
||||
37
ass1/Rekurzija/stack.asm
Normal file
37
ass1/Rekurzija/stack.asm
Normal file
|
|
@ -0,0 +1,37 @@
|
|||
prog START 0
|
||||
JSUB sinit
|
||||
LDX #5
|
||||
STX @stkp
|
||||
JSUB spush
|
||||
JSUB spop
|
||||
CLEAR X
|
||||
LDX @stkp
|
||||
halt J halt
|
||||
|
||||
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
|
||||
16
ass1/Rekurzija/sum.asm
Normal file
16
ass1/Rekurzija/sum.asm
Normal file
|
|
@ -0,0 +1,16 @@
|
|||
prog START 0
|
||||
|
||||
LDA #5
|
||||
JSUB sum
|
||||
halt J halt
|
||||
|
||||
|
||||
sum CLEAR B
|
||||
sumLoop ADDR A, B
|
||||
SUB #1
|
||||
COMP #0
|
||||
JGT sumLoop
|
||||
RMO B, A
|
||||
RSUB
|
||||
|
||||
END prog
|
||||
Loading…
Add table
Add a link
Reference in a new issue