90 lines
No EOL
2.4 KiB
NASM
90 lines
No EOL
2.4 KiB
NASM
rdp START 0
|
|
JSUB binit
|
|
LDT #10 . Za mnozenje z 10
|
|
|
|
rloop JSUB read
|
|
COMP #0
|
|
JEQ halt
|
|
JSUB store
|
|
JSUB print
|
|
J rloop
|
|
|
|
print LDCH @bfp . Shranimo char iz pomnilniske lokacije na katero kaze bfp (torej iz bufferja)
|
|
+STCH @screen . Ta char zapisemo na zaslon
|
|
LDA screen
|
|
ADD #1 . Pomaknemo screen za eno naprej
|
|
STA screen
|
|
LDA bfp . Bfp znizamo za 1, da kaze na naslednji znak (printamo v obratnem vrstnem redu kakor smo zapisovali)
|
|
SUB #1 .
|
|
STA bfp .
|
|
COMP #buffer . Ce smo sli cez buffer, smo sprintali vse, gremo na exit
|
|
JLT print_exit .
|
|
J print . Ce nismo sli cez, potem imamo se za sprintat
|
|
|
|
|
|
print_exit LDA #buffer
|
|
STA bfp . Obnovimo bfp na začetek bufferja za naslednjo zanko
|
|
RSUB
|
|
|
|
|
|
store COMP #10
|
|
JLT s_single
|
|
STA tmp
|
|
|
|
. MOD
|
|
DIV #10
|
|
MUL #10
|
|
RMO A, X
|
|
LDA tmp
|
|
SUBR X, A
|
|
. MOD
|
|
ADD #48
|
|
+STCH @bfp . Na buffer shranimo char ki je ostanek deljenja
|
|
LDA bfp . A = bfp
|
|
ADD #1 . A += 1
|
|
STA bfp . bfp = bfp + 1, buffer pointer premaknemo naprej
|
|
LDA tmp . Obnovimo A
|
|
DIV #10 . A /= 10
|
|
J store
|
|
|
|
|
|
|
|
s_single
|
|
ADD #48
|
|
+STCH @bfp
|
|
LDA bfp
|
|
ADD #1
|
|
STA bfp
|
|
LDB #0
|
|
STB tmp
|
|
RSUB
|
|
|
|
|
|
halt J halt
|
|
|
|
binit LDA #buffer
|
|
STA bfp
|
|
CLEAR A
|
|
RSUB
|
|
|
|
read RD #0xFA . V A se shrani naslednji prebrani znak
|
|
COMP #0xA
|
|
JEQ rExit . Če preberemo newline gremo na izhod
|
|
SUB #0x30 . 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
|
|
|
|
END rdp
|
|
|
|
tmp WORD 0
|
|
bfp WORD 0 . Pointer na buffer
|
|
buffer RESB 10
|
|
screen WORD 0xb800 |