Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- lmc_load(Filename, Result):- open(Filename,read,Stream), read_string(Stream,_,String), split_string(String, "\n","\r",Lines), close(Stream), riga(Lines, Result).
- lmc_run(Filename, Input, Output):-lmc_load(Filename, Mem).% execution_loop(state(0, 0, Mem,Input, [], 0), Output).
- riga([], []).
- riga([X|L], [Somma|Result] ):- split_string(X," ", " ", [F, G|_]), string_upper(F, String), calc(String, T), T=<800, number_string(M, G), Somma is M+ T, riga(L, Result).
- riga([X|L], [Somma|Result] ):- split_string(X," ", " ", [F|_]), string_upper(F, String), calc(String, T), T>800, Somma is T, riga(L, Result).
- calc("ADD", X) :- X is 100.
- calc("SUB", X) :- X is 200.
- calc("STA", X) :- X is 300.
- calc("LDA", X) :- X is 500.
- calc("BRA", X) :- X is 600.
- calc("BRZ", X) :- X is 700.
- calc("BRP", X) :- X is 800.
- calc("INP", X) :- X is 901.
- calc("OUT", X) :- X is 902.
- calc("HLT", X) :- X is 000.
- calc(_, X) :- X is 999.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement