working on sicxe
This commit is contained in:
parent
1b990e190c
commit
d836b3955d
79 changed files with 2011 additions and 917 deletions
14
FA.dev
14
FA.dev
|
|
@ -1,8 +1,8 @@
|
||||||
1
|
1
|
||||||
2
|
2
|
||||||
3
|
3
|
||||||
4
|
4
|
||||||
5
|
5
|
||||||
6
|
6
|
||||||
7
|
7
|
||||||
0
|
0
|
||||||
|
|
@ -1,44 +1,44 @@
|
||||||
|
|
||||||
|
|
||||||
arith START 0
|
arith START 0
|
||||||
|
|
||||||
start LDA x
|
start LDA x
|
||||||
ADD y
|
ADD y
|
||||||
STA sum .shrani vsoto
|
STA sum .shrani vsoto
|
||||||
|
|
||||||
LDA x
|
LDA x
|
||||||
SUB y
|
SUB y
|
||||||
STA diff .shrani razliko
|
STA diff .shrani razliko
|
||||||
|
|
||||||
LDA x
|
LDA x
|
||||||
MUL y
|
MUL y
|
||||||
STA prod .sharni produkt
|
STA prod .sharni produkt
|
||||||
|
|
||||||
LDA x
|
LDA x
|
||||||
DIV y
|
DIV y
|
||||||
STA quot .shrani kvocient
|
STA quot .shrani kvocient
|
||||||
|
|
||||||
LDA y
|
LDA y
|
||||||
MUL quot
|
MUL quot
|
||||||
STA z
|
STA z
|
||||||
LDA x
|
LDA x
|
||||||
SUB z
|
SUB z
|
||||||
STA mod .shrani modulo
|
STA mod .shrani modulo
|
||||||
|
|
||||||
halt J halt
|
halt J halt
|
||||||
END start
|
END start
|
||||||
|
|
||||||
.podatki
|
.podatki
|
||||||
x WORD 20
|
x WORD 20
|
||||||
y WORD 3
|
y WORD 3
|
||||||
|
|
||||||
.rezultati
|
.rezultati
|
||||||
sum RESW 1
|
sum RESW 1
|
||||||
diff RESW 1
|
diff RESW 1
|
||||||
prod RESW 1
|
prod RESW 1
|
||||||
quot RESW 1
|
quot RESW 1
|
||||||
mod RESW 1
|
mod RESW 1
|
||||||
|
|
||||||
.za modulo
|
.za modulo
|
||||||
z RESW 1
|
z RESW 1
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,46 +1,46 @@
|
||||||
|
|
||||||
|
|
||||||
arith START 0
|
arith START 0
|
||||||
|
|
||||||
start LDT x
|
start LDT x
|
||||||
LDS y
|
LDS y
|
||||||
ADDR T, S .shrani vsoto
|
ADDR T, S .shrani vsoto
|
||||||
STS sum
|
STS sum
|
||||||
SUBR T, S .resetiraj S nazaj na y
|
SUBR T, S .resetiraj S nazaj na y
|
||||||
|
|
||||||
SUBR S, T
|
SUBR S, T
|
||||||
STT diff .shrani razliko
|
STT diff .shrani razliko
|
||||||
ADDR S, T .popravi T
|
ADDR S, T .popravi T
|
||||||
|
|
||||||
MULR T, S
|
MULR T, S
|
||||||
STS prod .sharni produkt
|
STS prod .sharni produkt
|
||||||
|
|
||||||
LDT x
|
LDT x
|
||||||
LDS y
|
LDS y
|
||||||
DIVR S, T
|
DIVR S, T
|
||||||
STT quot .shrani kvocient
|
STT quot .shrani kvocient
|
||||||
|
|
||||||
LDT x
|
LDT x
|
||||||
LDS y
|
LDS y
|
||||||
LDB quot
|
LDB quot
|
||||||
MULR S, B
|
MULR S, B
|
||||||
SUBR B, T
|
SUBR B, T
|
||||||
STT mod .shrani modulo
|
STT mod .shrani modulo
|
||||||
|
|
||||||
halt J halt
|
halt J halt
|
||||||
END start
|
END start
|
||||||
|
|
||||||
.podatki
|
.podatki
|
||||||
x WORD 20
|
x WORD 20
|
||||||
y WORD 3
|
y WORD 3
|
||||||
|
|
||||||
.rezultati
|
.rezultati
|
||||||
sum RESW 1
|
sum RESW 1
|
||||||
diff RESW 1
|
diff RESW 1
|
||||||
prod RESW 1
|
prod RESW 1
|
||||||
quot RESW 1
|
quot RESW 1
|
||||||
mod RESW 1
|
mod RESW 1
|
||||||
|
|
||||||
.za modulo
|
.za modulo
|
||||||
z RESW 1
|
z RESW 1
|
||||||
|
|
||||||
|
|
|
||||||
12
ass1/cat.asm
12
ass1/cat.asm
|
|
@ -1,7 +1,7 @@
|
||||||
cat START 0
|
cat START 0
|
||||||
.beri in pisi
|
.beri in pisi
|
||||||
loop RD #0
|
loop RD #0
|
||||||
WD #1
|
WD #1
|
||||||
J loop
|
J loop
|
||||||
|
|
||||||
END loop
|
END loop
|
||||||
272
ass1/echo.asm
272
ass1/echo.asm
|
|
@ -1,137 +1,137 @@
|
||||||
echo START 0
|
echo START 0
|
||||||
start .LDCH txt
|
start .LDCH txt
|
||||||
.JSUB char
|
.JSUB char
|
||||||
.JSUB nl
|
.JSUB nl
|
||||||
.LDA #txt
|
.LDA #txt
|
||||||
.JSUB string
|
.JSUB string
|
||||||
.JSUB nl
|
.JSUB nl
|
||||||
|
|
||||||
LDCH #12
|
LDCH #12
|
||||||
JSUB num
|
JSUB num
|
||||||
|
|
||||||
halt J halt
|
halt J halt
|
||||||
|
|
||||||
.char
|
.char
|
||||||
char STB regB
|
char STB regB
|
||||||
STT regT
|
STT regT
|
||||||
.STL regL
|
.STL regL
|
||||||
STS regS .shranimo registre
|
STS regS .shranimo registre
|
||||||
|
|
||||||
WD #1
|
WD #1
|
||||||
.obnovimo registre
|
.obnovimo registre
|
||||||
LDB regB
|
LDB regB
|
||||||
LDT regT
|
LDT regT
|
||||||
.LDL regL
|
.LDL regL
|
||||||
LDS regS
|
LDS regS
|
||||||
|
|
||||||
RSUB
|
RSUB
|
||||||
|
|
||||||
.nl
|
.nl
|
||||||
nl STB regB
|
nl STB regB
|
||||||
STT regT
|
STT regT
|
||||||
STS regS .shranimo registre
|
STS regS .shranimo registre
|
||||||
|
|
||||||
LDCH newline
|
LDCH newline
|
||||||
WD #1
|
WD #1
|
||||||
LDX #1
|
LDX #1
|
||||||
LDCH newline, X
|
LDCH newline, X
|
||||||
WD #1
|
WD #1
|
||||||
|
|
||||||
.obnovimo registre
|
.obnovimo registre
|
||||||
LDB regB
|
LDB regB
|
||||||
LDT regT
|
LDT regT
|
||||||
LDS regS
|
LDS regS
|
||||||
|
|
||||||
RSUB
|
RSUB
|
||||||
|
|
||||||
.string
|
.string
|
||||||
string STA regA
|
string STA regA
|
||||||
STB regB
|
STB regB
|
||||||
STT regT
|
STT regT
|
||||||
.STL regL
|
.STL regL
|
||||||
STS regS .shranimo registre
|
STS regS .shranimo registre
|
||||||
|
|
||||||
loop LDB #1
|
loop LDB #1
|
||||||
CLEAR A .da lahko comparamo z 0
|
CLEAR A .da lahko comparamo z 0
|
||||||
LDCH @regA
|
LDCH @regA
|
||||||
COMP #0
|
COMP #0
|
||||||
WD #1
|
WD #1
|
||||||
.add +1 to regA
|
.add +1 to regA
|
||||||
LDA regA
|
LDA regA
|
||||||
ADD #1
|
ADD #1
|
||||||
STA regA
|
STA regA
|
||||||
JGT loop
|
JGT loop
|
||||||
|
|
||||||
LDA regA .obnovimo registre
|
LDA regA .obnovimo registre
|
||||||
LDB regB
|
LDB regB
|
||||||
LDT regT
|
LDT regT
|
||||||
.LDL regL
|
.LDL regL
|
||||||
LDS regS
|
LDS regS
|
||||||
|
|
||||||
RSUB
|
RSUB
|
||||||
.izpiše število zapisano v A na std izhod
|
.izpiše število zapisano v A na std izhod
|
||||||
num STA regA
|
num STA regA
|
||||||
STB regB
|
STB regB
|
||||||
STT regT
|
STT regT
|
||||||
STL regL
|
STL regL
|
||||||
STS regS .shranimo registre
|
STS regS .shranimo registre
|
||||||
|
|
||||||
LDX #4 .X steje stevke, 4 je zadnji index arraya velikosti 5
|
LDX #4 .X steje stevke, 4 je zadnji index arraya velikosti 5
|
||||||
LDS #10 .za množenje/deljenje
|
LDS #10 .za množenje/deljenje
|
||||||
LDT #0x30 .za pretvorbo v ascii
|
LDT #0x30 .za pretvorbo v ascii
|
||||||
|
|
||||||
loop2 RMO A, B
|
loop2 RMO A, B
|
||||||
DIVR S, B .B = B/10
|
DIVR S, B .B = B/10
|
||||||
MULR S, B .B= B*10
|
MULR S, B .B= B*10
|
||||||
SUBR B, A .A = ostanek
|
SUBR B, A .A = ostanek
|
||||||
ADDR T, A .pretvorimo A v ascii
|
ADDR T, A .pretvorimo A v ascii
|
||||||
STCH digs, X .shranimo ascii ostanek
|
STCH digs, X .shranimo ascii ostanek
|
||||||
|
|
||||||
.zmanjšamo X in primerjamo z #5
|
.zmanjšamo X in primerjamo z #5
|
||||||
RMO X, A
|
RMO X, A
|
||||||
SUB #1
|
SUB #1
|
||||||
RMO A, X
|
RMO A, X
|
||||||
LDA #0
|
LDA #0
|
||||||
COMPR X, A
|
COMPR X, A
|
||||||
|
|
||||||
RMO B, A .premaknemo kar je še potrebno izračunati v A
|
RMO B, A .premaknemo kar je še potrebno izračunati v A
|
||||||
DIVR S, A .A je sedaj naslednja števka
|
DIVR S, A .A je sedaj naslednja števka
|
||||||
|
|
||||||
JEQ loop2
|
JEQ loop2
|
||||||
JGT loop2
|
JGT loop2
|
||||||
|
|
||||||
.kličemo string za izpis
|
.kličemo string za izpis
|
||||||
LDA #digs
|
LDA #digs
|
||||||
JSUB string
|
JSUB string
|
||||||
JSUB nl
|
JSUB nl
|
||||||
|
|
||||||
LDA regA .obnovimo registre
|
LDA regA .obnovimo registre
|
||||||
LDB regB
|
LDB regB
|
||||||
LDT regT
|
LDT regT
|
||||||
LDL regL
|
LDL regL
|
||||||
LDS regS
|
LDS regS
|
||||||
|
|
||||||
RSUB
|
RSUB
|
||||||
|
|
||||||
|
|
||||||
.digits za num
|
.digits za num
|
||||||
digs RESB 5 .0 bo prazna za lazje izpisovanje
|
digs RESB 5 .0 bo prazna za lazje izpisovanje
|
||||||
BYTE 0 .konec števke
|
BYTE 0 .konec števke
|
||||||
|
|
||||||
.txt
|
.txt
|
||||||
txt BYTE C'hi'
|
txt BYTE C'hi'
|
||||||
BYTE 0
|
BYTE 0
|
||||||
|
|
||||||
.constante
|
.constante
|
||||||
newline BYTE 0x0D
|
newline BYTE 0x0D
|
||||||
BYTE 0x0A
|
BYTE 0x0A
|
||||||
|
|
||||||
.registri
|
.registri
|
||||||
regA RESW 1
|
regA RESW 1
|
||||||
regB RESW 1
|
regB RESW 1
|
||||||
regT RESW 1
|
regT RESW 1
|
||||||
regS RESW 1
|
regS RESW 1
|
||||||
regL RESW 1
|
regL RESW 1
|
||||||
|
|
||||||
|
|
||||||
END start
|
END start
|
||||||
134
ass1/fac.asm
134
ass1/fac.asm
|
|
@ -1,68 +1,68 @@
|
||||||
prog START 0
|
prog START 0
|
||||||
zacetek CLEAR X
|
zacetek CLEAR X
|
||||||
loop RD #0xFA
|
loop RD #0xFA
|
||||||
COMP #0
|
COMP #0
|
||||||
JEQ halt
|
JEQ halt
|
||||||
JSUB fact
|
JSUB fact
|
||||||
WD #1
|
WD #1
|
||||||
J loop
|
J loop
|
||||||
|
|
||||||
halt J halt
|
halt J halt
|
||||||
|
|
||||||
.fakulteta
|
.fakulteta
|
||||||
fact COMP #1
|
fact COMP #1
|
||||||
JGT rec
|
JGT rec
|
||||||
LDA #1 .base case
|
LDA #1 .base case
|
||||||
RSUB
|
RSUB
|
||||||
|
|
||||||
rec STL @stkp
|
rec STL @stkp
|
||||||
JSUB spush
|
JSUB spush
|
||||||
STA @stkp
|
STA @stkp
|
||||||
JSUB spush
|
JSUB spush
|
||||||
STB @stkp
|
STB @stkp
|
||||||
JSUB spush
|
JSUB spush
|
||||||
|
|
||||||
RMO A, B .shrani n v B
|
RMO A, B .shrani n v B
|
||||||
SUB #1 .n-1
|
SUB #1 .n-1
|
||||||
JSUB fact .fact(n-1)
|
JSUB fact .fact(n-1)
|
||||||
MULR B, A .n * fact(n-1)
|
MULR B, A .n * fact(n-1)
|
||||||
|
|
||||||
JSUB spop
|
JSUB spop
|
||||||
LDB @stkp
|
LDB @stkp
|
||||||
JSUB spop
|
JSUB spop
|
||||||
.LDA @stkp da ne povozimo odgovora?
|
.LDA @stkp da ne povozimo odgovora?
|
||||||
JSUB spop
|
JSUB spop
|
||||||
LDL @stkp
|
LDL @stkp
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
RSUB
|
RSUB
|
||||||
|
|
||||||
|
|
||||||
.rutine za sklad
|
.rutine za sklad
|
||||||
sinit STA stkA
|
sinit STA stkA
|
||||||
LDA #stkRESW .inicializiraj stkp
|
LDA #stkRESW .inicializiraj stkp
|
||||||
STA stkp
|
STA stkp
|
||||||
LDA stkA
|
LDA stkA
|
||||||
RSUB
|
RSUB
|
||||||
|
|
||||||
spush STA stkA
|
spush STA stkA
|
||||||
LDA stkp .poveca stkp za 3
|
LDA stkp .poveca stkp za 3
|
||||||
ADD #3
|
ADD #3
|
||||||
STA stkp
|
STA stkp
|
||||||
LDA stkA
|
LDA stkA
|
||||||
RSUB
|
RSUB
|
||||||
|
|
||||||
spop STA stkA
|
spop STA stkA
|
||||||
LDA stkp .zmanjsa stkp za 3
|
LDA stkp .zmanjsa stkp za 3
|
||||||
SUB #3
|
SUB #3
|
||||||
STA stkp
|
STA stkp
|
||||||
LDA stkA
|
LDA stkA
|
||||||
RSUB
|
RSUB
|
||||||
|
|
||||||
.podatki za sklad
|
.podatki za sklad
|
||||||
stkp WORD 0
|
stkp WORD 0
|
||||||
stkA WORD 0
|
stkA WORD 0
|
||||||
stkRESW RESW 1000
|
stkRESW RESW 1000
|
||||||
|
|
||||||
END prog
|
END prog
|
||||||
130
ass1/fact.asm
130
ass1/fact.asm
|
|
@ -1,66 +1,66 @@
|
||||||
prog START 0
|
prog START 0
|
||||||
JSUB sinit
|
JSUB sinit
|
||||||
LDA #5
|
LDA #5
|
||||||
JSUB fact
|
JSUB fact
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
halt J halt
|
halt J halt
|
||||||
|
|
||||||
.fakulteta
|
.fakulteta
|
||||||
fact COMP #1
|
fact COMP #1
|
||||||
JGT rec
|
JGT rec
|
||||||
LDA #1 .base case
|
LDA #1 .base case
|
||||||
RSUB
|
RSUB
|
||||||
|
|
||||||
rec STL @stkp
|
rec STL @stkp
|
||||||
JSUB spush
|
JSUB spush
|
||||||
STA @stkp
|
STA @stkp
|
||||||
JSUB spush
|
JSUB spush
|
||||||
STB @stkp
|
STB @stkp
|
||||||
JSUB spush
|
JSUB spush
|
||||||
|
|
||||||
RMO A, B .shrani n v B
|
RMO A, B .shrani n v B
|
||||||
SUB #1 .n-1
|
SUB #1 .n-1
|
||||||
JSUB fact .fact(n-1)
|
JSUB fact .fact(n-1)
|
||||||
MULR B, A .n * fact(n-1)
|
MULR B, A .n * fact(n-1)
|
||||||
|
|
||||||
JSUB spop
|
JSUB spop
|
||||||
LDB @stkp
|
LDB @stkp
|
||||||
JSUB spop
|
JSUB spop
|
||||||
.LDA @stkp da ne povozimo odgovora?
|
.LDA @stkp da ne povozimo odgovora?
|
||||||
JSUB spop
|
JSUB spop
|
||||||
LDL @stkp
|
LDL @stkp
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
RSUB
|
RSUB
|
||||||
|
|
||||||
|
|
||||||
.rutine za sklad
|
.rutine za sklad
|
||||||
sinit STA stkA
|
sinit STA stkA
|
||||||
LDA #stkRESW .inicializiraj stkp
|
LDA #stkRESW .inicializiraj stkp
|
||||||
STA stkp
|
STA stkp
|
||||||
LDA stkA
|
LDA stkA
|
||||||
RSUB
|
RSUB
|
||||||
|
|
||||||
spush STA stkA
|
spush STA stkA
|
||||||
LDA stkp .poveca stkp za 3
|
LDA stkp .poveca stkp za 3
|
||||||
ADD #3
|
ADD #3
|
||||||
STA stkp
|
STA stkp
|
||||||
LDA stkA
|
LDA stkA
|
||||||
RSUB
|
RSUB
|
||||||
|
|
||||||
spop STA stkA
|
spop STA stkA
|
||||||
LDA stkp .zmanjsa stkp za 3
|
LDA stkp .zmanjsa stkp za 3
|
||||||
SUB #3
|
SUB #3
|
||||||
STA stkp
|
STA stkp
|
||||||
LDA stkA
|
LDA stkA
|
||||||
RSUB
|
RSUB
|
||||||
|
|
||||||
.podatki za sklad
|
.podatki za sklad
|
||||||
stkp WORD 0
|
stkp WORD 0
|
||||||
stkA WORD 0
|
stkA WORD 0
|
||||||
stkRESW RESW 1000
|
stkRESW RESW 1000
|
||||||
|
|
||||||
END prog
|
END prog
|
||||||
|
|
@ -1,38 +1,38 @@
|
||||||
poly START 0
|
poly START 0
|
||||||
start LDT x4
|
start LDT x4
|
||||||
LDS x
|
LDS x
|
||||||
MULR S, T
|
MULR S, T
|
||||||
LDA x3
|
LDA x3
|
||||||
ADDR T, A . do sedaj izračunano (1x + 2)
|
ADDR T, A . do sedaj izračunano (1x + 2)
|
||||||
|
|
||||||
LDT x2
|
LDT x2
|
||||||
MULR S, A
|
MULR S, A
|
||||||
ADDR T, A .do sedaj izračunano ((1x+2)x + 3)
|
ADDR T, A .do sedaj izračunano ((1x+2)x + 3)
|
||||||
|
|
||||||
LDT x1
|
LDT x1
|
||||||
MULR S, A
|
MULR S, A
|
||||||
ADDR T, A .do sedaj izračunano (((1x+2)x + 3)x + 4)
|
ADDR T, A .do sedaj izračunano (((1x+2)x + 3)x + 4)
|
||||||
|
|
||||||
LDT x0
|
LDT x0
|
||||||
MULR S, A
|
MULR S, A
|
||||||
ADDR T, A .do sedaj izračunano (((1x+2)x + 3)x + 4)x + 5
|
ADDR T, A .do sedaj izračunano (((1x+2)x + 3)x + 4)x + 5
|
||||||
|
|
||||||
|
|
||||||
STA rez
|
STA rez
|
||||||
|
|
||||||
halt J halt
|
halt J halt
|
||||||
END start
|
END start
|
||||||
|
|
||||||
|
|
||||||
.polinom
|
.polinom
|
||||||
x4 WORD 1
|
x4 WORD 1
|
||||||
x3 WORD 2
|
x3 WORD 2
|
||||||
x2 WORD 3
|
x2 WORD 3
|
||||||
x1 WORD 4
|
x1 WORD 4
|
||||||
x0 WORD 5
|
x0 WORD 5
|
||||||
|
|
||||||
.tocka
|
.tocka
|
||||||
x WORD 2
|
x WORD 2
|
||||||
|
|
||||||
.rezultat
|
.rezultat
|
||||||
rez RESW 1
|
rez RESW 1
|
||||||
|
|
@ -1,66 +1,66 @@
|
||||||
.program prebere iz spomina seznam števil dolžine len
|
.program prebere iz spomina seznam števil dolžine len
|
||||||
.in jih uredi z insertion sortom
|
.in jih uredi z insertion sortom
|
||||||
.pustimo prvi element paddan, da lažje rečunamo premike
|
.pustimo prvi element paddan, da lažje rečunamo premike
|
||||||
prog START 0
|
prog START 0
|
||||||
LDX #6
|
LDX #6
|
||||||
|
|
||||||
loop LDB #len
|
loop LDB #len
|
||||||
COMPR X, B .i < len
|
COMPR X, B .i < len
|
||||||
JEQ halt .zaključi
|
JEQ halt .zaključi
|
||||||
|
|
||||||
LDA arr, X .A = arr[i]
|
LDA arr, X .A = arr[i]
|
||||||
RMO X, S .S <- i
|
RMO X, S .S <- i
|
||||||
LDT #3 .T <- 3
|
LDT #3 .T <- 3
|
||||||
SUBR T, X .X <- j= i - 1
|
SUBR T, X .X <- j= i - 1
|
||||||
|
|
||||||
loop2 LDT #3
|
loop2 LDT #3
|
||||||
COMPR X, T .j >= 1
|
COMPR X, T .j >= 1
|
||||||
JLT insert .ko je j = 0 skoči
|
JLT insert .ko je j = 0 skoči
|
||||||
J next .skoči na preverjanje naslednjega pogoja
|
J next .skoči na preverjanje naslednjega pogoja
|
||||||
|
|
||||||
.shranimo S nazaj v X in ga zmanjšamo za ena
|
.shranimo S nazaj v X in ga zmanjšamo za ena
|
||||||
.nato skočimo nazaj v loop
|
.nato skočimo nazaj v loop
|
||||||
exit2 RMO S, X .X <- i
|
exit2 RMO S, X .X <- i
|
||||||
LDT #3
|
LDT #3
|
||||||
ADDR T, X .X <- i + 1
|
ADDR T, X .X <- i + 1
|
||||||
J loop
|
J loop
|
||||||
|
|
||||||
next LDB arr, X
|
next LDB arr, X
|
||||||
COMPR B, A .arr[j] > arr[i]
|
COMPR B, A .arr[j] > arr[i]
|
||||||
JGT swap
|
JGT swap
|
||||||
J insert .če pogoj ni izpolnjen
|
J insert .če pogoj ni izpolnjen
|
||||||
|
|
||||||
.sicer zamenjamo elementa
|
.sicer zamenjamo elementa
|
||||||
swap LDT #3
|
swap LDT #3
|
||||||
ADDR T, X .X <- j + 1
|
ADDR T, X .X <- j + 1
|
||||||
STB arr, X. arr[j+1] = arr[j]
|
STB arr, X. arr[j+1] = arr[j]
|
||||||
|
|
||||||
LDT #6
|
LDT #6
|
||||||
SUBR T, X .x <- x-1
|
SUBR T, X .x <- x-1
|
||||||
J loop2
|
J loop2
|
||||||
|
|
||||||
insert LDT #3
|
insert LDT #3
|
||||||
ADDR T, X .j = j+1
|
ADDR T, X .j = j+1
|
||||||
STA arr, X .arr[j+1] = arr[i]
|
STA arr, X .arr[j+1] = arr[i]
|
||||||
SUBR T, X .j = j
|
SUBR T, X .j = j
|
||||||
J exit2
|
J exit2
|
||||||
|
|
||||||
halt J halt
|
halt J halt
|
||||||
|
|
||||||
arr WORD 0
|
arr WORD 0
|
||||||
WORD 5
|
WORD 5
|
||||||
WORD 3
|
WORD 3
|
||||||
WORD 8
|
WORD 8
|
||||||
WORD 1
|
WORD 1
|
||||||
WORD 4
|
WORD 4
|
||||||
WORD 7
|
WORD 7
|
||||||
WORD 2
|
WORD 2
|
||||||
WORD 9
|
WORD 9
|
||||||
arrEnd WORD 6
|
arrEnd WORD 6
|
||||||
|
|
||||||
len EQU arrEnd - arr + 3
|
len EQU arrEnd - arr + 3
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
END prog
|
END prog
|
||||||
|
|
@ -1,42 +1,42 @@
|
||||||
poly START 0
|
poly START 0
|
||||||
start LDA x0 .pristejemo x0 v A
|
start LDA x0 .pristejemo x0 v A
|
||||||
|
|
||||||
LDB x
|
LDB x
|
||||||
LDS x
|
LDS x
|
||||||
LDT x1
|
LDT x1
|
||||||
MULR S, T
|
MULR S, T
|
||||||
ADDR T, A .pristejemo x0 * x
|
ADDR T, A .pristejemo x0 * x
|
||||||
|
|
||||||
LDT x2
|
LDT x2
|
||||||
MULR B, S .izracunamo x^2
|
MULR B, S .izracunamo x^2
|
||||||
MULR S, T
|
MULR S, T
|
||||||
ADDR T, A
|
ADDR T, A
|
||||||
|
|
||||||
LDT x3
|
LDT x3
|
||||||
MULR B, S .izracunamo x^3
|
MULR B, S .izracunamo x^3
|
||||||
MULR S, T
|
MULR S, T
|
||||||
ADDR T, A
|
ADDR T, A
|
||||||
|
|
||||||
LDT x4
|
LDT x4
|
||||||
MULR B, S .izracunamo x^4
|
MULR B, S .izracunamo x^4
|
||||||
MULR S, T
|
MULR S, T
|
||||||
ADDR T, A
|
ADDR T, A
|
||||||
|
|
||||||
STA rez
|
STA rez
|
||||||
|
|
||||||
halt J halt
|
halt J halt
|
||||||
END start
|
END start
|
||||||
|
|
||||||
|
|
||||||
.polinom
|
.polinom
|
||||||
x4 WORD 1
|
x4 WORD 1
|
||||||
x3 WORD 2
|
x3 WORD 2
|
||||||
x2 WORD 3
|
x2 WORD 3
|
||||||
x1 WORD 4
|
x1 WORD 4
|
||||||
x0 WORD 5
|
x0 WORD 5
|
||||||
|
|
||||||
.tocka
|
.tocka
|
||||||
x WORD 2
|
x WORD 2
|
||||||
|
|
||||||
.rezultat
|
.rezultat
|
||||||
rez RESW 1
|
rez RESW 1
|
||||||
|
|
@ -1,64 +1,64 @@
|
||||||
poly START 0
|
poly START 0
|
||||||
start LDA x
|
start LDA x
|
||||||
STA arg1
|
STA arg1
|
||||||
JSUB startSubrutine
|
JSUB startSubrutine
|
||||||
LDA subRez
|
LDA subRez
|
||||||
STA rez
|
STA rez
|
||||||
|
|
||||||
halt J halt
|
halt J halt
|
||||||
END start
|
END start
|
||||||
|
|
||||||
.subrutina za izračun tega polinoma v točki arg1
|
.subrutina za izračun tega polinoma v točki arg1
|
||||||
startSubrutine STA regA
|
startSubrutine STA regA
|
||||||
STB regB
|
STB regB
|
||||||
STT regT
|
STT regT
|
||||||
STS regS .shranimo registre
|
STS regS .shranimo registre
|
||||||
|
|
||||||
LDA x0 .pristejemo x0 v A
|
LDA x0 .pristejemo x0 v A
|
||||||
|
|
||||||
LDX #3 .odmik v arrayu
|
LDX #3 .odmik v arrayu
|
||||||
LDS arg1
|
LDS arg1
|
||||||
loop LDT x0, X .preberemo x_n
|
loop LDT x0, X .preberemo x_n
|
||||||
MULR S, T .izračunamo x_n * x^n
|
MULR S, T .izračunamo x_n * x^n
|
||||||
ADDR T, A .pristejemo v vsoto
|
ADDR T, A .pristejemo v vsoto
|
||||||
LDT arg1
|
LDT arg1
|
||||||
MULR T, S .zmožimo naslednjo potenco
|
MULR T, S .zmožimo naslednjo potenco
|
||||||
LDT #3
|
LDT #3
|
||||||
ADDR T, X .povečamo odmik
|
ADDR T, X .povečamo odmik
|
||||||
LDT #13
|
LDT #13
|
||||||
COMPR T, X
|
COMPR T, X
|
||||||
JGT loop
|
JGT loop
|
||||||
|
|
||||||
STA subRez .shranimo rez
|
STA subRez .shranimo rez
|
||||||
|
|
||||||
LDA regA .obnovimo registre
|
LDA regA .obnovimo registre
|
||||||
LDB regB
|
LDB regB
|
||||||
LDT regT
|
LDT regT
|
||||||
LDS regS
|
LDS regS
|
||||||
|
|
||||||
RSUB
|
RSUB
|
||||||
|
|
||||||
.polinom
|
.polinom
|
||||||
x0 WORD 5
|
x0 WORD 5
|
||||||
WORD 4
|
WORD 4
|
||||||
WORD 3
|
WORD 3
|
||||||
WORD 2
|
WORD 2
|
||||||
WORD 1
|
WORD 1
|
||||||
|
|
||||||
.tocka
|
.tocka
|
||||||
x WORD 2
|
x WORD 2
|
||||||
|
|
||||||
.rezultat
|
.rezultat
|
||||||
rez RESW 1
|
rez RESW 1
|
||||||
|
|
||||||
.parameter subrutine
|
.parameter subrutine
|
||||||
arg1 RESW 1
|
arg1 RESW 1
|
||||||
|
|
||||||
.rezultat subrutine
|
.rezultat subrutine
|
||||||
subRez RESW 1
|
subRez RESW 1
|
||||||
|
|
||||||
.registri
|
.registri
|
||||||
regA RESW 1
|
regA RESW 1
|
||||||
regB RESW 1
|
regB RESW 1
|
||||||
regT RESW 1
|
regT RESW 1
|
||||||
regS RESW 1
|
regS RESW 1
|
||||||
|
|
|
||||||
|
|
@ -1,17 +1,17 @@
|
||||||
print START 0
|
print START 0
|
||||||
zacetek CLEAR X
|
zacetek CLEAR X
|
||||||
loop LDCH txt, X
|
loop LDCH txt, X
|
||||||
WD #0xAA
|
WD #0xAA
|
||||||
TIX #len .#len, ker je len EQU in ne dejanska lokacija v spominu!!!!!
|
TIX #len .#len, ker je len EQU in ne dejanska lokacija v spominu!!!!!
|
||||||
JLT loop
|
JLT loop
|
||||||
|
|
||||||
halt J halt
|
halt J halt
|
||||||
|
|
||||||
.constants
|
.constants
|
||||||
txt BYTE C'SIC/XE'
|
txt BYTE C'SIC/XE'
|
||||||
BYTE 0
|
BYTE 0
|
||||||
txtend EQU *
|
txtend EQU *
|
||||||
len EQU txtend-txt .definicija konstante EQU, ki ni shranjena v pomnilniku, zato ko jo želimo uporabiti
|
len EQU txtend-txt .definicija konstante EQU, ki ni shranjena v pomnilniku, zato ko jo želimo uporabiti
|
||||||
.rabimo #len
|
.rabimo #len
|
||||||
|
|
||||||
END zacetek
|
END zacetek
|
||||||
464
ass1/rec.asm
464
ass1/rec.asm
|
|
@ -1,233 +1,233 @@
|
||||||
prog START 0
|
prog START 0
|
||||||
zacetek JSUB sinit .inicializiramo sklad
|
zacetek JSUB sinit .inicializiramo sklad
|
||||||
.beremo iz 0xFA, dokler ne preberemo 0
|
.beremo iz 0xFA, dokler ne preberemo 0
|
||||||
loop3 CLEAR A
|
loop3 CLEAR A
|
||||||
JSUB rdNum
|
JSUB rdNum
|
||||||
COMP #0
|
COMP #0
|
||||||
JEQ halt
|
JEQ halt
|
||||||
|
|
||||||
|
|
||||||
JSUB fact
|
JSUB fact
|
||||||
JSUB num
|
JSUB num
|
||||||
J loop3
|
J loop3
|
||||||
|
|
||||||
halt J halt
|
halt J halt
|
||||||
|
|
||||||
.beri število v A dokler ne naletiš na newline in jo pretvori v int
|
.beri število v A dokler ne naletiš na newline in jo pretvori v int
|
||||||
rdNum STL @stkp
|
rdNum STL @stkp
|
||||||
JSUB spush
|
JSUB spush
|
||||||
STA @stkp
|
STA @stkp
|
||||||
JSUB spush
|
JSUB spush
|
||||||
STB @stkp
|
STB @stkp
|
||||||
JSUB spush
|
JSUB spush
|
||||||
|
|
||||||
CLEAR A
|
CLEAR A
|
||||||
CLEAR B .v B bomo shranili prebran rezultat
|
CLEAR B .v B bomo shranili prebran rezultat
|
||||||
LDS #10 .za množenje
|
LDS #10 .za množenje
|
||||||
loop4 RD #0xFA
|
loop4 RD #0xFA
|
||||||
COMP #0xD .beremo newline
|
COMP #0xD .beremo newline
|
||||||
JEQ nwl
|
JEQ nwl
|
||||||
.else
|
.else
|
||||||
MULR S, B
|
MULR S, B
|
||||||
SUB #0x30 .pretvorimo v int
|
SUB #0x30 .pretvorimo v int
|
||||||
ADDR A, B
|
ADDR A, B
|
||||||
J loop4
|
J loop4
|
||||||
|
|
||||||
nwl RD #0xFA .prebre še 0x0A
|
nwl RD #0xFA .prebre še 0x0A
|
||||||
CLEAR A
|
CLEAR A
|
||||||
RMO B, A
|
RMO B, A
|
||||||
|
|
||||||
JSUB spop
|
JSUB spop
|
||||||
LDB @stkp
|
LDB @stkp
|
||||||
JSUB spop
|
JSUB spop
|
||||||
.LDA @stkp da ne povozimo odgovora?
|
.LDA @stkp da ne povozimo odgovora?
|
||||||
JSUB spop
|
JSUB spop
|
||||||
LDL @stkp
|
LDL @stkp
|
||||||
|
|
||||||
RSUB
|
RSUB
|
||||||
.fakulteta
|
.fakulteta
|
||||||
fact COMP #1
|
fact COMP #1
|
||||||
JGT rec
|
JGT rec
|
||||||
LDA #1 .base case
|
LDA #1 .base case
|
||||||
RSUB
|
RSUB
|
||||||
|
|
||||||
rec STL @stkp
|
rec STL @stkp
|
||||||
JSUB spush
|
JSUB spush
|
||||||
STA @stkp
|
STA @stkp
|
||||||
JSUB spush
|
JSUB spush
|
||||||
STB @stkp
|
STB @stkp
|
||||||
JSUB spush
|
JSUB spush
|
||||||
|
|
||||||
RMO A, B .shrani n v B
|
RMO A, B .shrani n v B
|
||||||
SUB #1 .n-1
|
SUB #1 .n-1
|
||||||
JSUB fact .fact(n-1)
|
JSUB fact .fact(n-1)
|
||||||
MULR B, A .n * fact(n-1)
|
MULR B, A .n * fact(n-1)
|
||||||
|
|
||||||
JSUB spop
|
JSUB spop
|
||||||
LDB @stkp
|
LDB @stkp
|
||||||
JSUB spop
|
JSUB spop
|
||||||
.LDA @stkp da ne povozimo odgovora?
|
.LDA @stkp da ne povozimo odgovora?
|
||||||
JSUB spop
|
JSUB spop
|
||||||
LDL @stkp
|
LDL @stkp
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
RSUB
|
RSUB
|
||||||
|
|
||||||
|
|
||||||
.rutine za sklad
|
.rutine za sklad
|
||||||
.inicializira kazalec na sklad
|
.inicializira kazalec na sklad
|
||||||
sinit STA stkA
|
sinit STA stkA
|
||||||
LDA #stkRESW .inicializiraj stkp
|
LDA #stkRESW .inicializiraj stkp
|
||||||
STA stkp
|
STA stkp
|
||||||
LDA stkA
|
LDA stkA
|
||||||
RSUB
|
RSUB
|
||||||
|
|
||||||
.pusha na sklad, pred klicem te subrutine shrani na sklad kar želiš
|
.pusha na sklad, pred klicem te subrutine shrani na sklad kar želiš
|
||||||
spush STA stkA
|
spush STA stkA
|
||||||
LDA stkp .poveca stkp za 3
|
LDA stkp .poveca stkp za 3
|
||||||
ADD #3
|
ADD #3
|
||||||
STA stkp
|
STA stkp
|
||||||
LDA stkA
|
LDA stkA
|
||||||
RSUB
|
RSUB
|
||||||
|
|
||||||
.popa iz sklada, po koncu te subrutine iz sklada beri kar želš
|
.popa iz sklada, po koncu te subrutine iz sklada beri kar želš
|
||||||
spop STA stkA
|
spop STA stkA
|
||||||
LDA stkp .zmanjsa stkp za 3
|
LDA stkp .zmanjsa stkp za 3
|
||||||
SUB #3
|
SUB #3
|
||||||
STA stkp
|
STA stkp
|
||||||
LDA stkA
|
LDA stkA
|
||||||
RSUB
|
RSUB
|
||||||
|
|
||||||
|
|
||||||
.nl
|
.nl
|
||||||
nl STL @stkp
|
nl STL @stkp
|
||||||
JSUB spush
|
JSUB spush
|
||||||
STB @stkp .shranimo registre
|
STB @stkp .shranimo registre
|
||||||
JSUB spush
|
JSUB spush
|
||||||
STT @stkp
|
STT @stkp
|
||||||
JSUB spush
|
JSUB spush
|
||||||
STS @stkp
|
STS @stkp
|
||||||
JSUB spush
|
JSUB spush
|
||||||
|
|
||||||
|
|
||||||
LDCH newline
|
LDCH newline
|
||||||
WD #1
|
WD #1
|
||||||
LDX #1
|
LDX #1
|
||||||
LDCH newline, X
|
LDCH newline, X
|
||||||
WD #1
|
WD #1
|
||||||
|
|
||||||
.obnovimo registre
|
.obnovimo registre
|
||||||
JSUB spop
|
JSUB spop
|
||||||
LDS @stkp
|
LDS @stkp
|
||||||
JSUB spop
|
JSUB spop
|
||||||
LDT @stkp
|
LDT @stkp
|
||||||
JSUB spop
|
JSUB spop
|
||||||
LDB @stkp
|
LDB @stkp
|
||||||
JSUB spop
|
JSUB spop
|
||||||
LDL @stkp
|
LDL @stkp
|
||||||
|
|
||||||
RSUB
|
RSUB
|
||||||
|
|
||||||
.string
|
.string
|
||||||
string STL @stkp
|
string STL @stkp
|
||||||
JSUB spush
|
JSUB spush
|
||||||
STB @stkp .shranimo registre
|
STB @stkp .shranimo registre
|
||||||
JSUB spush
|
JSUB spush
|
||||||
STT @stkp
|
STT @stkp
|
||||||
JSUB spush
|
JSUB spush
|
||||||
STS @stkp
|
STS @stkp
|
||||||
JSUB spush
|
JSUB spush
|
||||||
STA regA
|
STA regA
|
||||||
|
|
||||||
loop LDB #1
|
loop LDB #1
|
||||||
CLEAR A .da lahko comparamo z 0
|
CLEAR A .da lahko comparamo z 0
|
||||||
LDCH @regA
|
LDCH @regA
|
||||||
COMP #0
|
COMP #0
|
||||||
WD #1
|
WD #1
|
||||||
.add +1 to regA
|
.add +1 to regA
|
||||||
LDA regA
|
LDA regA
|
||||||
ADD #1
|
ADD #1
|
||||||
STA regA
|
STA regA
|
||||||
JGT loop
|
JGT loop
|
||||||
|
|
||||||
LDA regA .obnovimo registre
|
LDA regA .obnovimo registre
|
||||||
JSUB spop
|
JSUB spop
|
||||||
LDS @stkp
|
LDS @stkp
|
||||||
JSUB spop
|
JSUB spop
|
||||||
LDT @stkp
|
LDT @stkp
|
||||||
JSUB spop
|
JSUB spop
|
||||||
LDB @stkp
|
LDB @stkp
|
||||||
JSUB spop
|
JSUB spop
|
||||||
LDL @stkp
|
LDL @stkp
|
||||||
|
|
||||||
RSUB
|
RSUB
|
||||||
.izpiše število zapisano v A na std izhod
|
.izpiše število zapisano v A na std izhod
|
||||||
num STL @stkp
|
num STL @stkp
|
||||||
JSUB spush
|
JSUB spush
|
||||||
STB @stkp .shranimo registre
|
STB @stkp .shranimo registre
|
||||||
JSUB spush
|
JSUB spush
|
||||||
STT @stkp
|
STT @stkp
|
||||||
JSUB spush
|
JSUB spush
|
||||||
STS @stkp
|
STS @stkp
|
||||||
JSUB spush
|
JSUB spush
|
||||||
|
|
||||||
LDX #4 .X steje stevke, 4 je zadnji index arraya velikosti 5
|
LDX #4 .X steje stevke, 4 je zadnji index arraya velikosti 5
|
||||||
LDS #10 .za množenje/deljenje
|
LDS #10 .za množenje/deljenje
|
||||||
LDT #0x30 .za pretvorbo v ascii
|
LDT #0x30 .za pretvorbo v ascii
|
||||||
|
|
||||||
|
|
||||||
loop2 RMO A, B
|
loop2 RMO A, B
|
||||||
DIVR S, B .B = B/10
|
DIVR S, B .B = B/10
|
||||||
MULR S, B .B= B*10
|
MULR S, B .B= B*10
|
||||||
SUBR B, A .A = ostanek
|
SUBR B, A .A = ostanek
|
||||||
ADDR T, A .pretvorimo A v ascii
|
ADDR T, A .pretvorimo A v ascii
|
||||||
STCH digs, X .shranimo ascii ostanek
|
STCH digs, X .shranimo ascii ostanek
|
||||||
|
|
||||||
.zmanjšamo X in primerjamo z #5
|
.zmanjšamo X in primerjamo z #5
|
||||||
RMO X, A
|
RMO X, A
|
||||||
SUB #1
|
SUB #1
|
||||||
RMO A, X
|
RMO A, X
|
||||||
LDA #0
|
LDA #0
|
||||||
COMPR X, A
|
COMPR X, A
|
||||||
|
|
||||||
RMO B, A .premaknemo kar je še potrebno izračunati v A
|
RMO B, A .premaknemo kar je še potrebno izračunati v A
|
||||||
DIVR S, A .A je sedaj naslednja števka
|
DIVR S, A .A je sedaj naslednja števka
|
||||||
|
|
||||||
JEQ loop2
|
JEQ loop2
|
||||||
JGT loop2
|
JGT loop2
|
||||||
|
|
||||||
.kličemo string za izpis
|
.kličemo string za izpis
|
||||||
LDA #digs
|
LDA #digs
|
||||||
JSUB string
|
JSUB string
|
||||||
JSUB nl
|
JSUB nl
|
||||||
|
|
||||||
JSUB spop
|
JSUB spop
|
||||||
LDS @stkp
|
LDS @stkp
|
||||||
JSUB spop
|
JSUB spop
|
||||||
LDT @stkp
|
LDT @stkp
|
||||||
JSUB spop
|
JSUB spop
|
||||||
LDB @stkp
|
LDB @stkp
|
||||||
JSUB spop
|
JSUB spop
|
||||||
LDL @stkp
|
LDL @stkp
|
||||||
|
|
||||||
RSUB
|
RSUB
|
||||||
|
|
||||||
|
|
||||||
.digits za num
|
.digits za num
|
||||||
digs RESB 5 .0 bo prazna za lazje izpisovanje
|
digs RESB 5 .0 bo prazna za lazje izpisovanje
|
||||||
BYTE 0 .konec števke
|
BYTE 0 .konec števke
|
||||||
|
|
||||||
.constante
|
.constante
|
||||||
newline BYTE 0x0D
|
newline BYTE 0x0D
|
||||||
BYTE 0x0A
|
BYTE 0x0A
|
||||||
|
|
||||||
.shramba za string
|
.shramba za string
|
||||||
regA WORD 0
|
regA WORD 0
|
||||||
|
|
||||||
.podatki za sklad
|
.podatki za sklad
|
||||||
stkp WORD 0
|
stkp WORD 0
|
||||||
stkA WORD 0
|
stkA WORD 0
|
||||||
stkRESW RESW 1000
|
stkRESW RESW 1000
|
||||||
|
|
||||||
END prog
|
END prog
|
||||||
|
|
@ -1,38 +1,38 @@
|
||||||
scr START 0
|
scr START 0
|
||||||
LDCH txt
|
LDCH txt
|
||||||
+STCH screen
|
+STCH screen
|
||||||
LDX #3
|
LDX #3
|
||||||
+STCH screen, X
|
+STCH screen, X
|
||||||
|
|
||||||
JSUB scrcfill
|
JSUB scrcfill
|
||||||
|
|
||||||
JSUB scrclear
|
JSUB scrclear
|
||||||
|
|
||||||
halt J halt
|
halt J halt
|
||||||
|
|
||||||
scrclear LDCH #0
|
scrclear LDCH #0
|
||||||
LDS #scrlen
|
LDS #scrlen
|
||||||
LDX #0
|
LDX #0
|
||||||
loop +STCH screen, X
|
loop +STCH screen, X
|
||||||
TIXR S
|
TIXR S
|
||||||
JLT loop
|
JLT loop
|
||||||
|
|
||||||
RSUB
|
RSUB
|
||||||
|
|
||||||
|
|
||||||
scrcfill
|
scrcfill
|
||||||
LDS #scrlen
|
LDS #scrlen
|
||||||
LDX #0
|
LDX #0
|
||||||
loop2 +STCH screen, X
|
loop2 +STCH screen, X
|
||||||
TIXR S
|
TIXR S
|
||||||
JLT loop2
|
JLT loop2
|
||||||
|
|
||||||
RSUB
|
RSUB
|
||||||
|
|
||||||
txt BYTE C'hi'
|
txt BYTE C'hi'
|
||||||
screen EQU 0x0B800
|
screen EQU 0x0B800
|
||||||
scrcols EQU 80
|
scrcols EQU 80
|
||||||
scrrows EQU 25
|
scrrows EQU 25
|
||||||
scrlen EQU 2000
|
scrlen EQU 2000
|
||||||
|
|
||||||
END scr
|
END scr
|
||||||
|
|
@ -1,33 +1,33 @@
|
||||||
prog START 0
|
prog START 0
|
||||||
JSUB sinit
|
JSUB sinit
|
||||||
LDT #4
|
LDT #4
|
||||||
STT @stkp
|
STT @stkp
|
||||||
JSUB spush
|
JSUB spush
|
||||||
JSUB spop
|
JSUB spop
|
||||||
CLEAR T
|
CLEAR T
|
||||||
LDT @stkp
|
LDT @stkp
|
||||||
|
|
||||||
halt J halt
|
halt J halt
|
||||||
|
|
||||||
.rutine za sklad
|
.rutine za sklad
|
||||||
sinit LDA #stkRESW .inicializiraj stkp
|
sinit LDA #stkRESW .inicializiraj stkp
|
||||||
STA stkp
|
STA stkp
|
||||||
RSUB
|
RSUB
|
||||||
|
|
||||||
spush LDA stkp .poveca stkp za 3
|
spush LDA stkp .poveca stkp za 3
|
||||||
ADD #3
|
ADD #3
|
||||||
STA stkp
|
STA stkp
|
||||||
RSUB
|
RSUB
|
||||||
|
|
||||||
spop LDA stkp .zmanjsa stkp za 3
|
spop LDA stkp .zmanjsa stkp za 3
|
||||||
SUB #3
|
SUB #3
|
||||||
STA stkp
|
STA stkp
|
||||||
RSUB
|
RSUB
|
||||||
|
|
||||||
.podatki za sklad
|
.podatki za sklad
|
||||||
stkp WORD 0
|
stkp WORD 0
|
||||||
stkRESW WORD 1000
|
stkRESW WORD 1000
|
||||||
|
|
||||||
END prog
|
END prog
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
32
ass2/SICocaml/SICXE/SICXE.opam
Normal file
32
ass2/SICocaml/SICXE/SICXE.opam
Normal file
|
|
@ -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 <maintainer@example.com>"]
|
||||||
|
authors: ["Author Name <author@example.com>"]
|
||||||
|
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)"]
|
||||||
BIN
ass2/SICocaml/SICXE/_build/.db
Normal file
BIN
ass2/SICocaml/SICXE/_build/.db
Normal file
Binary file not shown.
BIN
ass2/SICocaml/SICXE/_build/.digest-db
Normal file
BIN
ass2/SICocaml/SICXE/_build/.digest-db
Normal file
Binary file not shown.
1
ass2/SICocaml/SICXE/_build/.filesystem-clock
Normal file
1
ass2/SICocaml/SICXE/_build/.filesystem-clock
Normal file
|
|
@ -0,0 +1 @@
|
||||||
|
<dummy>
|
||||||
0
ass2/SICocaml/SICXE/_build/.lock
Normal file
0
ass2/SICocaml/SICXE/_build/.lock
Normal file
2
ass2/SICocaml/SICXE/_build/default/.dune/configurator
Normal file
2
ass2/SICocaml/SICXE/_build/default/.dune/configurator
Normal file
|
|
@ -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))
|
||||||
1
ass2/SICocaml/SICXE/_build/default/.dune/configurator.v2
Normal file
1
ass2/SICocaml/SICXE/_build/default/.dune/configurator.v2
Normal file
|
|
@ -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))))
|
||||||
0
ass2/SICocaml/SICXE/_build/default/META.SICXE
Normal file
0
ass2/SICocaml/SICXE/_build/default/META.SICXE
Normal file
4
ass2/SICocaml/SICXE/_build/default/SICXE.dune-package
Normal file
4
ass2/SICocaml/SICXE/_build/default/SICXE.dune-package
Normal file
|
|
@ -0,0 +1,4 @@
|
||||||
|
(lang dune 3.20)
|
||||||
|
(name SICXE)
|
||||||
|
(sections (lib .) (bin ../../bin))
|
||||||
|
(files (lib (META dune-package opam)) (bin (SICXE)))
|
||||||
32
ass2/SICocaml/SICXE/_build/default/SICXE.opam
Normal file
32
ass2/SICocaml/SICXE/_build/default/SICXE.opam
Normal file
|
|
@ -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 <maintainer@example.com>"]
|
||||||
|
authors: ["Author Name <author@example.com>"]
|
||||||
|
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)"]
|
||||||
BIN
ass2/SICocaml/SICXE/_build/default/bin/.merlin-conf/exe-main
Normal file
BIN
ass2/SICocaml/SICXE/_build/default/bin/.merlin-conf/exe-main
Normal file
Binary file not shown.
1
ass2/SICocaml/SICXE/_build/default/bin/main.ml
Normal file
1
ass2/SICocaml/SICXE/_build/default/bin/main.ml
Normal file
|
|
@ -0,0 +1 @@
|
||||||
|
let () = print_endline "Hello, World!"
|
||||||
1
ass2/SICocaml/SICXE/_build/default/bin/main.mli
Normal file
1
ass2/SICocaml/SICXE/_build/default/bin/main.mli
Normal file
|
|
@ -0,0 +1 @@
|
||||||
|
(* Auto-generated by Dune *)
|
||||||
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
|
|
@ -0,0 +1 @@
|
||||||
|
sICXE__OpcodeTable
|
||||||
|
|
@ -0,0 +1 @@
|
||||||
|
lib/decoder.ml: Char Hashtbl OpcodeTable
|
||||||
|
|
@ -0,0 +1,2 @@
|
||||||
|
sICXE__Decoder
|
||||||
|
sICXE__OpcodeTable
|
||||||
|
|
@ -0,0 +1 @@
|
||||||
|
lib/izvajalnik.ml: Bytes Char Decoder OpcodeTable Printf
|
||||||
|
|
@ -0,0 +1 @@
|
||||||
|
lib/opcodeTable.ml: Hashtbl
|
||||||
BIN
ass2/SICocaml/SICXE/_build/default/lib/.merlin-conf/lib-SICXE
Normal file
BIN
ass2/SICocaml/SICXE/_build/default/lib/.merlin-conf/lib-SICXE
Normal file
Binary file not shown.
10
ass2/SICocaml/SICXE/_build/default/lib/decoder.ml
Normal file
10
ass2/SICocaml/SICXE/_build/default/lib/decoder.ml
Normal file
|
|
@ -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"
|
||||||
|
|
||||||
228
ass2/SICocaml/SICXE/_build/default/lib/izvajalnik.ml
Normal file
228
ass2/SICocaml/SICXE/_build/default/lib/izvajalnik.ml
Normal file
|
|
@ -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
|
||||||
159
ass2/SICocaml/SICXE/_build/default/lib/opcodeTable.ml
Normal file
159
ass2/SICocaml/SICXE/_build/default/lib/opcodeTable.ml
Normal file
|
|
@ -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"
|
||||||
10
ass2/SICocaml/SICXE/_build/default/lib/sICXE.ml-gen
Normal file
10
ass2/SICocaml/SICXE/_build/default/lib/sICXE.ml-gen
Normal file
|
|
@ -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
|
||||||
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
BIN
ass2/SICocaml/SICXE/_build/default/test/test_SICXE.exe
Normal file
BIN
ass2/SICocaml/SICXE/_build/default/test/test_SICXE.exe
Normal file
Binary file not shown.
0
ass2/SICocaml/SICXE/_build/default/test/test_SICXE.ml
Normal file
0
ass2/SICocaml/SICXE/_build/default/test/test_SICXE.ml
Normal file
1
ass2/SICocaml/SICXE/_build/default/test/test_SICXE.mli
Normal file
1
ass2/SICocaml/SICXE/_build/default/test/test_SICXE.mli
Normal file
|
|
@ -0,0 +1 @@
|
||||||
|
(* Auto-generated by Dune *)
|
||||||
1
ass2/SICocaml/SICXE/_build/install/default/lib/SICXE/META
Symbolic link
1
ass2/SICocaml/SICXE/_build/install/default/lib/SICXE/META
Symbolic link
|
|
@ -0,0 +1 @@
|
||||||
|
../../../../default/META.SICXE
|
||||||
|
|
@ -0,0 +1 @@
|
||||||
|
../../../../default/SICXE.dune-package
|
||||||
1
ass2/SICocaml/SICXE/_build/install/default/lib/SICXE/opam
Symbolic link
1
ass2/SICocaml/SICXE/_build/install/default/lib/SICXE/opam
Symbolic link
|
|
@ -0,0 +1 @@
|
||||||
|
../../../../default/SICXE.opam
|
||||||
67
ass2/SICocaml/SICXE/_build/log
Normal file
67
ass2/SICocaml/SICXE/_build/log
Normal file
|
|
@ -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)
|
||||||
4
ass2/SICocaml/SICXE/bin/dune
Normal file
4
ass2/SICocaml/SICXE/bin/dune
Normal file
|
|
@ -0,0 +1,4 @@
|
||||||
|
(executable
|
||||||
|
(public_name SICXE)
|
||||||
|
(name main)
|
||||||
|
(libraries SICXE))
|
||||||
1
ass2/SICocaml/SICXE/bin/main.ml
Normal file
1
ass2/SICocaml/SICXE/bin/main.ml
Normal file
|
|
@ -0,0 +1 @@
|
||||||
|
let () = print_endline "Hello, World!"
|
||||||
26
ass2/SICocaml/SICXE/dune-project
Normal file
26
ass2/SICocaml/SICXE/dune-project
Normal file
|
|
@ -0,0 +1,26 @@
|
||||||
|
(lang dune 3.20)
|
||||||
|
|
||||||
|
(name SICXE)
|
||||||
|
|
||||||
|
(generate_opam_files true)
|
||||||
|
|
||||||
|
(source
|
||||||
|
(github username/reponame))
|
||||||
|
|
||||||
|
(authors "Author Name <author@example.com>")
|
||||||
|
|
||||||
|
(maintainers "Maintainer Name <maintainer@example.com>")
|
||||||
|
|
||||||
|
(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
|
||||||
10
ass2/SICocaml/SICXE/lib/decoder.ml
Normal file
10
ass2/SICocaml/SICXE/lib/decoder.ml
Normal file
|
|
@ -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"
|
||||||
|
|
||||||
2
ass2/SICocaml/SICXE/lib/dune
Normal file
2
ass2/SICocaml/SICXE/lib/dune
Normal file
|
|
@ -0,0 +1,2 @@
|
||||||
|
(library
|
||||||
|
(name SICXE))
|
||||||
228
ass2/SICocaml/SICXE/lib/izvajalnik.ml
Normal file
228
ass2/SICocaml/SICXE/lib/izvajalnik.ml
Normal file
|
|
@ -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
|
||||||
159
ass2/SICocaml/SICXE/lib/opcodeTable.ml
Normal file
159
ass2/SICocaml/SICXE/lib/opcodeTable.ml
Normal file
|
|
@ -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"
|
||||||
2
ass2/SICocaml/SICXE/test/dune
Normal file
2
ass2/SICocaml/SICXE/test/dune
Normal file
|
|
@ -0,0 +1,2 @@
|
||||||
|
(test
|
||||||
|
(name test_SICXE))
|
||||||
0
ass2/SICocaml/SICXE/test/test_SICXE.ml
Normal file
0
ass2/SICocaml/SICXE/test/test_SICXE.ml
Normal file
|
|
@ -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 ...)*)
|
(*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 byte2 = Char.code (readMem state 1) in
|
||||||
let highNibble = (byte2 land 0xF0) lsr 4 in (*pridobi prvi nibble*)
|
let highNibble = (byte2 land 0xF0) lsr 4 in (*pridobi prvi nibble*)
|
||||||
let lowNibble = byte2 land 0x0F in (*pridobi drugi 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;}
|
e = (byte2 lsr 4) land 1;}
|
||||||
|
|
||||||
|
|
||||||
|
let getAddress (state : state) : int =
|
||||||
|
42
|
||||||
|
|
||||||
|
|
||||||
(*execute format 1*)
|
(*execute format 1*)
|
||||||
let executeFormat1 (state : state) (mnemonic : OpcodeTable.mnemonic) : unit =
|
let executeFormat1 (state : state) (mnemonic : OpcodeTable.mnemonic) : unit =
|
||||||
match mnemonic with
|
match mnemonic with
|
||||||
|
|
@ -78,12 +82,13 @@ let executeFormat1 (state : state) (mnemonic : OpcodeTable.mnemonic) : unit =
|
||||||
| NORM -> notImplemented "NORM"
|
| NORM -> notImplemented "NORM"
|
||||||
| SIO -> notImplemented "SIO"
|
| SIO -> notImplemented "SIO"
|
||||||
| TIO -> notImplemented "TIO"
|
| 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*)
|
(*execute format 2*)
|
||||||
let executeFormat2 (state: state) (mnemonic : OpcodeTable.mnemonic) : unit =
|
let executeFormat2 (state: state) (mnemonic : OpcodeTable.mnemonic) : unit =
|
||||||
let (r1, r2) = readFormat2Byte2 state in
|
let (r1, r2) = readR1R2 state in
|
||||||
match mnemonic with
|
match mnemonic with
|
||||||
| ADDR -> notImplemented "ADD" (*when implemented: -> add state r1 r2*)
|
| ADDR -> notImplemented "ADD" (*when implemented: -> add state r1 r2*)
|
||||||
| CLEAR -> notImplemented "CLEAR"
|
| CLEAR -> notImplemented "CLEAR"
|
||||||
|
|
@ -96,18 +101,117 @@ let executeFormat2 (state: state) (mnemonic : OpcodeTable.mnemonic) : unit =
|
||||||
| SUBR -> notImplemented "F2"
|
| SUBR -> notImplemented "F2"
|
||||||
| SVC -> notImplemented "F2"
|
| SVC -> notImplemented "F2"
|
||||||
| TIXR -> 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 executeFormat3_4 (state : state) (mnemonic : OpcodeTable.mnemonic) : unit =
|
||||||
let nixbpe = getNIXBPE state in
|
let nixbpe = getNIXBPE state in
|
||||||
match nixbpe.e with
|
match nixbpe.e with
|
||||||
| 0 -> executeFormat3 state
|
| 0 -> executeFormat3 state nixbpe mnemonic
|
||||||
| 1 -> executeFormat4 state
|
| 1 -> executeFormat4 state nixbpe mnemonic
|
||||||
| _ -> failwith "invalid computation of nxbpe"
|
| _ -> failwith "invalid computation of nxbpe"
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
26
hello.asm
26
hello.asm
|
|
@ -1,13 +1,13 @@
|
||||||
.koda
|
.koda
|
||||||
hello START 0
|
hello START 0
|
||||||
LDA n
|
LDA n
|
||||||
LDB #9
|
LDB #9
|
||||||
MULR A, B
|
MULR A, B
|
||||||
STA out
|
STA out
|
||||||
WD out
|
WD out
|
||||||
halt J halt
|
halt J halt
|
||||||
|
|
||||||
.podatki
|
.podatki
|
||||||
n WORD 0x000002
|
n WORD 0x000002
|
||||||
out RESW 1
|
out RESW 1
|
||||||
END hello
|
END hello
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue