-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathProcesor RISC.java
More file actions
87 lines (86 loc) · 2.78 KB
/
Procesor RISC.java
File metadata and controls
87 lines (86 loc) · 2.78 KB
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
77
78
79
80
81
82
83
84
85
86
87
public class Registre{
int adresa;
int valoare;
Registre(int adresa, int valoare){
this.adresa=adresa;
this.valoare=valoare;
}
}
import java.util.*;
public class ECCPR{
public static void main(String [] args){
Scanner sc= new Scanner(System.in);
ArrayList<Registre>list=new ArrayList<>();
int n=sc.nextInt();
int x,y,z;
int a1=0,a2=0,ver=0,a3=0;
String comanda;
for(int i=0;i<n;i++){
comanda=sc.next();
if(comanda.equals("lconst")){
x=sc.nextInt();
y=sc.nextInt();
for(int j=0;j<list.size();j++){
if(list.get(j).adresa==x){
ver=1;
list.get(j).valoare=y;
}
}
if(ver==0){
list.add(new Registre(x,y));
}ver=0;
}
else if(comanda.equals("print")){
x=sc.nextInt();
for(int j=0;j<list.size();j++){
if(list.get(j).adresa==x){
System.out.println(list.get(j).valoare);
}
}
}
else{
x=sc.nextInt();
y=sc.nextInt();
z=sc.nextInt();
for(int j=0;j<list.size();j++){
if(list.get(j).adresa==y){
a1=list.get(j).valoare;
}
if(list.get(j).adresa==z){
a2=list.get(j).valoare;
}
if(list.get(j).adresa==x){
a3=j;
ver=1;
}
}
if(comanda.equals("add")){
if(ver==1){
list.get(a3).valoare=a1+a2;
}else{
list.add(new Registre(x,a1+a2));
}
}
if(comanda.equals("mul")){
if(ver==1){
list.get(a3).valoare=a1*a2;
}else{
list.add(new Registre(x,a1*a2));
}
}
if(comanda.equals("div")){
if(a2!=0){
if(ver==1){
list.get(a3).valoare=a1/a2;
}else{
list.add(new Registre(x,a1/a2));
}
}else{
System.out.println("Exception: line "+(i+1));
}
}
ver=0;
}
}
}
}