-
Notifications
You must be signed in to change notification settings - Fork 0
/
Instrucoes.java
123 lines (74 loc) · 2.4 KB
/
Instrucoes.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
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
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
import java.io.BufferedReader;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.*;
import java.util.*;
public class Instrucoes {
BlocoDeControleDeProcessos bcp;
int quantum;
int cont;
private int tempo, instrucoesExecutadas;
public Instrucoes(BlocoDeControleDeProcessos bcp, int quantum){
this.bcp = bcp;
this.quantum = quantum;
}
//Compara as instrucoes e executa os comandos
public void processaInstrucoes() throws Exception{
System.out.println("\n-------->>\n\t EXEC. PROGRAMA: " + bcp.getNomePrograma());
instrucoesExecutadas = 0;
for(int i = 0; i < quantum; i++){
//Obtem a instrucao a ser executada
String instrucao = bcp.getInstrucoesDoPrograma().get(bcp.getContador());
System.out.println("\t\tINSTRUCAO EXECUTADA: " + instrucao);
bcp.incrementaContador();
instrucoesExecutadas++;
if (instrucao.startsWith("X"))
this.instrucaoX(Integer.parseInt(instrucao.substring(instrucao.indexOf("=")+1, instrucao.length())));
if (instrucao.startsWith("Y"))
this.instrucaoY(Integer.parseInt(instrucao.substring(instrucao.indexOf("=")+1, instrucao.length())));
if (instrucao.equals("E/S")){
if(cont == 0){
this.tempo = i+1;
this.cont++;
}
chamadaAoSO();
}
if (instrucao.equals("COM")) instrucaoCOM();
if(instrucao.equals("SAIDA")){
if(cont == 0){
this.tempo = i+1;
this.cont++;
System.out.println("\nTERMINOU ->>>> " + "NOME: " + bcp.getNomePrograma() + " TEMPO: " + (bcp.getTempoEspera()+this.tempo)+" \n");
}
throw new Exception("SAIDA");
}
}
if(cont == 0) this.tempo = quantum;
this.cont = 0;
}
//1° Instrucao de atribuicao no registrador
public void instrucaoX(int x){
bcp.setRegistradorX(x);
}
public void instrucaoY(int y){
bcp.setRegistradorY(y);
}
//2° Instrucao Chamada ao SO
public void chamadaAoSO() throws Exception{
bcp.setEstadoProcesso("Bloqueado");
throw new Exception("E/S");
}
//3° Tarefa executada pela maquina
//Pode executar um comando comum e simples
public void instrucaoCOM(){}
public boolean terminou(){
return bcp.getContador() >= bcp.getInstrucoesDoPrograma().size();
}
public int getTempo(){
return this.tempo;
}
public int getInstrucoesExecutadas(){
return instrucoesExecutadas;
}
}