-
Notifications
You must be signed in to change notification settings - Fork 17
/
Copy pathAssemblySimulator.java
48 lines (46 loc) · 1.04 KB
/
AssemblySimulator.java
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
import java.io.*;
class Solution
{
public static void main(String ar[])
{
try
{
InputStreamReader isr=new InputStreamReader(System.in);
BufferedReader br=new BufferedReader(isr);
int n=Integer.parseInt(br.readLine(),16);
System.out.println(n);
int a[]=new int[n];
String str;
while((str=br.readLine()).length()!=0)
{
String codes[]=str.split(" ");
int index=0;
if(codes.length==3)
index=1;
else
{
if(codes[index].equals("PRINT"))
{
String operands[]=codes[index+1].split(",");
if(operands.length==1)
{
System.out.print(a[Integer.parseInt(codes[index+1],16)]);
System.out.print("");
}
else
{
int low=Integer.parseInt(operands[0],16);
int high=Integer.parseInt(operands[1],16);
for(int i=low;i<high;i++)
System.out.print(a[i]+" ");
System.out.print(a[high]);
}
}
else if(codes[0].equals("MOVE"))
{
}
}
}
}catch(Exception e){}
}
}