-
Notifications
You must be signed in to change notification settings - Fork 3
/
Main.hs
43 lines (34 loc) · 1.19 KB
/
Main.hs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
import Microprogram
import qualified Simulation as S
import qualified Listing as L
import Data.IntMap.Strict (IntMap)
import qualified Data.IntMap.Strict as Map
program :: Microprogram m => Register m -> Register m -> m ()
program reg0 reg1 = do
writeMemory 100 200
writeMemory 100 200
writeRegister reg0 1234
let programAddress = 10000
writeRegister pc programAddress
writeMemory (programAddress + 1) 100
writeMemory (programAddress + 2) 222
load reg1
programSimulation :: S.Simulation ()
programSimulation =
program (S.R 0) (S.R 1)
programListing :: L.Listing ()
programListing =
program (L.Register "0") (L.Register "1")
processor = S.Processor (Map.empty) (Map.empty)
main = do
putStrLn "==============="
putStrLn "=== Listing ==="
putStrLn "==============="
putStrLn $ L.listing programListing
putStrLn "=================="
putStrLn "=== Simulation ==="
putStrLn "=================="
putStrLn $ "\nInitial processor:\n" ++ show processor ++ "\n"
let (value, newProcessor) = S.simulate programSimulation processor
putStrLn $ "Value = " ++ show value ++ "\n"
putStrLn $ "New processor:\n" ++ show newProcessor ++ "\n"