diff --git a/FA.dev b/FA.dev index 68125c5..2addf68 100644 --- a/FA.dev +++ b/FA.dev @@ -1,8 +1,8 @@ -1 -2 -3 -4 -5 -6 -7 +1 +2 +3 +4 +5 +6 +7 0 \ No newline at end of file diff --git a/ass1/arith.asm b/ass1/arith.asm index 3474a8e..21b7e12 100644 --- a/ass1/arith.asm +++ b/ass1/arith.asm @@ -1,44 +1,44 @@ - - -arith START 0 - -start LDA x - ADD y - STA sum .shrani vsoto - - LDA x - SUB y - STA diff .shrani razliko - - LDA x - MUL y - STA prod .sharni produkt - - LDA x - DIV y - STA quot .shrani kvocient - - LDA y - MUL quot - STA z - LDA x - SUB z - STA mod .shrani modulo - -halt J halt - END start - -.podatki -x WORD 20 -y WORD 3 - -.rezultati -sum RESW 1 -diff RESW 1 -prod RESW 1 -quot RESW 1 -mod RESW 1 - -.za modulo -z RESW 1 - + + +arith START 0 + +start LDA x + ADD y + STA sum .shrani vsoto + + LDA x + SUB y + STA diff .shrani razliko + + LDA x + MUL y + STA prod .sharni produkt + + LDA x + DIV y + STA quot .shrani kvocient + + LDA y + MUL quot + STA z + LDA x + SUB z + STA mod .shrani modulo + +halt J halt + END start + +.podatki +x WORD 20 +y WORD 3 + +.rezultati +sum RESW 1 +diff RESW 1 +prod RESW 1 +quot RESW 1 +mod RESW 1 + +.za modulo +z RESW 1 + diff --git a/ass1/arithr.asm b/ass1/arithr.asm index e014c74..d1792cf 100644 --- a/ass1/arithr.asm +++ b/ass1/arithr.asm @@ -1,46 +1,46 @@ - - -arith START 0 - -start LDT x - LDS y - ADDR T, S .shrani vsoto - STS sum - SUBR T, S .resetiraj S nazaj na y - - SUBR S, T - STT diff .shrani razliko - ADDR S, T .popravi T - - MULR T, S - STS prod .sharni produkt - - LDT x - LDS y - DIVR S, T - STT quot .shrani kvocient - - LDT x - LDS y - LDB quot - MULR S, B - SUBR B, T - STT mod .shrani modulo - -halt J halt - END start - -.podatki -x WORD 20 -y WORD 3 - -.rezultati -sum RESW 1 -diff RESW 1 -prod RESW 1 -quot RESW 1 -mod RESW 1 - -.za modulo -z RESW 1 - + + +arith START 0 + +start LDT x + LDS y + ADDR T, S .shrani vsoto + STS sum + SUBR T, S .resetiraj S nazaj na y + + SUBR S, T + STT diff .shrani razliko + ADDR S, T .popravi T + + MULR T, S + STS prod .sharni produkt + + LDT x + LDS y + DIVR S, T + STT quot .shrani kvocient + + LDT x + LDS y + LDB quot + MULR S, B + SUBR B, T + STT mod .shrani modulo + +halt J halt + END start + +.podatki +x WORD 20 +y WORD 3 + +.rezultati +sum RESW 1 +diff RESW 1 +prod RESW 1 +quot RESW 1 +mod RESW 1 + +.za modulo +z RESW 1 + diff --git a/ass1/cat.asm b/ass1/cat.asm index 555b53f..4faea58 100644 --- a/ass1/cat.asm +++ b/ass1/cat.asm @@ -1,7 +1,7 @@ -cat START 0 -.beri in pisi -loop RD #0 - WD #1 - J loop - +cat START 0 +.beri in pisi +loop RD #0 + WD #1 + J loop + END loop \ No newline at end of file diff --git a/ass1/echo.asm b/ass1/echo.asm index 28bdeba..fdf38db 100644 --- a/ass1/echo.asm +++ b/ass1/echo.asm @@ -1,137 +1,137 @@ -echo START 0 -start .LDCH txt - .JSUB char - .JSUB nl - .LDA #txt - .JSUB string - .JSUB nl - - LDCH #12 - JSUB num - -halt J halt - -.char -char STB regB - STT regT - .STL regL - STS regS .shranimo registre - - WD #1 - .obnovimo registre - LDB regB - LDT regT - .LDL regL - LDS regS - - RSUB - -.nl -nl STB regB - STT regT - STS regS .shranimo registre - - LDCH newline - WD #1 - LDX #1 - LDCH newline, X - WD #1 - - .obnovimo registre - LDB regB - LDT regT - LDS regS - - RSUB - -.string -string STA regA - STB regB - STT regT - .STL regL - STS regS .shranimo registre - -loop LDB #1 - CLEAR A .da lahko comparamo z 0 - LDCH @regA - COMP #0 - WD #1 - .add +1 to regA - LDA regA - ADD #1 - STA regA - JGT loop - - LDA regA .obnovimo registre - LDB regB - LDT regT - .LDL regL - LDS regS - - RSUB -.izpiše število zapisano v A na std izhod -num STA regA - STB regB - STT regT - STL regL - STS regS .shranimo registre - - LDX #4 .X steje stevke, 4 je zadnji index arraya velikosti 5 - LDS #10 .za množenje/deljenje - LDT #0x30 .za pretvorbo v ascii - -loop2 RMO A, B - DIVR S, B .B = B/10 - MULR S, B .B= B*10 - SUBR B, A .A = ostanek - ADDR T, A .pretvorimo A v ascii - STCH digs, X .shranimo ascii ostanek - - .zmanjšamo X in primerjamo z #5 - RMO X, A - SUB #1 - RMO A, X - LDA #0 - COMPR X, A - - RMO B, A .premaknemo kar je še potrebno izračunati v A - DIVR S, A .A je sedaj naslednja števka - - JEQ loop2 - JGT loop2 - - .kličemo string za izpis - LDA #digs - JSUB string - JSUB nl - - LDA regA .obnovimo registre - LDB regB - LDT regT - LDL regL - LDS regS - - RSUB - - -.digits za num -digs RESB 5 .0 bo prazna za lazje izpisovanje - BYTE 0 .konec števke - -.txt -txt BYTE C'hi' - BYTE 0 - -.constante -newline BYTE 0x0D - BYTE 0x0A - -.registri -regA RESW 1 -regB RESW 1 -regT RESW 1 -regS RESW 1 -regL RESW 1 - - +echo START 0 +start .LDCH txt + .JSUB char + .JSUB nl + .LDA #txt + .JSUB string + .JSUB nl + + LDCH #12 + JSUB num + +halt J halt + +.char +char STB regB + STT regT + .STL regL + STS regS .shranimo registre + + WD #1 + .obnovimo registre + LDB regB + LDT regT + .LDL regL + LDS regS + + RSUB + +.nl +nl STB regB + STT regT + STS regS .shranimo registre + + LDCH newline + WD #1 + LDX #1 + LDCH newline, X + WD #1 + + .obnovimo registre + LDB regB + LDT regT + LDS regS + + RSUB + +.string +string STA regA + STB regB + STT regT + .STL regL + STS regS .shranimo registre + +loop LDB #1 + CLEAR A .da lahko comparamo z 0 + LDCH @regA + COMP #0 + WD #1 + .add +1 to regA + LDA regA + ADD #1 + STA regA + JGT loop + + LDA regA .obnovimo registre + LDB regB + LDT regT + .LDL regL + LDS regS + + RSUB +.izpiše število zapisano v A na std izhod +num STA regA + STB regB + STT regT + STL regL + STS regS .shranimo registre + + LDX #4 .X steje stevke, 4 je zadnji index arraya velikosti 5 + LDS #10 .za množenje/deljenje + LDT #0x30 .za pretvorbo v ascii + +loop2 RMO A, B + DIVR S, B .B = B/10 + MULR S, B .B= B*10 + SUBR B, A .A = ostanek + ADDR T, A .pretvorimo A v ascii + STCH digs, X .shranimo ascii ostanek + + .zmanjšamo X in primerjamo z #5 + RMO X, A + SUB #1 + RMO A, X + LDA #0 + COMPR X, A + + RMO B, A .premaknemo kar je še potrebno izračunati v A + DIVR S, A .A je sedaj naslednja števka + + JEQ loop2 + JGT loop2 + + .kličemo string za izpis + LDA #digs + JSUB string + JSUB nl + + LDA regA .obnovimo registre + LDB regB + LDT regT + LDL regL + LDS regS + + RSUB + + +.digits za num +digs RESB 5 .0 bo prazna za lazje izpisovanje + BYTE 0 .konec števke + +.txt +txt BYTE C'hi' + BYTE 0 + +.constante +newline BYTE 0x0D + BYTE 0x0A + +.registri +regA RESW 1 +regB RESW 1 +regT RESW 1 +regS RESW 1 +regL RESW 1 + + END start \ No newline at end of file diff --git a/ass1/fac.asm b/ass1/fac.asm index 6969099..cc68666 100644 --- a/ass1/fac.asm +++ b/ass1/fac.asm @@ -1,68 +1,68 @@ -prog START 0 -zacetek CLEAR X -loop RD #0xFA - COMP #0 - JEQ halt - JSUB fact - WD #1 - J loop - -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 - +prog START 0 +zacetek CLEAR X +loop RD #0xFA + COMP #0 + JEQ halt + JSUB fact + WD #1 + J loop + +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 \ No newline at end of file diff --git a/ass1/fact.asm b/ass1/fact.asm index 0e77c99..5115aa7 100644 --- a/ass1/fact.asm +++ b/ass1/fact.asm @@ -1,66 +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 - +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 \ No newline at end of file diff --git a/ass1/horner.asm b/ass1/horner.asm index 75a1a87..fd6002c 100644 --- a/ass1/horner.asm +++ b/ass1/horner.asm @@ -1,38 +1,38 @@ -poly START 0 -start LDT x4 - LDS x - MULR S, T - LDA x3 - ADDR T, A . do sedaj izračunano (1x + 2) - - LDT x2 - MULR S, A - ADDR T, A .do sedaj izračunano ((1x+2)x + 3) - - LDT x1 - MULR S, A - ADDR T, A .do sedaj izračunano (((1x+2)x + 3)x + 4) - - LDT x0 - MULR S, A - ADDR T, A .do sedaj izračunano (((1x+2)x + 3)x + 4)x + 5 - - - STA rez - -halt J halt - END start - - -.polinom -x4 WORD 1 -x3 WORD 2 -x2 WORD 3 -x1 WORD 4 -x0 WORD 5 - -.tocka -x WORD 2 - -.rezultat +poly START 0 +start LDT x4 + LDS x + MULR S, T + LDA x3 + ADDR T, A . do sedaj izračunano (1x + 2) + + LDT x2 + MULR S, A + ADDR T, A .do sedaj izračunano ((1x+2)x + 3) + + LDT x1 + MULR S, A + ADDR T, A .do sedaj izračunano (((1x+2)x + 3)x + 4) + + LDT x0 + MULR S, A + ADDR T, A .do sedaj izračunano (((1x+2)x + 3)x + 4)x + 5 + + + STA rez + +halt J halt + END start + + +.polinom +x4 WORD 1 +x3 WORD 2 +x2 WORD 3 +x1 WORD 4 +x0 WORD 5 + +.tocka +x WORD 2 + +.rezultat rez RESW 1 \ No newline at end of file diff --git a/ass1/insertion_sort.asm b/ass1/insertion_sort.asm index db83692..b1aee81 100644 --- a/ass1/insertion_sort.asm +++ b/ass1/insertion_sort.asm @@ -1,66 +1,66 @@ -.program prebere iz spomina seznam števil dolžine len -.in jih uredi z insertion sortom -.pustimo prvi element paddan, da lažje rečunamo premike -prog START 0 - LDX #6 - -loop LDB #len - COMPR X, B .i < len - JEQ halt .zaključi - - LDA arr, X .A = arr[i] - RMO X, S .S <- i - LDT #3 .T <- 3 - SUBR T, X .X <- j= i - 1 - -loop2 LDT #3 - COMPR X, T .j >= 1 - JLT insert .ko je j = 0 skoči - J next .skoči na preverjanje naslednjega pogoja - - .shranimo S nazaj v X in ga zmanjšamo za ena - .nato skočimo nazaj v loop -exit2 RMO S, X .X <- i - LDT #3 - ADDR T, X .X <- i + 1 - J loop - -next LDB arr, X - COMPR B, A .arr[j] > arr[i] - JGT swap - J insert .če pogoj ni izpolnjen - - .sicer zamenjamo elementa -swap LDT #3 - ADDR T, X .X <- j + 1 - STB arr, X. arr[j+1] = arr[j] - - LDT #6 - SUBR T, X .x <- x-1 - J loop2 - -insert LDT #3 - ADDR T, X .j = j+1 - STA arr, X .arr[j+1] = arr[i] - SUBR T, X .j = j - J exit2 - -halt J halt - -arr WORD 0 - WORD 5 - WORD 3 - WORD 8 - WORD 1 - WORD 4 - WORD 7 - WORD 2 - WORD 9 -arrEnd WORD 6 - -len EQU arrEnd - arr + 3 - - - - +.program prebere iz spomina seznam števil dolžine len +.in jih uredi z insertion sortom +.pustimo prvi element paddan, da lažje rečunamo premike +prog START 0 + LDX #6 + +loop LDB #len + COMPR X, B .i < len + JEQ halt .zaključi + + LDA arr, X .A = arr[i] + RMO X, S .S <- i + LDT #3 .T <- 3 + SUBR T, X .X <- j= i - 1 + +loop2 LDT #3 + COMPR X, T .j >= 1 + JLT insert .ko je j = 0 skoči + J next .skoči na preverjanje naslednjega pogoja + + .shranimo S nazaj v X in ga zmanjšamo za ena + .nato skočimo nazaj v loop +exit2 RMO S, X .X <- i + LDT #3 + ADDR T, X .X <- i + 1 + J loop + +next LDB arr, X + COMPR B, A .arr[j] > arr[i] + JGT swap + J insert .če pogoj ni izpolnjen + + .sicer zamenjamo elementa +swap LDT #3 + ADDR T, X .X <- j + 1 + STB arr, X. arr[j+1] = arr[j] + + LDT #6 + SUBR T, X .x <- x-1 + J loop2 + +insert LDT #3 + ADDR T, X .j = j+1 + STA arr, X .arr[j+1] = arr[i] + SUBR T, X .j = j + J exit2 + +halt J halt + +arr WORD 0 + WORD 5 + WORD 3 + WORD 8 + WORD 1 + WORD 4 + WORD 7 + WORD 2 + WORD 9 +arrEnd WORD 6 + +len EQU arrEnd - arr + 3 + + + + END prog \ No newline at end of file diff --git a/ass1/poly.asm b/ass1/poly.asm index 24e92a1..0fb41a5 100644 --- a/ass1/poly.asm +++ b/ass1/poly.asm @@ -1,42 +1,42 @@ -poly START 0 -start LDA x0 .pristejemo x0 v A - - LDB x - LDS x - LDT x1 - MULR S, T - ADDR T, A .pristejemo x0 * x - - LDT x2 - MULR B, S .izracunamo x^2 - MULR S, T - ADDR T, A - - LDT x3 - MULR B, S .izracunamo x^3 - MULR S, T - ADDR T, A - - LDT x4 - MULR B, S .izracunamo x^4 - MULR S, T - ADDR T, A - - STA rez - -halt J halt - END start - - -.polinom -x4 WORD 1 -x3 WORD 2 -x2 WORD 3 -x1 WORD 4 -x0 WORD 5 - -.tocka -x WORD 2 - -.rezultat +poly START 0 +start LDA x0 .pristejemo x0 v A + + LDB x + LDS x + LDT x1 + MULR S, T + ADDR T, A .pristejemo x0 * x + + LDT x2 + MULR B, S .izracunamo x^2 + MULR S, T + ADDR T, A + + LDT x3 + MULR B, S .izracunamo x^3 + MULR S, T + ADDR T, A + + LDT x4 + MULR B, S .izracunamo x^4 + MULR S, T + ADDR T, A + + STA rez + +halt J halt + END start + + +.polinom +x4 WORD 1 +x3 WORD 2 +x2 WORD 3 +x1 WORD 4 +x0 WORD 5 + +.tocka +x WORD 2 + +.rezultat rez RESW 1 \ No newline at end of file diff --git a/ass1/polySubrutine.asm b/ass1/polySubrutine.asm index af8de5d..8b81723 100644 --- a/ass1/polySubrutine.asm +++ b/ass1/polySubrutine.asm @@ -1,64 +1,64 @@ -poly START 0 -start LDA x - STA arg1 - JSUB startSubrutine - LDA subRez - STA rez - -halt J halt - END start - -.subrutina za izračun tega polinoma v točki arg1 -startSubrutine STA regA - STB regB - STT regT - STS regS .shranimo registre - - LDA x0 .pristejemo x0 v A - - LDX #3 .odmik v arrayu - LDS arg1 -loop LDT x0, X .preberemo x_n - MULR S, T .izračunamo x_n * x^n - ADDR T, A .pristejemo v vsoto - LDT arg1 - MULR T, S .zmožimo naslednjo potenco - LDT #3 - ADDR T, X .povečamo odmik - LDT #13 - COMPR T, X - JGT loop - - STA subRez .shranimo rez - - LDA regA .obnovimo registre - LDB regB - LDT regT - LDS regS - - RSUB - -.polinom -x0 WORD 5 - WORD 4 - WORD 3 - WORD 2 - WORD 1 - -.tocka -x WORD 2 - -.rezultat -rez RESW 1 - -.parameter subrutine -arg1 RESW 1 - -.rezultat subrutine -subRez RESW 1 - -.registri -regA RESW 1 -regB RESW 1 -regT RESW 1 -regS RESW 1 +poly START 0 +start LDA x + STA arg1 + JSUB startSubrutine + LDA subRez + STA rez + +halt J halt + END start + +.subrutina za izračun tega polinoma v točki arg1 +startSubrutine STA regA + STB regB + STT regT + STS regS .shranimo registre + + LDA x0 .pristejemo x0 v A + + LDX #3 .odmik v arrayu + LDS arg1 +loop LDT x0, X .preberemo x_n + MULR S, T .izračunamo x_n * x^n + ADDR T, A .pristejemo v vsoto + LDT arg1 + MULR T, S .zmožimo naslednjo potenco + LDT #3 + ADDR T, X .povečamo odmik + LDT #13 + COMPR T, X + JGT loop + + STA subRez .shranimo rez + + LDA regA .obnovimo registre + LDB regB + LDT regT + LDS regS + + RSUB + +.polinom +x0 WORD 5 + WORD 4 + WORD 3 + WORD 2 + WORD 1 + +.tocka +x WORD 2 + +.rezultat +rez RESW 1 + +.parameter subrutine +arg1 RESW 1 + +.rezultat subrutine +subRez RESW 1 + +.registri +regA RESW 1 +regB RESW 1 +regT RESW 1 +regS RESW 1 diff --git a/ass1/print.asm b/ass1/print.asm index e65c5b2..97e1e3e 100644 --- a/ass1/print.asm +++ b/ass1/print.asm @@ -1,17 +1,17 @@ -print START 0 -zacetek CLEAR X -loop LDCH txt, X - WD #0xAA - TIX #len .#len, ker je len EQU in ne dejanska lokacija v spominu!!!!! - JLT loop - -halt J halt - -.constants -txt BYTE C'SIC/XE' - BYTE 0 -txtend EQU * -len EQU txtend-txt .definicija konstante EQU, ki ni shranjena v pomnilniku, zato ko jo želimo uporabiti -.rabimo #len - +print START 0 +zacetek CLEAR X +loop LDCH txt, X + WD #0xAA + TIX #len .#len, ker je len EQU in ne dejanska lokacija v spominu!!!!! + JLT loop + +halt J halt + +.constants +txt BYTE C'SIC/XE' + BYTE 0 +txtend EQU * +len EQU txtend-txt .definicija konstante EQU, ki ni shranjena v pomnilniku, zato ko jo želimo uporabiti +.rabimo #len + END zacetek \ No newline at end of file diff --git a/ass1/rec.asm b/ass1/rec.asm index 624bc11..be5e4ac 100644 --- a/ass1/rec.asm +++ b/ass1/rec.asm @@ -1,233 +1,233 @@ -prog START 0 -zacetek JSUB sinit .inicializiramo sklad -.beremo iz 0xFA, dokler ne preberemo 0 -loop3 CLEAR A - JSUB rdNum - COMP #0 - JEQ halt - - - JSUB fact - JSUB num - J loop3 - -halt J halt - -.beri število v A dokler ne naletiš na newline in jo pretvori v int -rdNum STL @stkp - JSUB spush - STA @stkp - JSUB spush - STB @stkp - JSUB spush - - CLEAR A - CLEAR B .v B bomo shranili prebran rezultat - LDS #10 .za množenje -loop4 RD #0xFA - COMP #0xD .beremo newline - JEQ nwl - .else - MULR S, B - SUB #0x30 .pretvorimo v int - ADDR A, B - J loop4 - -nwl RD #0xFA .prebre še 0x0A - CLEAR A - RMO B, A - - JSUB spop - LDB @stkp - JSUB spop - .LDA @stkp da ne povozimo odgovora? - JSUB spop - LDL @stkp - - RSUB -.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 -.inicializira kazalec na sklad -sinit STA stkA - LDA #stkRESW .inicializiraj stkp - STA stkp - LDA stkA - RSUB - -.pusha na sklad, pred klicem te subrutine shrani na sklad kar želiš -spush STA stkA - LDA stkp .poveca stkp za 3 - ADD #3 - STA stkp - LDA stkA - RSUB - -.popa iz sklada, po koncu te subrutine iz sklada beri kar želš -spop STA stkA - LDA stkp .zmanjsa stkp za 3 - SUB #3 - STA stkp - LDA stkA - RSUB - - -.nl -nl STL @stkp - JSUB spush - STB @stkp .shranimo registre - JSUB spush - STT @stkp - JSUB spush - STS @stkp - JSUB spush - - - LDCH newline - WD #1 - LDX #1 - LDCH newline, X - WD #1 - - .obnovimo registre - JSUB spop - LDS @stkp - JSUB spop - LDT @stkp - JSUB spop - LDB @stkp - JSUB spop - LDL @stkp - - RSUB - -.string -string STL @stkp - JSUB spush - STB @stkp .shranimo registre - JSUB spush - STT @stkp - JSUB spush - STS @stkp - JSUB spush - STA regA - -loop LDB #1 - CLEAR A .da lahko comparamo z 0 - LDCH @regA - COMP #0 - WD #1 - .add +1 to regA - LDA regA - ADD #1 - STA regA - JGT loop - - LDA regA .obnovimo registre - JSUB spop - LDS @stkp - JSUB spop - LDT @stkp - JSUB spop - LDB @stkp - JSUB spop - LDL @stkp - - RSUB -.izpiše število zapisano v A na std izhod -num STL @stkp - JSUB spush - STB @stkp .shranimo registre - JSUB spush - STT @stkp - JSUB spush - STS @stkp - JSUB spush - - LDX #4 .X steje stevke, 4 je zadnji index arraya velikosti 5 - LDS #10 .za množenje/deljenje - LDT #0x30 .za pretvorbo v ascii - - -loop2 RMO A, B - DIVR S, B .B = B/10 - MULR S, B .B= B*10 - SUBR B, A .A = ostanek - ADDR T, A .pretvorimo A v ascii - STCH digs, X .shranimo ascii ostanek - - .zmanjšamo X in primerjamo z #5 - RMO X, A - SUB #1 - RMO A, X - LDA #0 - COMPR X, A - - RMO B, A .premaknemo kar je še potrebno izračunati v A - DIVR S, A .A je sedaj naslednja števka - - JEQ loop2 - JGT loop2 - - .kličemo string za izpis - LDA #digs - JSUB string - JSUB nl - - JSUB spop - LDS @stkp - JSUB spop - LDT @stkp - JSUB spop - LDB @stkp - JSUB spop - LDL @stkp - - RSUB - - -.digits za num -digs RESB 5 .0 bo prazna za lazje izpisovanje - BYTE 0 .konec števke - -.constante -newline BYTE 0x0D - BYTE 0x0A - -.shramba za string -regA WORD 0 - -.podatki za sklad -stkp WORD 0 -stkA WORD 0 -stkRESW RESW 1000 - +prog START 0 +zacetek JSUB sinit .inicializiramo sklad +.beremo iz 0xFA, dokler ne preberemo 0 +loop3 CLEAR A + JSUB rdNum + COMP #0 + JEQ halt + + + JSUB fact + JSUB num + J loop3 + +halt J halt + +.beri število v A dokler ne naletiš na newline in jo pretvori v int +rdNum STL @stkp + JSUB spush + STA @stkp + JSUB spush + STB @stkp + JSUB spush + + CLEAR A + CLEAR B .v B bomo shranili prebran rezultat + LDS #10 .za množenje +loop4 RD #0xFA + COMP #0xD .beremo newline + JEQ nwl + .else + MULR S, B + SUB #0x30 .pretvorimo v int + ADDR A, B + J loop4 + +nwl RD #0xFA .prebre še 0x0A + CLEAR A + RMO B, A + + JSUB spop + LDB @stkp + JSUB spop + .LDA @stkp da ne povozimo odgovora? + JSUB spop + LDL @stkp + + RSUB +.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 +.inicializira kazalec na sklad +sinit STA stkA + LDA #stkRESW .inicializiraj stkp + STA stkp + LDA stkA + RSUB + +.pusha na sklad, pred klicem te subrutine shrani na sklad kar želiš +spush STA stkA + LDA stkp .poveca stkp za 3 + ADD #3 + STA stkp + LDA stkA + RSUB + +.popa iz sklada, po koncu te subrutine iz sklada beri kar želš +spop STA stkA + LDA stkp .zmanjsa stkp za 3 + SUB #3 + STA stkp + LDA stkA + RSUB + + +.nl +nl STL @stkp + JSUB spush + STB @stkp .shranimo registre + JSUB spush + STT @stkp + JSUB spush + STS @stkp + JSUB spush + + + LDCH newline + WD #1 + LDX #1 + LDCH newline, X + WD #1 + + .obnovimo registre + JSUB spop + LDS @stkp + JSUB spop + LDT @stkp + JSUB spop + LDB @stkp + JSUB spop + LDL @stkp + + RSUB + +.string +string STL @stkp + JSUB spush + STB @stkp .shranimo registre + JSUB spush + STT @stkp + JSUB spush + STS @stkp + JSUB spush + STA regA + +loop LDB #1 + CLEAR A .da lahko comparamo z 0 + LDCH @regA + COMP #0 + WD #1 + .add +1 to regA + LDA regA + ADD #1 + STA regA + JGT loop + + LDA regA .obnovimo registre + JSUB spop + LDS @stkp + JSUB spop + LDT @stkp + JSUB spop + LDB @stkp + JSUB spop + LDL @stkp + + RSUB +.izpiše število zapisano v A na std izhod +num STL @stkp + JSUB spush + STB @stkp .shranimo registre + JSUB spush + STT @stkp + JSUB spush + STS @stkp + JSUB spush + + LDX #4 .X steje stevke, 4 je zadnji index arraya velikosti 5 + LDS #10 .za množenje/deljenje + LDT #0x30 .za pretvorbo v ascii + + +loop2 RMO A, B + DIVR S, B .B = B/10 + MULR S, B .B= B*10 + SUBR B, A .A = ostanek + ADDR T, A .pretvorimo A v ascii + STCH digs, X .shranimo ascii ostanek + + .zmanjšamo X in primerjamo z #5 + RMO X, A + SUB #1 + RMO A, X + LDA #0 + COMPR X, A + + RMO B, A .premaknemo kar je še potrebno izračunati v A + DIVR S, A .A je sedaj naslednja števka + + JEQ loop2 + JGT loop2 + + .kličemo string za izpis + LDA #digs + JSUB string + JSUB nl + + JSUB spop + LDS @stkp + JSUB spop + LDT @stkp + JSUB spop + LDB @stkp + JSUB spop + LDL @stkp + + RSUB + + +.digits za num +digs RESB 5 .0 bo prazna za lazje izpisovanje + BYTE 0 .konec števke + +.constante +newline BYTE 0x0D + BYTE 0x0A + +.shramba za string +regA WORD 0 + +.podatki za sklad +stkp WORD 0 +stkA WORD 0 +stkRESW RESW 1000 + END prog \ No newline at end of file diff --git a/ass1/sreen.asm b/ass1/sreen.asm index 76f0330..8702e49 100644 --- a/ass1/sreen.asm +++ b/ass1/sreen.asm @@ -1,38 +1,38 @@ -scr START 0 - LDCH txt - +STCH screen - LDX #3 - +STCH screen, X - - JSUB scrcfill - - JSUB scrclear - -halt J halt - -scrclear LDCH #0 - LDS #scrlen - LDX #0 -loop +STCH screen, X - TIXR S - JLT loop - - RSUB - - -scrcfill - LDS #scrlen - LDX #0 -loop2 +STCH screen, X - TIXR S - JLT loop2 - - RSUB - -txt BYTE C'hi' -screen EQU 0x0B800 -scrcols EQU 80 -scrrows EQU 25 -scrlen EQU 2000 - +scr START 0 + LDCH txt + +STCH screen + LDX #3 + +STCH screen, X + + JSUB scrcfill + + JSUB scrclear + +halt J halt + +scrclear LDCH #0 + LDS #scrlen + LDX #0 +loop +STCH screen, X + TIXR S + JLT loop + + RSUB + + +scrcfill + LDS #scrlen + LDX #0 +loop2 +STCH screen, X + TIXR S + JLT loop2 + + RSUB + +txt BYTE C'hi' +screen EQU 0x0B800 +scrcols EQU 80 +scrrows EQU 25 +scrlen EQU 2000 + END scr \ No newline at end of file diff --git a/ass1/stack.asm b/ass1/stack.asm index bd6940d..d6cdd0d 100644 --- a/ass1/stack.asm +++ b/ass1/stack.asm @@ -1,33 +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 - - +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 + + diff --git a/ass2/SICocaml/SICXE/SICXE.opam b/ass2/SICocaml/SICXE/SICXE.opam new file mode 100644 index 0000000..a43bbcb --- /dev/null +++ b/ass2/SICocaml/SICXE/SICXE.opam @@ -0,0 +1,32 @@ +# This file is generated by dune, edit dune-project instead +opam-version: "2.0" +synopsis: "A short synopsis" +description: "A longer description" +maintainer: ["Maintainer Name "] +authors: ["Author Name "] +license: "LICENSE" +tags: ["add topics" "to describe" "your" "project"] +homepage: "https://github.com/username/reponame" +doc: "https://url/to/documentation" +bug-reports: "https://github.com/username/reponame/issues" +depends: [ + "dune" {>= "3.20"} + "ocaml" + "odoc" {with-doc} +] +build: [ + ["dune" "subst"] {dev} + [ + "dune" + "build" + "-p" + name + "-j" + jobs + "@install" + "@runtest" {with-test} + "@doc" {with-doc} + ] +] +dev-repo: "git+https://github.com/username/reponame.git" +x-maintenance-intent: ["(latest)"] diff --git a/ass2/SICocaml/SICXE/_build/.db b/ass2/SICocaml/SICXE/_build/.db new file mode 100644 index 0000000..0a18ffb Binary files /dev/null and b/ass2/SICocaml/SICXE/_build/.db differ diff --git a/ass2/SICocaml/SICXE/_build/.digest-db b/ass2/SICocaml/SICXE/_build/.digest-db new file mode 100644 index 0000000..9838aa9 Binary files /dev/null and b/ass2/SICocaml/SICXE/_build/.digest-db differ diff --git a/ass2/SICocaml/SICXE/_build/.filesystem-clock b/ass2/SICocaml/SICXE/_build/.filesystem-clock new file mode 100644 index 0000000..c61f4a7 --- /dev/null +++ b/ass2/SICocaml/SICXE/_build/.filesystem-clock @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/ass2/SICocaml/SICXE/_build/.lock b/ass2/SICocaml/SICXE/_build/.lock new file mode 100644 index 0000000..e69de29 diff --git a/ass2/SICocaml/SICXE/_build/default/.dune/configurator b/ass2/SICocaml/SICXE/_build/default/.dune/configurator new file mode 100644 index 0000000..19708df --- /dev/null +++ b/ass2/SICocaml/SICXE/_build/default/.dune/configurator @@ -0,0 +1,2 @@ +(ocamlc /usr/bin/ocamlc.opt) +(ocaml_config_vars (afl_instrument false) (architecture amd64) (asm x86_64-linux-gnu-as) (asm_cfi_supported true) (ast_impl_magic_number Caml1999M030) (ast_intf_magic_number Caml1999N030) (bytecomp_c_compiler "x86_64-linux-gnu-gcc -O2 -fno-strict-aliasing -fwrapv -pthread -fPIC -g -O2 -ffile-prefix-map=/build/ocaml-SC7b9w/ocaml-4.13.1=. -fstack-protector-strong -Wformat -Werror=format-security -D_FILE_OFFSET_BITS=64 -Wdate-time -D_FORTIFY_SOURCE=2") (bytecomp_c_libraries "-lm -lpthread") (c_compiler x86_64-linux-gnu-gcc) (ccomp_type cc) (cma_magic_number Caml1999A030) (cmi_magic_number Caml1999I030) (cmo_magic_number Caml1999O030) (cmt_magic_number Caml1999T030) (cmx_magic_number Caml1999Y030) (cmxa_magic_number Caml1999Z030) (cmxs_magic_number Caml1999D030) (default_executable_name a.out) (default_safe_string true) (exec_magic_number Caml1999X030) (ext_asm .s) (ext_dll .so) (ext_exe "") (ext_lib .a) (ext_obj .o) (flambda false) (flat_float_array true) (function_sections true) (host x86_64-pc-linux-gnu) (int_size 63) (linear_magic_number Caml1999L030) (model default) (native_c_compiler "x86_64-linux-gnu-gcc -O2 -fno-strict-aliasing -fwrapv -pthread -fPIC -g -O2 -ffile-prefix-map=/build/ocaml-SC7b9w/ocaml-4.13.1=. -fstack-protector-strong -Wformat -Werror=format-security -D_FILE_OFFSET_BITS=64 -Wdate-time -D_FORTIFY_SOURCE=2") (native_c_libraries "-lm ") (native_pack_linker "x86_64-linux-gnu-ld -r -o ") (ocamlc_cflags "-O2 -fno-strict-aliasing -fwrapv -pthread -fPIC -g -O2 -ffile-prefix-map=/build/ocaml-SC7b9w/ocaml-4.13.1=. -fstack-protector-strong -Wformat -Werror=format-security") (ocamlc_cppflags "-D_FILE_OFFSET_BITS=64 -Wdate-time -D_FORTIFY_SOURCE=2") (ocamlopt_cflags "-O2 -fno-strict-aliasing -fwrapv -pthread -fPIC -g -O2 -ffile-prefix-map=/build/ocaml-SC7b9w/ocaml-4.13.1=. -fstack-protector-strong -Wformat -Werror=format-security") (ocamlopt_cppflags "-D_FILE_OFFSET_BITS=64 -Wdate-time -D_FORTIFY_SOURCE=2") (os_type Unix) (ranlib x86_64-linux-gnu-ranlib) (safe_string true) (standard_library /usr/lib/ocaml) (standard_library_default /usr/lib/ocaml) (supports_shared_libraries true) (system linux) (systhread_supported true) (target x86_64-pc-linux-gnu) (version 4.13.1) (windows_unicode false) (with_frame_pointers false) (word_size 64)) diff --git a/ass2/SICocaml/SICXE/_build/default/.dune/configurator.v2 b/ass2/SICocaml/SICXE/_build/default/.dune/configurator.v2 new file mode 100644 index 0000000..6fe4a49 --- /dev/null +++ b/ass2/SICocaml/SICXE/_build/default/.dune/configurator.v2 @@ -0,0 +1 @@ +((6:ocamlc19:/usr/bin/ocamlc.opt)(17:ocaml_config_vars((14:afl_instrument5:false)(12:architecture5:amd64)(3:asm19:x86_64-linux-gnu-as)(17:asm_cfi_supported4:true)(21:ast_impl_magic_number12:Caml1999M030)(21:ast_intf_magic_number12:Caml1999N030)(19:bytecomp_c_compiler241:x86_64-linux-gnu-gcc -O2 -fno-strict-aliasing -fwrapv -pthread -fPIC -g -O2 -ffile-prefix-map=/build/ocaml-SC7b9w/ocaml-4.13.1=. -fstack-protector-strong -Wformat -Werror=format-security -D_FILE_OFFSET_BITS=64 -Wdate-time -D_FORTIFY_SOURCE=2)(20:bytecomp_c_libraries14:-lm -lpthread)(10:c_compiler20:x86_64-linux-gnu-gcc)(10:ccomp_type2:cc)(16:cma_magic_number12:Caml1999A030)(16:cmi_magic_number12:Caml1999I030)(16:cmo_magic_number12:Caml1999O030)(16:cmt_magic_number12:Caml1999T030)(16:cmx_magic_number12:Caml1999Y030)(17:cmxa_magic_number12:Caml1999Z030)(17:cmxs_magic_number12:Caml1999D030)(23:default_executable_name5:a.out)(19:default_safe_string4:true)(17:exec_magic_number12:Caml1999X030)(7:ext_asm2:.s)(7:ext_dll3:.so)(7:ext_exe0:)(7:ext_lib2:.a)(7:ext_obj2:.o)(7:flambda5:false)(16:flat_float_array4:true)(17:function_sections4:true)(4:host19:x86_64-pc-linux-gnu)(8:int_size2:63)(19:linear_magic_number12:Caml1999L030)(5:model7:default)(17:native_c_compiler241:x86_64-linux-gnu-gcc -O2 -fno-strict-aliasing -fwrapv -pthread -fPIC -g -O2 -ffile-prefix-map=/build/ocaml-SC7b9w/ocaml-4.13.1=. -fstack-protector-strong -Wformat -Werror=format-security -D_FILE_OFFSET_BITS=64 -Wdate-time -D_FORTIFY_SOURCE=2)(18:native_c_libraries4:-lm )(18:native_pack_linker26:x86_64-linux-gnu-ld -r -o )(13:ocamlc_cflags165:-O2 -fno-strict-aliasing -fwrapv -pthread -fPIC -g -O2 -ffile-prefix-map=/build/ocaml-SC7b9w/ocaml-4.13.1=. -fstack-protector-strong -Wformat -Werror=format-security)(15:ocamlc_cppflags54:-D_FILE_OFFSET_BITS=64 -Wdate-time -D_FORTIFY_SOURCE=2)(15:ocamlopt_cflags165:-O2 -fno-strict-aliasing -fwrapv -pthread -fPIC -g -O2 -ffile-prefix-map=/build/ocaml-SC7b9w/ocaml-4.13.1=. -fstack-protector-strong -Wformat -Werror=format-security)(17:ocamlopt_cppflags54:-D_FILE_OFFSET_BITS=64 -Wdate-time -D_FORTIFY_SOURCE=2)(7:os_type4:Unix)(6:ranlib23:x86_64-linux-gnu-ranlib)(11:safe_string4:true)(16:standard_library14:/usr/lib/ocaml)(24:standard_library_default14:/usr/lib/ocaml)(25:supports_shared_libraries4:true)(6:system5:linux)(19:systhread_supported4:true)(6:target19:x86_64-pc-linux-gnu)(7:version6:4.13.1)(15:windows_unicode5:false)(19:with_frame_pointers5:false)(9:word_size2:64)))) \ No newline at end of file diff --git a/ass2/SICocaml/SICXE/_build/default/META.SICXE b/ass2/SICocaml/SICXE/_build/default/META.SICXE new file mode 100644 index 0000000..e69de29 diff --git a/ass2/SICocaml/SICXE/_build/default/SICXE.dune-package b/ass2/SICocaml/SICXE/_build/default/SICXE.dune-package new file mode 100644 index 0000000..222b651 --- /dev/null +++ b/ass2/SICocaml/SICXE/_build/default/SICXE.dune-package @@ -0,0 +1,4 @@ +(lang dune 3.20) +(name SICXE) +(sections (lib .) (bin ../../bin)) +(files (lib (META dune-package opam)) (bin (SICXE))) diff --git a/ass2/SICocaml/SICXE/_build/default/SICXE.opam b/ass2/SICocaml/SICXE/_build/default/SICXE.opam new file mode 100644 index 0000000..a43bbcb --- /dev/null +++ b/ass2/SICocaml/SICXE/_build/default/SICXE.opam @@ -0,0 +1,32 @@ +# This file is generated by dune, edit dune-project instead +opam-version: "2.0" +synopsis: "A short synopsis" +description: "A longer description" +maintainer: ["Maintainer Name "] +authors: ["Author Name "] +license: "LICENSE" +tags: ["add topics" "to describe" "your" "project"] +homepage: "https://github.com/username/reponame" +doc: "https://url/to/documentation" +bug-reports: "https://github.com/username/reponame/issues" +depends: [ + "dune" {>= "3.20"} + "ocaml" + "odoc" {with-doc} +] +build: [ + ["dune" "subst"] {dev} + [ + "dune" + "build" + "-p" + name + "-j" + jobs + "@install" + "@runtest" {with-test} + "@doc" {with-doc} + ] +] +dev-repo: "git+https://github.com/username/reponame.git" +x-maintenance-intent: ["(latest)"] diff --git a/ass2/SICocaml/SICXE/_build/default/bin/.merlin-conf/exe-main b/ass2/SICocaml/SICXE/_build/default/bin/.merlin-conf/exe-main new file mode 100644 index 0000000..fd1b4d3 Binary files /dev/null and b/ass2/SICocaml/SICXE/_build/default/bin/.merlin-conf/exe-main differ diff --git a/ass2/SICocaml/SICXE/_build/default/bin/main.ml b/ass2/SICocaml/SICXE/_build/default/bin/main.ml new file mode 100644 index 0000000..7bf6048 --- /dev/null +++ b/ass2/SICocaml/SICXE/_build/default/bin/main.ml @@ -0,0 +1 @@ +let () = print_endline "Hello, World!" diff --git a/ass2/SICocaml/SICXE/_build/default/bin/main.mli b/ass2/SICocaml/SICXE/_build/default/bin/main.mli new file mode 100644 index 0000000..335ae1f --- /dev/null +++ b/ass2/SICocaml/SICXE/_build/default/bin/main.mli @@ -0,0 +1 @@ +(* Auto-generated by Dune *) \ No newline at end of file diff --git a/ass2/SICocaml/SICXE/_build/default/lib/.SICXE.objs/byte/sICXE.cmi b/ass2/SICocaml/SICXE/_build/default/lib/.SICXE.objs/byte/sICXE.cmi new file mode 100644 index 0000000..cdbf023 Binary files /dev/null and b/ass2/SICocaml/SICXE/_build/default/lib/.SICXE.objs/byte/sICXE.cmi differ diff --git a/ass2/SICocaml/SICXE/_build/default/lib/.SICXE.objs/byte/sICXE.cmo b/ass2/SICocaml/SICXE/_build/default/lib/.SICXE.objs/byte/sICXE.cmo new file mode 100644 index 0000000..79df2e0 Binary files /dev/null and b/ass2/SICocaml/SICXE/_build/default/lib/.SICXE.objs/byte/sICXE.cmo differ diff --git a/ass2/SICocaml/SICXE/_build/default/lib/.SICXE.objs/byte/sICXE.cmt b/ass2/SICocaml/SICXE/_build/default/lib/.SICXE.objs/byte/sICXE.cmt new file mode 100644 index 0000000..56bff20 Binary files /dev/null and b/ass2/SICocaml/SICXE/_build/default/lib/.SICXE.objs/byte/sICXE.cmt differ diff --git a/ass2/SICocaml/SICXE/_build/default/lib/.SICXE.objs/byte/sICXE__Decoder.cmi b/ass2/SICocaml/SICXE/_build/default/lib/.SICXE.objs/byte/sICXE__Decoder.cmi new file mode 100644 index 0000000..8d272c6 Binary files /dev/null and b/ass2/SICocaml/SICXE/_build/default/lib/.SICXE.objs/byte/sICXE__Decoder.cmi differ diff --git a/ass2/SICocaml/SICXE/_build/default/lib/.SICXE.objs/byte/sICXE__Decoder.cmo b/ass2/SICocaml/SICXE/_build/default/lib/.SICXE.objs/byte/sICXE__Decoder.cmo new file mode 100644 index 0000000..27592f3 Binary files /dev/null and b/ass2/SICocaml/SICXE/_build/default/lib/.SICXE.objs/byte/sICXE__Decoder.cmo differ diff --git a/ass2/SICocaml/SICXE/_build/default/lib/.SICXE.objs/byte/sICXE__Decoder.cmt b/ass2/SICocaml/SICXE/_build/default/lib/.SICXE.objs/byte/sICXE__Decoder.cmt new file mode 100644 index 0000000..a536bc4 Binary files /dev/null and b/ass2/SICocaml/SICXE/_build/default/lib/.SICXE.objs/byte/sICXE__Decoder.cmt differ diff --git a/ass2/SICocaml/SICXE/_build/default/lib/.SICXE.objs/byte/sICXE__Izvajalnik.cmi b/ass2/SICocaml/SICXE/_build/default/lib/.SICXE.objs/byte/sICXE__Izvajalnik.cmi new file mode 100644 index 0000000..e2fa06e Binary files /dev/null and b/ass2/SICocaml/SICXE/_build/default/lib/.SICXE.objs/byte/sICXE__Izvajalnik.cmi differ diff --git a/ass2/SICocaml/SICXE/_build/default/lib/.SICXE.objs/byte/sICXE__Izvajalnik.cmt b/ass2/SICocaml/SICXE/_build/default/lib/.SICXE.objs/byte/sICXE__Izvajalnik.cmt new file mode 100644 index 0000000..4e31218 Binary files /dev/null and b/ass2/SICocaml/SICXE/_build/default/lib/.SICXE.objs/byte/sICXE__Izvajalnik.cmt differ diff --git a/ass2/SICocaml/SICXE/_build/default/lib/.SICXE.objs/byte/sICXE__OpcodeTable.cmi b/ass2/SICocaml/SICXE/_build/default/lib/.SICXE.objs/byte/sICXE__OpcodeTable.cmi new file mode 100644 index 0000000..c29fff5 Binary files /dev/null and b/ass2/SICocaml/SICXE/_build/default/lib/.SICXE.objs/byte/sICXE__OpcodeTable.cmi differ diff --git a/ass2/SICocaml/SICXE/_build/default/lib/.SICXE.objs/byte/sICXE__OpcodeTable.cmo b/ass2/SICocaml/SICXE/_build/default/lib/.SICXE.objs/byte/sICXE__OpcodeTable.cmo new file mode 100644 index 0000000..0be3155 Binary files /dev/null and b/ass2/SICocaml/SICXE/_build/default/lib/.SICXE.objs/byte/sICXE__OpcodeTable.cmo differ diff --git a/ass2/SICocaml/SICXE/_build/default/lib/.SICXE.objs/byte/sICXE__OpcodeTable.cmt b/ass2/SICocaml/SICXE/_build/default/lib/.SICXE.objs/byte/sICXE__OpcodeTable.cmt new file mode 100644 index 0000000..71861c4 Binary files /dev/null and b/ass2/SICocaml/SICXE/_build/default/lib/.SICXE.objs/byte/sICXE__OpcodeTable.cmt differ diff --git a/ass2/SICocaml/SICXE/_build/default/lib/.SICXE.objs/native/sICXE.cmx b/ass2/SICocaml/SICXE/_build/default/lib/.SICXE.objs/native/sICXE.cmx new file mode 100644 index 0000000..2f431f0 Binary files /dev/null and b/ass2/SICocaml/SICXE/_build/default/lib/.SICXE.objs/native/sICXE.cmx differ diff --git a/ass2/SICocaml/SICXE/_build/default/lib/.SICXE.objs/native/sICXE.o b/ass2/SICocaml/SICXE/_build/default/lib/.SICXE.objs/native/sICXE.o new file mode 100644 index 0000000..4446fe7 Binary files /dev/null and b/ass2/SICocaml/SICXE/_build/default/lib/.SICXE.objs/native/sICXE.o differ diff --git a/ass2/SICocaml/SICXE/_build/default/lib/.SICXE.objs/native/sICXE__Decoder.cmx b/ass2/SICocaml/SICXE/_build/default/lib/.SICXE.objs/native/sICXE__Decoder.cmx new file mode 100644 index 0000000..e127514 Binary files /dev/null and b/ass2/SICocaml/SICXE/_build/default/lib/.SICXE.objs/native/sICXE__Decoder.cmx differ diff --git a/ass2/SICocaml/SICXE/_build/default/lib/.SICXE.objs/native/sICXE__Decoder.o b/ass2/SICocaml/SICXE/_build/default/lib/.SICXE.objs/native/sICXE__Decoder.o new file mode 100644 index 0000000..22936fd Binary files /dev/null and b/ass2/SICocaml/SICXE/_build/default/lib/.SICXE.objs/native/sICXE__Decoder.o differ diff --git a/ass2/SICocaml/SICXE/_build/default/lib/.SICXE.objs/native/sICXE__OpcodeTable.cmx b/ass2/SICocaml/SICXE/_build/default/lib/.SICXE.objs/native/sICXE__OpcodeTable.cmx new file mode 100644 index 0000000..20fed4e Binary files /dev/null and b/ass2/SICocaml/SICXE/_build/default/lib/.SICXE.objs/native/sICXE__OpcodeTable.cmx differ diff --git a/ass2/SICocaml/SICXE/_build/default/lib/.SICXE.objs/native/sICXE__OpcodeTable.o b/ass2/SICocaml/SICXE/_build/default/lib/.SICXE.objs/native/sICXE__OpcodeTable.o new file mode 100644 index 0000000..3df9bf1 Binary files /dev/null and b/ass2/SICocaml/SICXE/_build/default/lib/.SICXE.objs/native/sICXE__OpcodeTable.o differ diff --git a/ass2/SICocaml/SICXE/_build/default/lib/.SICXE.objs/sICXE__Decoder.impl.all-deps b/ass2/SICocaml/SICXE/_build/default/lib/.SICXE.objs/sICXE__Decoder.impl.all-deps new file mode 100644 index 0000000..3f72c8d --- /dev/null +++ b/ass2/SICocaml/SICXE/_build/default/lib/.SICXE.objs/sICXE__Decoder.impl.all-deps @@ -0,0 +1 @@ +sICXE__OpcodeTable diff --git a/ass2/SICocaml/SICXE/_build/default/lib/.SICXE.objs/sICXE__Decoder.impl.d b/ass2/SICocaml/SICXE/_build/default/lib/.SICXE.objs/sICXE__Decoder.impl.d new file mode 100644 index 0000000..9986791 --- /dev/null +++ b/ass2/SICocaml/SICXE/_build/default/lib/.SICXE.objs/sICXE__Decoder.impl.d @@ -0,0 +1 @@ +lib/decoder.ml: Char Hashtbl OpcodeTable diff --git a/ass2/SICocaml/SICXE/_build/default/lib/.SICXE.objs/sICXE__Izvajalnik.impl.all-deps b/ass2/SICocaml/SICXE/_build/default/lib/.SICXE.objs/sICXE__Izvajalnik.impl.all-deps new file mode 100644 index 0000000..530b8ce --- /dev/null +++ b/ass2/SICocaml/SICXE/_build/default/lib/.SICXE.objs/sICXE__Izvajalnik.impl.all-deps @@ -0,0 +1,2 @@ +sICXE__Decoder +sICXE__OpcodeTable diff --git a/ass2/SICocaml/SICXE/_build/default/lib/.SICXE.objs/sICXE__Izvajalnik.impl.d b/ass2/SICocaml/SICXE/_build/default/lib/.SICXE.objs/sICXE__Izvajalnik.impl.d new file mode 100644 index 0000000..4f810dc --- /dev/null +++ b/ass2/SICocaml/SICXE/_build/default/lib/.SICXE.objs/sICXE__Izvajalnik.impl.d @@ -0,0 +1 @@ +lib/izvajalnik.ml: Bytes Char Decoder OpcodeTable Printf diff --git a/ass2/SICocaml/SICXE/_build/default/lib/.SICXE.objs/sICXE__OpcodeTable.impl.all-deps b/ass2/SICocaml/SICXE/_build/default/lib/.SICXE.objs/sICXE__OpcodeTable.impl.all-deps new file mode 100644 index 0000000..e69de29 diff --git a/ass2/SICocaml/SICXE/_build/default/lib/.SICXE.objs/sICXE__OpcodeTable.impl.d b/ass2/SICocaml/SICXE/_build/default/lib/.SICXE.objs/sICXE__OpcodeTable.impl.d new file mode 100644 index 0000000..d061633 --- /dev/null +++ b/ass2/SICocaml/SICXE/_build/default/lib/.SICXE.objs/sICXE__OpcodeTable.impl.d @@ -0,0 +1 @@ +lib/opcodeTable.ml: Hashtbl diff --git a/ass2/SICocaml/SICXE/_build/default/lib/.merlin-conf/lib-SICXE b/ass2/SICocaml/SICXE/_build/default/lib/.merlin-conf/lib-SICXE new file mode 100644 index 0000000..a5e9c8b Binary files /dev/null and b/ass2/SICocaml/SICXE/_build/default/lib/.merlin-conf/lib-SICXE differ diff --git a/ass2/SICocaml/SICXE/_build/default/lib/decoder.ml b/ass2/SICocaml/SICXE/_build/default/lib/decoder.ml new file mode 100644 index 0000000..7955cc3 --- /dev/null +++ b/ass2/SICocaml/SICXE/_build/default/lib/decoder.ml @@ -0,0 +1,10 @@ +(*decoderjeva naloga je pridobiti mnemonic in tip ukaza iz prvega byta z pogledom v hash-table*) +let table = OpcodeTable.table + +let decoder (byte1 : char) : OpcodeTable.info = + let opcode = (Char.code byte1) land 0xFC in + try + Hashtbl.find OpcodeTable.table opcode + with + | Not_found -> failwith "invalid opcode" + diff --git a/ass2/SICocaml/SICXE/_build/default/lib/izvajalnik.ml b/ass2/SICocaml/SICXE/_build/default/lib/izvajalnik.ml new file mode 100644 index 0000000..fb27223 --- /dev/null +++ b/ass2/SICocaml/SICXE/_build/default/lib/izvajalnik.ml @@ -0,0 +1,228 @@ +type registers = { + mutable a : int; + mutable x : int; + mutable l : int; + mutable b : int; + mutable s : int; + mutable t : int; + mutable f : int; + mutable pc : int; + mutable sw : int +} +(*tip state predstavlja stanje SIC/XE, z pomnilnikom in registri*) +type state = { + regs : registers; + memory : Bytes.t +} + +type nixbpe = { + n : int; + i : int; + x : int; + b : int; + p : int; + e : int +} + +(*kreiramo začetno stanje*) +let regs = {a = 0; x = 0; l = 0; b = 0; s = 0; t = 0; f = 0; pc = 0; sw = 0} +let memSize = 1 lsl 20 (*2^20*) +let memory = Bytes.make memSize '\x00' (*mutbale kos pomnilnika velikosti memSize*) +let state = {regs; memory} + + +(*----Funkcije izvajalnika----*) +(*TODO - brali bomo vedno relativno od začetka instrukcije, PC bomo na koncu ukaza povečali za pravo velikost!*) + +(*funkcije za javljanje napak*) +let notImplemented (mnemonic : string) = Printf.printf "mnemonic %s is not implemented!\n" mnemonic +let invalidOpcode (opcode : int) = Printf.printf "opcode %d is invalid!\n" opcode +let invalidAdressing () = Printf.printf "invalid adressing!\n" + +(*beri in povisaj PC*) +let fetch (state : state) : char = + let byte = Bytes.get state.memory state.regs.pc in + state.regs.pc <- state.regs.pc + 1; + byte + + (*beri za offset in ne povecaj PC*) +let readMem (state : state) (offset : int) : char = + Bytes.get state.memory (state.regs.pc + offset) + + +(*beri drugi byte ukaza formata 2 in vrni r1 in r2, kot int njunih vrednosti (reg a -> 1, reg x -> 2 ...)*) +let readR1R2 (state : state) : (int * int) = + let byte2 = Char.code (readMem state 1) in + let highNibble = (byte2 land 0xF0) lsr 4 in (*pridobi prvi nibble*) + let lowNibble = byte2 land 0x0F in (*pridobi drugi nibble*) + (highNibble, lowNibble) + +(*preberi byta 1 in 2 in dobi nixbpe bite*) +let getNIXBPE (state : state) : nixbpe = + let byte1 = Char.code (readMem state 0) in + let byte2 = Char.code (readMem state 1) in + {n = (byte1 lsr 1) land 1; + i = byte1 land 1; + x = (byte2 lsr 7) land 1; + b = (byte2 lsr 6) land 1; + p = (byte2 lsr 5) land 1; + e = (byte2 lsr 4) land 1;} + + +let getAddress (state : state) : int = + 42 + + +(*execute format 1*) +let executeFormat1 (state : state) (mnemonic : OpcodeTable.mnemonic) : unit = + match mnemonic with + | FIX -> notImplemented "FIX" + | FLOAT -> notImplemented "FLOAT" + | HIO -> notImplemented "HIO" + | NORM -> notImplemented "NORM" + | SIO -> notImplemented "SIO" + | TIO -> notImplemented "TIO" + |_ -> failwith ("Mnemonic" ^ (OpcodeTable.string_of_mnemonic mnemonic) ^ "falsely flaged as format 1") + + + +(*execute format 2*) +let executeFormat2 (state: state) (mnemonic : OpcodeTable.mnemonic) : unit = + let (r1, r2) = readR1R2 state in + match mnemonic with + | ADDR -> notImplemented "ADD" (*when implemented: -> add state r1 r2*) + | CLEAR -> notImplemented "CLEAR" + | COMPR -> notImplemented "F2" + | DIVR -> notImplemented "F2" + | MULR -> notImplemented "F2" + | RMO -> notImplemented "F2" + | SHIFTL -> notImplemented "F2" + | SHIFTR -> notImplemented "F2" + | SUBR -> notImplemented "F2" + | SVC -> notImplemented "F2" + | TIXR -> notImplemented "F2" + |_ -> failwith ("Mnemonic" ^ (OpcodeTable.string_of_mnemonic mnemonic) ^ "falsely flaged as format 2") + + +(*execute Format 3*) +let executeFormat3 (state : state) (nixbpe : nixbpe) (mnemonic: OpcodeTable.mnemonic): unit = + let address = getAddress state in + match mnemonic with + | ADD -> notImplemented "ADD3" + | ADDF -> notImplemented "ADDF4" + | AND -> notImplemented "AND4" + | COMP -> notImplemented "COMP4" + | COMPF -> notImplemented "COMPF4" + | DIV -> notImplemented "DIV4" + | MUL -> notImplemented "MUL4" + | OR -> notImplemented "OR4" + | SUB -> notImplemented "SUB4" + | SUBF -> notImplemented "SUBF4" + | TD -> notImplemented "TD4" + | WD -> notImplemented "WD4" + + (* Jump / subroutine *) + | J -> notImplemented "J4" + | JEQ -> notImplemented "JEQ4" + | JGT -> notImplemented "JGT4" + | JLT -> notImplemented "JLT4" + | JSUB -> notImplemented "JSUB4" + | RSUB -> notImplemented "RSUB4" + + (* Load/store *) + | LDA -> notImplemented "LDA4" + | LDB -> notImplemented "LDB4" + | LDCH -> notImplemented "LDCH4" + | LDF -> notImplemented "LDF4" + | LDL -> notImplemented "LDL4" + | LDS -> notImplemented "LDS4" + | LDT -> notImplemented "LDT4" + | LDX -> notImplemented "LDX4" + | LPS -> notImplemented "LPS4" + | STA -> notImplemented "STA4" + | STB -> notImplemented "STB4" + | STCH -> notImplemented "STCH4" + | STF -> notImplemented "STF4" + | STL -> notImplemented "STL4" + | STS -> notImplemented "STS4" + | STSW -> notImplemented "STSW4" + | STT -> notImplemented "STT4" + | STX -> notImplemented "STX4" + + (* Control / IO *) + | TIX -> notImplemented "TIX4" + |_ -> failwith ("Mnemonic" ^ (OpcodeTable.string_of_mnemonic mnemonic) ^ "falsely flaged as format 3") + + +let executeFormat4 (state : state) (nixbpe : nixbpe) (mnemonic: OpcodeTable.mnemonic): unit = + let address = getAddress state in + match mnemonic with + (*aritmetika*) + | ADD -> notImplemented "ADD4" + | ADDF -> notImplemented "ADDF4" + | AND -> notImplemented "AND4" + | COMP -> notImplemented "COMP4" + | COMPF -> notImplemented "COMPF4" + | DIV -> notImplemented "DIV4" + | MUL -> notImplemented "MUL4" + | OR -> notImplemented "OR4" + | SUB -> notImplemented "SUB4" + | SUBF -> notImplemented "SUBF4" + | TD -> notImplemented "TD4" + | WD -> notImplemented "WD4" + + (* Jump / subroutine *) + | J -> notImplemented "J4" + | JEQ -> notImplemented "JEQ4" + | JGT -> notImplemented "JGT4" + | JLT -> notImplemented "JLT4" + | JSUB -> notImplemented "JSUB4" + | RSUB -> notImplemented "RSUB4" + + (* Load/store *) + | LDA -> notImplemented "LDA4" + | LDB -> notImplemented "LDB4" + | LDCH -> notImplemented "LDCH4" + | LDF -> notImplemented "LDF4" + | LDL -> notImplemented "LDL4" + | LDS -> notImplemented "LDS4" + | LDT -> notImplemented "LDT4" + | LDX -> notImplemented "LDX4" + | LPS -> notImplemented "LPS4" + | STA -> notImplemented "STA4" + | STB -> notImplemented "STB4" + | STCH -> notImplemented "STCH4" + | STF -> notImplemented "STF4" + | STL -> notImplemented "STL4" + | STS -> notImplemented "STS4" + | STSW -> notImplemented "STSW4" + | STT -> notImplemented "STT4" + | STX -> notImplemented "STX4" + + (* Control / IO *) + | TIX -> notImplemented "TIX4" + |_ -> failwith ("Mnemonic" ^ (OpcodeTable.string_of_mnemonic mnemonic) ^ "falsely flaged as format 4") + + + + +(*execute format 3_4*) +let executeFormat3_4 (state : state) (mnemonic : OpcodeTable.mnemonic) : unit = + let nixbpe = getNIXBPE state in + match nixbpe.e with + | 0 -> executeFormat3 state nixbpe mnemonic + | 1 -> executeFormat4 state nixbpe mnemonic + | _ -> failwith "invalid computation of nxbpe" + + +(*execute ukaza*) +let execute (state : state) : unit = + let byte1 = readMem state 0 in (*read the 1st byte of the instruction*) + try + let {OpcodeTable.mnemonic; OpcodeTable.format} = Decoder.decoder byte1 in (*determen the format of the instruction from the 1st byte*) + match format with + | F1 -> executeFormat1 state mnemonic + | F2 -> executeFormat2 state mnemonic + | F3_4 -> executeFormat3_4 state mnemonic + with + | Failure msg -> byte1 |> Char.code |> invalidOpcode \ No newline at end of file diff --git a/ass2/SICocaml/SICXE/_build/default/lib/opcodeTable.ml b/ass2/SICocaml/SICXE/_build/default/lib/opcodeTable.ml new file mode 100644 index 0000000..4c4544c --- /dev/null +++ b/ass2/SICocaml/SICXE/_build/default/lib/opcodeTable.ml @@ -0,0 +1,159 @@ +(*opcode hash table, formati ukazov in mnemoniki*) +type mnemonic = + (* Format 1 *) + | FIX | FLOAT | HIO | NORM | SIO | TIO + + (* Format 2 *) + | ADDR | CLEAR | COMPR | DIVR | MULR | RMO + | SHIFTL | SHIFTR | SUBR | SVC | TIXR + + (* Format 3/4 *) + | ADD | ADDF | AND | COMP | COMPF | DIV + | J | JEQ | JGT | JLT | JSUB | LDA | LDB | LDCH | LDF + | LDL | LDS | LDT | LDX | LPS | MUL | OR | RD + | RSUB | STA | STB | STCH | STF | STL | STS | STSW + | STT | STX | SUB | SUBF | TD | TIX | WD + +type format = + | F1 + | F2 + | F3_4 + +type info = { + mnemonic : mnemonic; + format : format; +} + +(* Opcode table *) + +let table : (int, info) Hashtbl.t = Hashtbl.create 128 + +let () = + let add op mnemonic format = + Hashtbl.add table op { mnemonic; format } + in + + (*Format 1 Instructions*) + add 0xC4 FIX F1; + add 0xC0 FLOAT F1; + add 0xC8 HIO F1; + add 0xC1 NORM F1; + add 0xF0 SIO F1; + add 0xF8 TIO F1; + + (*Format 2 Instructions*) + add 0x90 ADDR F2; + add 0xB4 CLEAR F2; + add 0xA0 COMPR F2; + add 0x9C DIVR F2; + add 0x98 MULR F2; + add 0xAC RMO F2; + add 0xA4 SHIFTL F2; + add 0xA8 SHIFTR F2; + add 0x94 SUBR F2; + add 0xB0 SVC F2; + add 0xB8 TIXR F2; + + (*Format 3/4 Instructions*) + add 0x18 ADD F3_4; + add 0x58 ADDF F3_4; + add 0x40 AND F3_4; + add 0x28 COMP F3_4; + add 0x88 COMPF F3_4; + add 0x24 DIV F3_4; + add 0x3C J F3_4; + add 0x30 JEQ F3_4; + add 0x34 JGT F3_4; + add 0x38 JLT F3_4; + add 0x48 JSUB F3_4; + add 0x00 LDA F3_4; + add 0x68 LDB F3_4; + add 0x50 LDCH F3_4; + add 0x70 LDF F3_4; + add 0x08 LDL F3_4; + add 0x6C LDS F3_4; + add 0x74 LDT F3_4; + add 0x04 LDX F3_4; + add 0xD0 LPS F3_4; + add 0x20 MUL F3_4; + add 0x44 OR F3_4; + add 0xD8 RD F3_4; + add 0x4C RSUB F3_4; + add 0x0C STA F3_4; + add 0x78 STB F3_4; + add 0x54 STCH F3_4; + add 0x80 STF F3_4; + add 0x14 STL F3_4; + add 0x7C STS F3_4; + add 0xE8 STSW F3_4; + add 0x84 STT F3_4; + add 0x10 STX F3_4; + add 0x1C SUB F3_4; + add 0x5C SUBF F3_4; + add 0xE0 TD F3_4; + add 0x2C TIX F3_4; + add 0xDC WD F3_4; +() + +(*mnemonic to string*) +let string_of_mnemonic = function + (* Format 1 *) + | FIX -> "FIX" + | FLOAT -> "FLOAT" + | HIO -> "HIO" + | NORM -> "NORM" + | SIO -> "SIO" + | TIO -> "TIO" + + (* Format 2 *) + | ADDR -> "ADDR" + | CLEAR -> "CLEAR" + | COMPR -> "COMPR" + | DIVR -> "DIVR" + | MULR -> "MULR" + | RMO -> "RMO" + | SHIFTL -> "SHIFTL" + | SHIFTR -> "SHIFTR" + | SUBR -> "SUBR" + | SVC -> "SVC" + | TIXR -> "TIXR" + + (* Format 3/4 *) + | ADD -> "ADD" + | ADDF -> "ADDF" + | AND -> "AND" + | COMP -> "COMP" + | COMPF -> "COMPF" + | DIV -> "DIV" + | J -> "J" + | JEQ -> "JEQ" + | JGT -> "JGT" + | JLT -> "JLT" + | JSUB -> "JSUB" + | LDA -> "LDA" + | LDB -> "LDB" + | LDCH -> "LDCH" + | LDF -> "LDF" + | LDL -> "LDL" + | LDS -> "LDS" + | LDT -> "LDT" + | LDX -> "LDX" + | LPS -> "LPS" + | MUL -> "MUL" + | OR -> "OR" + | RD -> "RD" + | RSUB -> "RSUB" + | STA -> "STA" + | STB -> "STB" + | STCH -> "STCH" + | STF -> "STF" + | STL -> "STL" + | STS -> "STS" + | STSW -> "STSW" + | STT -> "STT" + | STX -> "STX" + | SUB -> "SUB" + | SUBF -> "SUBF" + | TD -> "TD" + | TIX -> "TIX" + | WD -> "WD" diff --git a/ass2/SICocaml/SICXE/_build/default/lib/sICXE.ml-gen b/ass2/SICocaml/SICXE/_build/default/lib/sICXE.ml-gen new file mode 100644 index 0000000..adb1617 --- /dev/null +++ b/ass2/SICocaml/SICXE/_build/default/lib/sICXE.ml-gen @@ -0,0 +1,10 @@ +(* generated by dune *) + +(** @canonical SICXE.Decoder *) +module Decoder = SICXE__Decoder + +(** @canonical SICXE.Izvajalnik *) +module Izvajalnik = SICXE__Izvajalnik + +(** @canonical SICXE.OpcodeTable *) +module OpcodeTable = SICXE__OpcodeTable diff --git a/ass2/SICocaml/SICXE/_build/default/test/.merlin-conf/exe-test_SICXE b/ass2/SICocaml/SICXE/_build/default/test/.merlin-conf/exe-test_SICXE new file mode 100644 index 0000000..704e488 Binary files /dev/null and b/ass2/SICocaml/SICXE/_build/default/test/.merlin-conf/exe-test_SICXE differ diff --git a/ass2/SICocaml/SICXE/_build/default/test/.test_SICXE.eobjs/byte/dune__exe__Test_SICXE.cmi b/ass2/SICocaml/SICXE/_build/default/test/.test_SICXE.eobjs/byte/dune__exe__Test_SICXE.cmi new file mode 100644 index 0000000..2313f36 Binary files /dev/null and b/ass2/SICocaml/SICXE/_build/default/test/.test_SICXE.eobjs/byte/dune__exe__Test_SICXE.cmi differ diff --git a/ass2/SICocaml/SICXE/_build/default/test/.test_SICXE.eobjs/byte/dune__exe__Test_SICXE.cmti b/ass2/SICocaml/SICXE/_build/default/test/.test_SICXE.eobjs/byte/dune__exe__Test_SICXE.cmti new file mode 100644 index 0000000..72fb912 Binary files /dev/null and b/ass2/SICocaml/SICXE/_build/default/test/.test_SICXE.eobjs/byte/dune__exe__Test_SICXE.cmti differ diff --git a/ass2/SICocaml/SICXE/_build/default/test/.test_SICXE.eobjs/native/dune__exe__Test_SICXE.cmx b/ass2/SICocaml/SICXE/_build/default/test/.test_SICXE.eobjs/native/dune__exe__Test_SICXE.cmx new file mode 100644 index 0000000..cfd0396 Binary files /dev/null and b/ass2/SICocaml/SICXE/_build/default/test/.test_SICXE.eobjs/native/dune__exe__Test_SICXE.cmx differ diff --git a/ass2/SICocaml/SICXE/_build/default/test/.test_SICXE.eobjs/native/dune__exe__Test_SICXE.o b/ass2/SICocaml/SICXE/_build/default/test/.test_SICXE.eobjs/native/dune__exe__Test_SICXE.o new file mode 100644 index 0000000..a20e89f Binary files /dev/null and b/ass2/SICocaml/SICXE/_build/default/test/.test_SICXE.eobjs/native/dune__exe__Test_SICXE.o differ diff --git a/ass2/SICocaml/SICXE/_build/default/test/test_SICXE.exe b/ass2/SICocaml/SICXE/_build/default/test/test_SICXE.exe new file mode 100644 index 0000000..2b21f3e Binary files /dev/null and b/ass2/SICocaml/SICXE/_build/default/test/test_SICXE.exe differ diff --git a/ass2/SICocaml/SICXE/_build/default/test/test_SICXE.ml b/ass2/SICocaml/SICXE/_build/default/test/test_SICXE.ml new file mode 100644 index 0000000..e69de29 diff --git a/ass2/SICocaml/SICXE/_build/default/test/test_SICXE.mli b/ass2/SICocaml/SICXE/_build/default/test/test_SICXE.mli new file mode 100644 index 0000000..335ae1f --- /dev/null +++ b/ass2/SICocaml/SICXE/_build/default/test/test_SICXE.mli @@ -0,0 +1 @@ +(* Auto-generated by Dune *) \ No newline at end of file diff --git a/ass2/SICocaml/SICXE/_build/install/default/lib/SICXE/META b/ass2/SICocaml/SICXE/_build/install/default/lib/SICXE/META new file mode 120000 index 0000000..908d008 --- /dev/null +++ b/ass2/SICocaml/SICXE/_build/install/default/lib/SICXE/META @@ -0,0 +1 @@ +../../../../default/META.SICXE \ No newline at end of file diff --git a/ass2/SICocaml/SICXE/_build/install/default/lib/SICXE/dune-package b/ass2/SICocaml/SICXE/_build/install/default/lib/SICXE/dune-package new file mode 120000 index 0000000..ea1386e --- /dev/null +++ b/ass2/SICocaml/SICXE/_build/install/default/lib/SICXE/dune-package @@ -0,0 +1 @@ +../../../../default/SICXE.dune-package \ No newline at end of file diff --git a/ass2/SICocaml/SICXE/_build/install/default/lib/SICXE/opam b/ass2/SICocaml/SICXE/_build/install/default/lib/SICXE/opam new file mode 120000 index 0000000..e4d474a --- /dev/null +++ b/ass2/SICocaml/SICXE/_build/install/default/lib/SICXE/opam @@ -0,0 +1 @@ +../../../../default/SICXE.opam \ No newline at end of file diff --git a/ass2/SICocaml/SICXE/_build/log b/ass2/SICocaml/SICXE/_build/log new file mode 100644 index 0000000..449f978 --- /dev/null +++ b/ass2/SICocaml/SICXE/_build/log @@ -0,0 +1,67 @@ +# dune build +# OCAMLPARAM: unset +# Shared cache: enabled-except-user-rules +# Shared cache location: /home/jaka/.cache/dune/db +# Workspace root: /mnt/c/Programiranje/SPO/ass2/SICocaml/SICXE +# Auto-detected concurrency: 16 +# Dune context: +# { name = "default" +# ; kind = "default" +# ; profile = Dev +# ; merlin = true +# ; fdo_target_exe = None +# ; build_dir = In_build_dir "default" +# ; instrument_with = [] +# } +$ /usr/bin/ocamlc.opt -config > /tmp/dune_71502d_output +# Promoting "_build/default/SICXE.opam" to "SICXE.opam" +$ (cd _build/default && /usr/bin/ocamlc.opt -w @1..3@5..28@31..39@43@46..47@49..57@61..62@67@69-40 -strict-sequence -strict-formats -short-paths -keep-locs -w -49 -nopervasives -nostdlib -g -bin-annot -I lib/.SICXE.objs/byte -no-alias-deps -opaque -o lib/.SICXE.objs/byte/sICXE.cmo -c -impl lib/sICXE.ml-gen) +$ (cd _build/default && /usr/bin/ocamldep.opt -modules -impl lib/opcodeTable.ml) > _build/default/lib/.SICXE.objs/sICXE__OpcodeTable.impl.d +$ (cd _build/default && /usr/bin/ocamlopt.opt -w @1..3@5..28@31..39@43@46..47@49..57@61..62@67@69-40 -strict-sequence -strict-formats -short-paths -keep-locs -w -49 -nopervasives -nostdlib -g -I lib/.SICXE.objs/byte -I lib/.SICXE.objs/native -intf-suffix .ml-gen -no-alias-deps -opaque -o lib/.SICXE.objs/native/sICXE.cmx -c -impl lib/sICXE.ml-gen) +$ (cd _build/default && /usr/bin/ocamldep.opt -modules -impl lib/decoder.ml) > _build/default/lib/.SICXE.objs/sICXE__Decoder.impl.d +$ (cd _build/default && /usr/bin/ocamldep.opt -modules -impl lib/izvajalnik.ml) > _build/default/lib/.SICXE.objs/sICXE__Izvajalnik.impl.d +$ (cd _build/default && /usr/bin/ocamlc.opt -w @1..3@5..28@31..39@43@46..47@49..57@61..62@67@69-40 -strict-sequence -strict-formats -short-paths -keep-locs -g -bin-annot -I lib/.SICXE.objs/byte -no-alias-deps -opaque -open SICXE -o lib/.SICXE.objs/byte/sICXE__OpcodeTable.cmo -c -impl lib/opcodeTable.ml) +$ (cd _build/default && /usr/bin/ocamlc.opt -w @1..3@5..28@31..39@43@46..47@49..57@61..62@67@69-40 -strict-sequence -strict-formats -short-paths -keep-locs -g -bin-annot -I test/.test_SICXE.eobjs/byte -no-alias-deps -opaque -o test/.test_SICXE.eobjs/byte/dune__exe__Test_SICXE.cmi -c -intf test/test_SICXE.mli) +$ (cd _build/default && /usr/bin/ocamlc.opt -w @1..3@5..28@31..39@43@46..47@49..57@61..62@67@69-40 -strict-sequence -strict-formats -short-paths -keep-locs -g -bin-annot -I lib/.SICXE.objs/byte -no-alias-deps -opaque -open SICXE -o lib/.SICXE.objs/byte/sICXE__Decoder.cmo -c -impl lib/decoder.ml) +$ (cd _build/default && /usr/bin/ocamlopt.opt -w @1..3@5..28@31..39@43@46..47@49..57@61..62@67@69-40 -strict-sequence -strict-formats -short-paths -keep-locs -g -I lib/.SICXE.objs/byte -I lib/.SICXE.objs/native -intf-suffix .ml -no-alias-deps -opaque -open SICXE -o lib/.SICXE.objs/native/sICXE__OpcodeTable.cmx -c -impl lib/opcodeTable.ml) +$ (cd _build/default && /usr/bin/ocamlopt.opt -w @1..3@5..28@31..39@43@46..47@49..57@61..62@67@69-40 -strict-sequence -strict-formats -short-paths -keep-locs -g -I test/.test_SICXE.eobjs/byte -I test/.test_SICXE.eobjs/native -intf-suffix .ml -no-alias-deps -opaque -o test/.test_SICXE.eobjs/native/dune__exe__Test_SICXE.cmx -c -impl test/test_SICXE.ml) +$ (cd _build/default && /usr/bin/ocamlopt.opt -w @1..3@5..28@31..39@43@46..47@49..57@61..62@67@69-40 -strict-sequence -strict-formats -short-paths -keep-locs -g -I lib/.SICXE.objs/byte -I lib/.SICXE.objs/native -intf-suffix .ml -no-alias-deps -opaque -open SICXE -o lib/.SICXE.objs/native/sICXE__Decoder.cmx -c -impl lib/decoder.ml) +$ (cd _build/default && /usr/bin/ocamlc.opt -w @1..3@5..28@31..39@43@46..47@49..57@61..62@67@69-40 -strict-sequence -strict-formats -short-paths -keep-locs -g -bin-annot -I lib/.SICXE.objs/byte -no-alias-deps -opaque -open SICXE -o lib/.SICXE.objs/byte/sICXE__Izvajalnik.cmo -c -impl lib/izvajalnik.ml) +> File "lib/izvajalnik.ml", line 72, characters 16-21: +> 72 | let getAddress (state : state) : int = +> ^^^^^ +> Error (warning 27 [unused-var-strict]): unused variable state. +> File "lib/izvajalnik.ml", line 77, characters 20-25: +> 77 | let executeFormat1 (state : state) (mnemonic : OpcodeTable.mnemonic) : unit = +> ^^^^^ +> Error (warning 27 [unused-var-strict]): unused variable state. +> File "lib/izvajalnik.ml", line 91, characters 7-9: +> 91 | let (r1, r2) = readR1R2 state in +> ^^ +> Error (warning 26 [unused-var]): unused variable r1. +> File "lib/izvajalnik.ml", line 91, characters 11-13: +> 91 | let (r1, r2) = readR1R2 state in +> ^^ +> Error (warning 26 [unused-var]): unused variable r2. +> File "lib/izvajalnik.ml", line 108, characters 36-42: +> 108 | let executeFormat3 (state : state) (nixbpe : nixbpe) (mnemonic: OpcodeTable.mnemonic): unit = +> ^^^^^^ +> Error (warning 27 [unused-var-strict]): unused variable nixbpe. +> File "lib/izvajalnik.ml", line 109, characters 6-13: +> 109 | let address = getAddress state in +> ^^^^^^^ +> Error (warning 26 [unused-var]): unused variable address. +> File "lib/izvajalnik.ml", line 157, characters 36-42: +> 157 | let executeFormat4 (state : state) (nixbpe : nixbpe) (mnemonic: OpcodeTable.mnemonic): unit = +> ^^^^^^ +> Error (warning 27 [unused-var-strict]): unused variable nixbpe. +> File "lib/izvajalnik.ml", line 158, characters 6-13: +> 158 | let address = getAddress state in +> ^^^^^^^ +> Error (warning 26 [unused-var]): unused variable address. +> File "lib/izvajalnik.ml", line 228, characters 14-17: +> 228 | | Failure msg -> byte1 |> Char.code |> invalidOpcode +> ^^^ +> Error (warning 27 [unused-var-strict]): unused variable msg. +[2] +$ (cd _build/default && /usr/bin/ocamlopt.opt -w @1..3@5..28@31..39@43@46..47@49..57@61..62@67@69-40 -strict-sequence -strict-formats -short-paths -keep-locs -g -o test/test_SICXE.exe test/.test_SICXE.eobjs/native/dune__exe__Test_SICXE.cmx) diff --git a/ass2/SICocaml/SICXE/bin/dune b/ass2/SICocaml/SICXE/bin/dune new file mode 100644 index 0000000..3bed0d6 --- /dev/null +++ b/ass2/SICocaml/SICXE/bin/dune @@ -0,0 +1,4 @@ +(executable + (public_name SICXE) + (name main) + (libraries SICXE)) diff --git a/ass2/SICocaml/SICXE/bin/main.ml b/ass2/SICocaml/SICXE/bin/main.ml new file mode 100644 index 0000000..7bf6048 --- /dev/null +++ b/ass2/SICocaml/SICXE/bin/main.ml @@ -0,0 +1 @@ +let () = print_endline "Hello, World!" diff --git a/ass2/SICocaml/SICXE/dune-project b/ass2/SICocaml/SICXE/dune-project new file mode 100644 index 0000000..35c6ec0 --- /dev/null +++ b/ass2/SICocaml/SICXE/dune-project @@ -0,0 +1,26 @@ +(lang dune 3.20) + +(name SICXE) + +(generate_opam_files true) + +(source + (github username/reponame)) + +(authors "Author Name ") + +(maintainers "Maintainer Name ") + +(license LICENSE) + +(documentation https://url/to/documentation) + +(package + (name SICXE) + (synopsis "A short synopsis") + (description "A longer description") + (depends ocaml) + (tags + ("add topics" "to describe" your project))) + +; See the complete stanza docs at https://dune.readthedocs.io/en/stable/reference/dune-project/index.html diff --git a/ass2/SICocaml/SICXE/lib/decoder.ml b/ass2/SICocaml/SICXE/lib/decoder.ml new file mode 100644 index 0000000..7955cc3 --- /dev/null +++ b/ass2/SICocaml/SICXE/lib/decoder.ml @@ -0,0 +1,10 @@ +(*decoderjeva naloga je pridobiti mnemonic in tip ukaza iz prvega byta z pogledom v hash-table*) +let table = OpcodeTable.table + +let decoder (byte1 : char) : OpcodeTable.info = + let opcode = (Char.code byte1) land 0xFC in + try + Hashtbl.find OpcodeTable.table opcode + with + | Not_found -> failwith "invalid opcode" + diff --git a/ass2/SICocaml/SICXE/lib/dune b/ass2/SICocaml/SICXE/lib/dune new file mode 100644 index 0000000..6debd99 --- /dev/null +++ b/ass2/SICocaml/SICXE/lib/dune @@ -0,0 +1,2 @@ +(library + (name SICXE)) diff --git a/ass2/SICocaml/SICXE/lib/izvajalnik.ml b/ass2/SICocaml/SICXE/lib/izvajalnik.ml new file mode 100644 index 0000000..fb27223 --- /dev/null +++ b/ass2/SICocaml/SICXE/lib/izvajalnik.ml @@ -0,0 +1,228 @@ +type registers = { + mutable a : int; + mutable x : int; + mutable l : int; + mutable b : int; + mutable s : int; + mutable t : int; + mutable f : int; + mutable pc : int; + mutable sw : int +} +(*tip state predstavlja stanje SIC/XE, z pomnilnikom in registri*) +type state = { + regs : registers; + memory : Bytes.t +} + +type nixbpe = { + n : int; + i : int; + x : int; + b : int; + p : int; + e : int +} + +(*kreiramo začetno stanje*) +let regs = {a = 0; x = 0; l = 0; b = 0; s = 0; t = 0; f = 0; pc = 0; sw = 0} +let memSize = 1 lsl 20 (*2^20*) +let memory = Bytes.make memSize '\x00' (*mutbale kos pomnilnika velikosti memSize*) +let state = {regs; memory} + + +(*----Funkcije izvajalnika----*) +(*TODO - brali bomo vedno relativno od začetka instrukcije, PC bomo na koncu ukaza povečali za pravo velikost!*) + +(*funkcije za javljanje napak*) +let notImplemented (mnemonic : string) = Printf.printf "mnemonic %s is not implemented!\n" mnemonic +let invalidOpcode (opcode : int) = Printf.printf "opcode %d is invalid!\n" opcode +let invalidAdressing () = Printf.printf "invalid adressing!\n" + +(*beri in povisaj PC*) +let fetch (state : state) : char = + let byte = Bytes.get state.memory state.regs.pc in + state.regs.pc <- state.regs.pc + 1; + byte + + (*beri za offset in ne povecaj PC*) +let readMem (state : state) (offset : int) : char = + Bytes.get state.memory (state.regs.pc + offset) + + +(*beri drugi byte ukaza formata 2 in vrni r1 in r2, kot int njunih vrednosti (reg a -> 1, reg x -> 2 ...)*) +let readR1R2 (state : state) : (int * int) = + let byte2 = Char.code (readMem state 1) in + let highNibble = (byte2 land 0xF0) lsr 4 in (*pridobi prvi nibble*) + let lowNibble = byte2 land 0x0F in (*pridobi drugi nibble*) + (highNibble, lowNibble) + +(*preberi byta 1 in 2 in dobi nixbpe bite*) +let getNIXBPE (state : state) : nixbpe = + let byte1 = Char.code (readMem state 0) in + let byte2 = Char.code (readMem state 1) in + {n = (byte1 lsr 1) land 1; + i = byte1 land 1; + x = (byte2 lsr 7) land 1; + b = (byte2 lsr 6) land 1; + p = (byte2 lsr 5) land 1; + e = (byte2 lsr 4) land 1;} + + +let getAddress (state : state) : int = + 42 + + +(*execute format 1*) +let executeFormat1 (state : state) (mnemonic : OpcodeTable.mnemonic) : unit = + match mnemonic with + | FIX -> notImplemented "FIX" + | FLOAT -> notImplemented "FLOAT" + | HIO -> notImplemented "HIO" + | NORM -> notImplemented "NORM" + | SIO -> notImplemented "SIO" + | TIO -> notImplemented "TIO" + |_ -> failwith ("Mnemonic" ^ (OpcodeTable.string_of_mnemonic mnemonic) ^ "falsely flaged as format 1") + + + +(*execute format 2*) +let executeFormat2 (state: state) (mnemonic : OpcodeTable.mnemonic) : unit = + let (r1, r2) = readR1R2 state in + match mnemonic with + | ADDR -> notImplemented "ADD" (*when implemented: -> add state r1 r2*) + | CLEAR -> notImplemented "CLEAR" + | COMPR -> notImplemented "F2" + | DIVR -> notImplemented "F2" + | MULR -> notImplemented "F2" + | RMO -> notImplemented "F2" + | SHIFTL -> notImplemented "F2" + | SHIFTR -> notImplemented "F2" + | SUBR -> notImplemented "F2" + | SVC -> notImplemented "F2" + | TIXR -> notImplemented "F2" + |_ -> failwith ("Mnemonic" ^ (OpcodeTable.string_of_mnemonic mnemonic) ^ "falsely flaged as format 2") + + +(*execute Format 3*) +let executeFormat3 (state : state) (nixbpe : nixbpe) (mnemonic: OpcodeTable.mnemonic): unit = + let address = getAddress state in + match mnemonic with + | ADD -> notImplemented "ADD3" + | ADDF -> notImplemented "ADDF4" + | AND -> notImplemented "AND4" + | COMP -> notImplemented "COMP4" + | COMPF -> notImplemented "COMPF4" + | DIV -> notImplemented "DIV4" + | MUL -> notImplemented "MUL4" + | OR -> notImplemented "OR4" + | SUB -> notImplemented "SUB4" + | SUBF -> notImplemented "SUBF4" + | TD -> notImplemented "TD4" + | WD -> notImplemented "WD4" + + (* Jump / subroutine *) + | J -> notImplemented "J4" + | JEQ -> notImplemented "JEQ4" + | JGT -> notImplemented "JGT4" + | JLT -> notImplemented "JLT4" + | JSUB -> notImplemented "JSUB4" + | RSUB -> notImplemented "RSUB4" + + (* Load/store *) + | LDA -> notImplemented "LDA4" + | LDB -> notImplemented "LDB4" + | LDCH -> notImplemented "LDCH4" + | LDF -> notImplemented "LDF4" + | LDL -> notImplemented "LDL4" + | LDS -> notImplemented "LDS4" + | LDT -> notImplemented "LDT4" + | LDX -> notImplemented "LDX4" + | LPS -> notImplemented "LPS4" + | STA -> notImplemented "STA4" + | STB -> notImplemented "STB4" + | STCH -> notImplemented "STCH4" + | STF -> notImplemented "STF4" + | STL -> notImplemented "STL4" + | STS -> notImplemented "STS4" + | STSW -> notImplemented "STSW4" + | STT -> notImplemented "STT4" + | STX -> notImplemented "STX4" + + (* Control / IO *) + | TIX -> notImplemented "TIX4" + |_ -> failwith ("Mnemonic" ^ (OpcodeTable.string_of_mnemonic mnemonic) ^ "falsely flaged as format 3") + + +let executeFormat4 (state : state) (nixbpe : nixbpe) (mnemonic: OpcodeTable.mnemonic): unit = + let address = getAddress state in + match mnemonic with + (*aritmetika*) + | ADD -> notImplemented "ADD4" + | ADDF -> notImplemented "ADDF4" + | AND -> notImplemented "AND4" + | COMP -> notImplemented "COMP4" + | COMPF -> notImplemented "COMPF4" + | DIV -> notImplemented "DIV4" + | MUL -> notImplemented "MUL4" + | OR -> notImplemented "OR4" + | SUB -> notImplemented "SUB4" + | SUBF -> notImplemented "SUBF4" + | TD -> notImplemented "TD4" + | WD -> notImplemented "WD4" + + (* Jump / subroutine *) + | J -> notImplemented "J4" + | JEQ -> notImplemented "JEQ4" + | JGT -> notImplemented "JGT4" + | JLT -> notImplemented "JLT4" + | JSUB -> notImplemented "JSUB4" + | RSUB -> notImplemented "RSUB4" + + (* Load/store *) + | LDA -> notImplemented "LDA4" + | LDB -> notImplemented "LDB4" + | LDCH -> notImplemented "LDCH4" + | LDF -> notImplemented "LDF4" + | LDL -> notImplemented "LDL4" + | LDS -> notImplemented "LDS4" + | LDT -> notImplemented "LDT4" + | LDX -> notImplemented "LDX4" + | LPS -> notImplemented "LPS4" + | STA -> notImplemented "STA4" + | STB -> notImplemented "STB4" + | STCH -> notImplemented "STCH4" + | STF -> notImplemented "STF4" + | STL -> notImplemented "STL4" + | STS -> notImplemented "STS4" + | STSW -> notImplemented "STSW4" + | STT -> notImplemented "STT4" + | STX -> notImplemented "STX4" + + (* Control / IO *) + | TIX -> notImplemented "TIX4" + |_ -> failwith ("Mnemonic" ^ (OpcodeTable.string_of_mnemonic mnemonic) ^ "falsely flaged as format 4") + + + + +(*execute format 3_4*) +let executeFormat3_4 (state : state) (mnemonic : OpcodeTable.mnemonic) : unit = + let nixbpe = getNIXBPE state in + match nixbpe.e with + | 0 -> executeFormat3 state nixbpe mnemonic + | 1 -> executeFormat4 state nixbpe mnemonic + | _ -> failwith "invalid computation of nxbpe" + + +(*execute ukaza*) +let execute (state : state) : unit = + let byte1 = readMem state 0 in (*read the 1st byte of the instruction*) + try + let {OpcodeTable.mnemonic; OpcodeTable.format} = Decoder.decoder byte1 in (*determen the format of the instruction from the 1st byte*) + match format with + | F1 -> executeFormat1 state mnemonic + | F2 -> executeFormat2 state mnemonic + | F3_4 -> executeFormat3_4 state mnemonic + with + | Failure msg -> byte1 |> Char.code |> invalidOpcode \ No newline at end of file diff --git a/ass2/SICocaml/SICXE/lib/opcodeTable.ml b/ass2/SICocaml/SICXE/lib/opcodeTable.ml new file mode 100644 index 0000000..4c4544c --- /dev/null +++ b/ass2/SICocaml/SICXE/lib/opcodeTable.ml @@ -0,0 +1,159 @@ +(*opcode hash table, formati ukazov in mnemoniki*) +type mnemonic = + (* Format 1 *) + | FIX | FLOAT | HIO | NORM | SIO | TIO + + (* Format 2 *) + | ADDR | CLEAR | COMPR | DIVR | MULR | RMO + | SHIFTL | SHIFTR | SUBR | SVC | TIXR + + (* Format 3/4 *) + | ADD | ADDF | AND | COMP | COMPF | DIV + | J | JEQ | JGT | JLT | JSUB | LDA | LDB | LDCH | LDF + | LDL | LDS | LDT | LDX | LPS | MUL | OR | RD + | RSUB | STA | STB | STCH | STF | STL | STS | STSW + | STT | STX | SUB | SUBF | TD | TIX | WD + +type format = + | F1 + | F2 + | F3_4 + +type info = { + mnemonic : mnemonic; + format : format; +} + +(* Opcode table *) + +let table : (int, info) Hashtbl.t = Hashtbl.create 128 + +let () = + let add op mnemonic format = + Hashtbl.add table op { mnemonic; format } + in + + (*Format 1 Instructions*) + add 0xC4 FIX F1; + add 0xC0 FLOAT F1; + add 0xC8 HIO F1; + add 0xC1 NORM F1; + add 0xF0 SIO F1; + add 0xF8 TIO F1; + + (*Format 2 Instructions*) + add 0x90 ADDR F2; + add 0xB4 CLEAR F2; + add 0xA0 COMPR F2; + add 0x9C DIVR F2; + add 0x98 MULR F2; + add 0xAC RMO F2; + add 0xA4 SHIFTL F2; + add 0xA8 SHIFTR F2; + add 0x94 SUBR F2; + add 0xB0 SVC F2; + add 0xB8 TIXR F2; + + (*Format 3/4 Instructions*) + add 0x18 ADD F3_4; + add 0x58 ADDF F3_4; + add 0x40 AND F3_4; + add 0x28 COMP F3_4; + add 0x88 COMPF F3_4; + add 0x24 DIV F3_4; + add 0x3C J F3_4; + add 0x30 JEQ F3_4; + add 0x34 JGT F3_4; + add 0x38 JLT F3_4; + add 0x48 JSUB F3_4; + add 0x00 LDA F3_4; + add 0x68 LDB F3_4; + add 0x50 LDCH F3_4; + add 0x70 LDF F3_4; + add 0x08 LDL F3_4; + add 0x6C LDS F3_4; + add 0x74 LDT F3_4; + add 0x04 LDX F3_4; + add 0xD0 LPS F3_4; + add 0x20 MUL F3_4; + add 0x44 OR F3_4; + add 0xD8 RD F3_4; + add 0x4C RSUB F3_4; + add 0x0C STA F3_4; + add 0x78 STB F3_4; + add 0x54 STCH F3_4; + add 0x80 STF F3_4; + add 0x14 STL F3_4; + add 0x7C STS F3_4; + add 0xE8 STSW F3_4; + add 0x84 STT F3_4; + add 0x10 STX F3_4; + add 0x1C SUB F3_4; + add 0x5C SUBF F3_4; + add 0xE0 TD F3_4; + add 0x2C TIX F3_4; + add 0xDC WD F3_4; +() + +(*mnemonic to string*) +let string_of_mnemonic = function + (* Format 1 *) + | FIX -> "FIX" + | FLOAT -> "FLOAT" + | HIO -> "HIO" + | NORM -> "NORM" + | SIO -> "SIO" + | TIO -> "TIO" + + (* Format 2 *) + | ADDR -> "ADDR" + | CLEAR -> "CLEAR" + | COMPR -> "COMPR" + | DIVR -> "DIVR" + | MULR -> "MULR" + | RMO -> "RMO" + | SHIFTL -> "SHIFTL" + | SHIFTR -> "SHIFTR" + | SUBR -> "SUBR" + | SVC -> "SVC" + | TIXR -> "TIXR" + + (* Format 3/4 *) + | ADD -> "ADD" + | ADDF -> "ADDF" + | AND -> "AND" + | COMP -> "COMP" + | COMPF -> "COMPF" + | DIV -> "DIV" + | J -> "J" + | JEQ -> "JEQ" + | JGT -> "JGT" + | JLT -> "JLT" + | JSUB -> "JSUB" + | LDA -> "LDA" + | LDB -> "LDB" + | LDCH -> "LDCH" + | LDF -> "LDF" + | LDL -> "LDL" + | LDS -> "LDS" + | LDT -> "LDT" + | LDX -> "LDX" + | LPS -> "LPS" + | MUL -> "MUL" + | OR -> "OR" + | RD -> "RD" + | RSUB -> "RSUB" + | STA -> "STA" + | STB -> "STB" + | STCH -> "STCH" + | STF -> "STF" + | STL -> "STL" + | STS -> "STS" + | STSW -> "STSW" + | STT -> "STT" + | STX -> "STX" + | SUB -> "SUB" + | SUBF -> "SUBF" + | TD -> "TD" + | TIX -> "TIX" + | WD -> "WD" diff --git a/ass2/SICocaml/SICXE/test/dune b/ass2/SICocaml/SICXE/test/dune new file mode 100644 index 0000000..d37d3d2 --- /dev/null +++ b/ass2/SICocaml/SICXE/test/dune @@ -0,0 +1,2 @@ +(test + (name test_SICXE)) diff --git a/ass2/SICocaml/SICXE/test/test_SICXE.ml b/ass2/SICocaml/SICXE/test/test_SICXE.ml new file mode 100644 index 0000000..e69de29 diff --git a/ass2/SICocaml/izvajalnik.ml b/ass2/SICocaml/izvajalnik.ml index 47588d7..fb27223 100644 --- a/ass2/SICocaml/izvajalnik.ml +++ b/ass2/SICocaml/izvajalnik.ml @@ -51,7 +51,7 @@ let readMem (state : state) (offset : int) : char = (*beri drugi byte ukaza formata 2 in vrni r1 in r2, kot int njunih vrednosti (reg a -> 1, reg x -> 2 ...)*) -let readFormat2Byte2 (state : state) : (int * int) = +let readR1R2 (state : state) : (int * int) = let byte2 = Char.code (readMem state 1) in let highNibble = (byte2 land 0xF0) lsr 4 in (*pridobi prvi nibble*) let lowNibble = byte2 land 0x0F in (*pridobi drugi nibble*) @@ -69,6 +69,10 @@ let getNIXBPE (state : state) : nixbpe = e = (byte2 lsr 4) land 1;} +let getAddress (state : state) : int = + 42 + + (*execute format 1*) let executeFormat1 (state : state) (mnemonic : OpcodeTable.mnemonic) : unit = match mnemonic with @@ -78,12 +82,13 @@ let executeFormat1 (state : state) (mnemonic : OpcodeTable.mnemonic) : unit = | NORM -> notImplemented "NORM" | SIO -> notImplemented "SIO" | TIO -> notImplemented "TIO" - | _ -> Printf.printf "Mnemonic %s falsely flaged as format 1" (OpcodeTable.string_of_mnemonic mnemonic) + |_ -> failwith ("Mnemonic" ^ (OpcodeTable.string_of_mnemonic mnemonic) ^ "falsely flaged as format 1") + (*execute format 2*) let executeFormat2 (state: state) (mnemonic : OpcodeTable.mnemonic) : unit = - let (r1, r2) = readFormat2Byte2 state in + let (r1, r2) = readR1R2 state in match mnemonic with | ADDR -> notImplemented "ADD" (*when implemented: -> add state r1 r2*) | CLEAR -> notImplemented "CLEAR" @@ -96,18 +101,117 @@ let executeFormat2 (state: state) (mnemonic : OpcodeTable.mnemonic) : unit = | SUBR -> notImplemented "F2" | SVC -> notImplemented "F2" | TIXR -> notImplemented "F2" - |_ -> Printf.printf "Mnemonic %s falsely flaged as format 1" (OpcodeTable.string_of_mnemonic mnemonic) + |_ -> failwith ("Mnemonic" ^ (OpcodeTable.string_of_mnemonic mnemonic) ^ "falsely flaged as format 2") -let executeFormat3 (state : state) (nixbpe : nixbpe) : unit +(*execute Format 3*) +let executeFormat3 (state : state) (nixbpe : nixbpe) (mnemonic: OpcodeTable.mnemonic): unit = + let address = getAddress state in + match mnemonic with + | ADD -> notImplemented "ADD3" + | ADDF -> notImplemented "ADDF4" + | AND -> notImplemented "AND4" + | COMP -> notImplemented "COMP4" + | COMPF -> notImplemented "COMPF4" + | DIV -> notImplemented "DIV4" + | MUL -> notImplemented "MUL4" + | OR -> notImplemented "OR4" + | SUB -> notImplemented "SUB4" + | SUBF -> notImplemented "SUBF4" + | TD -> notImplemented "TD4" + | WD -> notImplemented "WD4" + + (* Jump / subroutine *) + | J -> notImplemented "J4" + | JEQ -> notImplemented "JEQ4" + | JGT -> notImplemented "JGT4" + | JLT -> notImplemented "JLT4" + | JSUB -> notImplemented "JSUB4" + | RSUB -> notImplemented "RSUB4" + + (* Load/store *) + | LDA -> notImplemented "LDA4" + | LDB -> notImplemented "LDB4" + | LDCH -> notImplemented "LDCH4" + | LDF -> notImplemented "LDF4" + | LDL -> notImplemented "LDL4" + | LDS -> notImplemented "LDS4" + | LDT -> notImplemented "LDT4" + | LDX -> notImplemented "LDX4" + | LPS -> notImplemented "LPS4" + | STA -> notImplemented "STA4" + | STB -> notImplemented "STB4" + | STCH -> notImplemented "STCH4" + | STF -> notImplemented "STF4" + | STL -> notImplemented "STL4" + | STS -> notImplemented "STS4" + | STSW -> notImplemented "STSW4" + | STT -> notImplemented "STT4" + | STX -> notImplemented "STX4" + + (* Control / IO *) + | TIX -> notImplemented "TIX4" + |_ -> failwith ("Mnemonic" ^ (OpcodeTable.string_of_mnemonic mnemonic) ^ "falsely flaged as format 3") -(*execute format 3*) +let executeFormat4 (state : state) (nixbpe : nixbpe) (mnemonic: OpcodeTable.mnemonic): unit = + let address = getAddress state in + match mnemonic with + (*aritmetika*) + | ADD -> notImplemented "ADD4" + | ADDF -> notImplemented "ADDF4" + | AND -> notImplemented "AND4" + | COMP -> notImplemented "COMP4" + | COMPF -> notImplemented "COMPF4" + | DIV -> notImplemented "DIV4" + | MUL -> notImplemented "MUL4" + | OR -> notImplemented "OR4" + | SUB -> notImplemented "SUB4" + | SUBF -> notImplemented "SUBF4" + | TD -> notImplemented "TD4" + | WD -> notImplemented "WD4" + + (* Jump / subroutine *) + | J -> notImplemented "J4" + | JEQ -> notImplemented "JEQ4" + | JGT -> notImplemented "JGT4" + | JLT -> notImplemented "JLT4" + | JSUB -> notImplemented "JSUB4" + | RSUB -> notImplemented "RSUB4" + + (* Load/store *) + | LDA -> notImplemented "LDA4" + | LDB -> notImplemented "LDB4" + | LDCH -> notImplemented "LDCH4" + | LDF -> notImplemented "LDF4" + | LDL -> notImplemented "LDL4" + | LDS -> notImplemented "LDS4" + | LDT -> notImplemented "LDT4" + | LDX -> notImplemented "LDX4" + | LPS -> notImplemented "LPS4" + | STA -> notImplemented "STA4" + | STB -> notImplemented "STB4" + | STCH -> notImplemented "STCH4" + | STF -> notImplemented "STF4" + | STL -> notImplemented "STL4" + | STS -> notImplemented "STS4" + | STSW -> notImplemented "STSW4" + | STT -> notImplemented "STT4" + | STX -> notImplemented "STX4" + + (* Control / IO *) + | TIX -> notImplemented "TIX4" + |_ -> failwith ("Mnemonic" ^ (OpcodeTable.string_of_mnemonic mnemonic) ^ "falsely flaged as format 4") + + + + +(*execute format 3_4*) let executeFormat3_4 (state : state) (mnemonic : OpcodeTable.mnemonic) : unit = let nixbpe = getNIXBPE state in match nixbpe.e with - | 0 -> executeFormat3 state - | 1 -> executeFormat4 state + | 0 -> executeFormat3 state nixbpe mnemonic + | 1 -> executeFormat4 state nixbpe mnemonic | _ -> failwith "invalid computation of nxbpe" diff --git a/hello.asm b/hello.asm index 362a8cd..0d6e135 100644 --- a/hello.asm +++ b/hello.asm @@ -1,13 +1,13 @@ -.koda -hello START 0 - LDA n - LDB #9 - MULR A, B - STA out - WD out -halt J halt - -.podatki -n WORD 0x000002 -out RESW 1 - END hello +.koda +hello START 0 + LDA n + LDB #9 + MULR A, B + STA out + WD out +halt J halt + +.podatki +n WORD 0x000002 +out RESW 1 + END hello