From 7cb6dcee10b19484aeb1817dc7cc0b2ad336ca6f Mon Sep 17 00:00:00 2001 From: Timon Date: Sat, 15 Nov 2025 12:20:46 +0100 Subject: [PATCH] Spremenu FA.dev pa ene pomozne programe ki sm jih uporabljou dodal --- ass1/Rekurzija/FA.dev | 2 + ass1/Rekurzija/read_print_int.asm | 90 +++++++++++++++++++++++++++++++ ass1/Rekurzija/rek_simplified.asm | 82 ++++++++++++++++++++++++++++ 3 files changed, 174 insertions(+) create mode 100644 ass1/Rekurzija/read_print_int.asm create mode 100644 ass1/Rekurzija/rek_simplified.asm diff --git a/ass1/Rekurzija/FA.dev b/ass1/Rekurzija/FA.dev index 86e9df1..cc4fa43 100644 --- a/ass1/Rekurzija/FA.dev +++ b/ass1/Rekurzija/FA.dev @@ -2,4 +2,6 @@ 4 5 6 +7 +10 0 diff --git a/ass1/Rekurzija/read_print_int.asm b/ass1/Rekurzija/read_print_int.asm new file mode 100644 index 0000000..de7d2be --- /dev/null +++ b/ass1/Rekurzija/read_print_int.asm @@ -0,0 +1,90 @@ +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 \ No newline at end of file diff --git a/ass1/Rekurzija/rek_simplified.asm b/ass1/Rekurzija/rek_simplified.asm new file mode 100644 index 0000000..7e525ea --- /dev/null +++ b/ass1/Rekurzija/rek_simplified.asm @@ -0,0 +1,82 @@ +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 \ No newline at end of file