82 lines
No EOL
1.8 KiB
NASM
82 lines
No EOL
1.8 KiB
NASM
rek START 0
|
|
JSUB sinit
|
|
LDT #10
|
|
|
|
|
|
loop JSUB read . Pretvorimo iz ASCII v stevilko
|
|
COMP #1 . Če je (A) <= 1 končamo, ker 0!=1!=1
|
|
JLT halt
|
|
JSUB fa . Sicer izračunamo (A)!
|
|
+STCH @screen
|
|
LDA screen
|
|
ADD #1
|
|
STA screen
|
|
CLEAR B
|
|
CLEAR A
|
|
J loop . Gremo prebrat naslednji vhod
|
|
|
|
halt J halt
|
|
|
|
read RD #0xFA . V A se shrani naslednji prebrani znak
|
|
COMP #0xA
|
|
JEQ rExit . Če preberemo newline gremo na izhod
|
|
SUB #48 . Sicer iz ascii kode dobimo stevko
|
|
LDB tmp
|
|
MULR T, B . tmp *= 10
|
|
ADDR A, B . tmp += A
|
|
STB tmp
|
|
J read
|
|
|
|
rExit LDA tmp . Shranimo prebrano stevilko v A
|
|
LDB #0
|
|
STB tmp . Ponastavimo tmp
|
|
RSUB
|
|
|
|
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
|
|
|
|
|
|
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
|
|
|
|
screen WORD 0xb800
|
|
stkp WORD 0
|
|
stk RESW 1000
|
|
stkA WORD 0
|
|
tmp WORD 0
|
|
END rek |