FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
processinator/src/main/java/Sim.java at master · andreer/processinator · GitHub
andreer
/
processinator
Public
Notifications
You must be signed in to change notification settings
Fork
0
Star
2
Code
Issues
0
Pull requests
0
Actions
Projects
Security and quality
0
Insights
Additional navigation options
Code
Issues
Pull requests
Actions
Projects
Security and quality
Insights
Expand file tree
Breadcrumbs
processinator
/
src
/
main
/
java
/
Sim.java
Copy path
More file actions
More file actions
Latest commit
History
History
History
76 lines (59 loc) · 1.84 KB
Breadcrumbs
processinator
/
src
/
main
/
java
/
Sim.java
Copy path
File metadata and controls
76 lines (59 loc) · 1.84 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
import
java
.
io
.
BufferedOutputStream
;
import
java
.
io
.
IOException
;
import
java
.
io
.
OutputStreamWriter
;
import
java
.
io
.
Writer
;
public
class
Sim
{
private
final
int
[]
mem
=
new
int
[
1
<<
24
];
// 64M
{
mem
[
0
] =
0xd0ed004B
;
// print k
mem
[
1
] =
0xd0ed0041
;
// print a
mem
[
2
] =
0xd0ed004B
;
// print k
mem
[
3
] =
0xd0ed0045
;
// print e
mem
[
4
] =
0xf0ed0000
;
// jmp 0
}
private
final
static
int
ZR
=
13
;
private
final
static
int
PC
=
15
;
private
final
static
int
OUT
=
13
;
private
final
static
int
MR
=
12
;
private
final
static
int
AR
=
14
;
private
final
static
int
IMM
=
14
;
public
static
void
main
(
String
[]
args
)
throws
IOException
{
new
Sim
().
go
();
}
private
void
go
()
throws
IOException
{
BufferedOutputStream
out
=
new
BufferedOutputStream
(
System
.
out
);
Writer
writer
=
new
OutputStreamWriter
(
out
);
int
[]
regs
=
new
int
[
16
];
int
[]
alu
=
new
int
[
4
];
while
(
true
) {
execute
(
writer
,
regs
,
alu
);
}
}
private
void
execute
(
Writer
writer
,
int
[]
regs
,
int
[]
alu
)
throws
IOException
{
int
ir
;
regs
[
ZR
] =
0
;
regs
[
OUT
] =
0
;
ir
=
mem
[
regs
[
PC
]];
regs
[
MR
] =
mem
[
regs
[
AR
]];
int
imm
=
ir
&
0xffff
;
regs
[
IMM
] =
imm
;
int
src1
=
ir
>>
16
&
0xF
;
int
src2
=
ir
>>
20
&
0xF
;
int
op
=
ir
>>
24
&
0xF
;
int
dst
=
ir
>>
28
&
0xF
;
int
src1v
=
regs
[
src1
];
int
src2v
=
regs
[
src2
];
alu
[
0
] =
src1v
+
src2v
;
alu
[
1
] = -
src1v
;
alu
[
2
] =
src1v
&
src2v
;
alu
[
3
] =
src1v
|
src2v
;
int
res
=
alu
[
op
];
regs
[
dst
] =
res
;
char
c
= (
char
) (
regs
[
OUT
] &
0x7f
);
if
(
c
!=
0
)
writer
.
append
(
c
);
if
(
dst
!=
PC
)
regs
[
PC
]++;
regs
[
PC
] = (
regs
[
PC
]) &
0xffffff
;
}
}
Back
|
FazBrowse Home
|
New Git URL