Skip to content
Open

Ze #18

Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
165 changes: 146 additions & 19 deletions Processador.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,36 +6,163 @@
import Pipeline.IFID;
import Pipeline.MEMWB;
import Pipeline.Pipeline;
import UnidadeFuncionais.BancoRegistradores;
import UnidadeFuncionais.Memoria;
import java.awt.Font;
import java.io.File;
import java.io.FileWriter;
import java.io.IOException;
import javax.swing.*;

public class Processador {


public static void main(String[] args){

AssemblyParser.parseFile("exemplo_copy.asm");
Pipeline.setPc(0);
BancoRegistradores registersl = new BancoRegistradores();
Memoria memory = new Memoria();
try{
String[] memoria = memory.getMemoria();
File arquivo = new File("saida.out");
arquivo.createNewFile();
FileWriter fw = new FileWriter ("saida.out");
int regs[]=registersl.getRegisters();

//Linhas de código para a interface(Swing)
JFrame frame = new JFrame();
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setSize(1400, 1000);
JPanel painel = new JPanel();
painel.setSize(250, 100);
painel.setLayout(new BoxLayout(painel, BoxLayout.Y_AXIS));

for(int i = 0; i < 10; i++){
Pipeline.runCycle();
AssemblyParser.parseFile("exemplo.asm");
Pipeline.setPc(0);

for(int i = 0; i < 7; i++){
Pipeline.runCycle();

printPipelineStages();

fw.write("\n=== Pipeline Stages " + "ciclo " + i + " ===" + "\n");
fw.write(("IF/ID: " + Decoder.decodeInstruction(IFID.getIFIDInstruction())) + "\n");
fw.write(("ID/EX: " + Decoder.decodeInstruction(IDEX.getIDEXInstruction())) + "\n");
fw.write(("EX/MEM: " + Decoder.decodeInstruction(EXMEM.getEXMEMInstruction())) + "\n");
fw.write(("MEM/WB: " + Decoder.decodeInstruction(MEMWB.getMEMWBInstruction())) + "\n");
fw.write("=====================" + "\n");

}
JLabel cabecalho = new JLabel();
cabecalho.setText("\n=== Pipeline Stages " + "ciclo " + i + " ===" + "\n");
cabecalho.setFont(new Font("Arial", Font.BOLD, 12));
JLabel IFIDl = new JLabel();
IFIDl.setText(("IF/ID: " + Decoder.decodeInstruction(IFID.getIFIDInstruction())) + "\n");
IFIDl.setFont(new Font("Arial", Font.BOLD, 12));
JLabel IDEXl = new JLabel();
IDEXl.setText(("ID/EX: " + Decoder.decodeInstruction(IDEX.getIDEXInstruction())) + "\n");
IDEXl.setFont(new Font("Arial", Font.BOLD, 12));
JLabel EXMEMl = new JLabel();
EXMEMl.setText(("EX/MEM: " + Decoder.decodeInstruction(EXMEM.getEXMEMInstruction())) + "\n");
EXMEMl.setFont(new Font("Arial", Font.BOLD, 12));
JLabel MEMWBl = new JLabel();
MEMWBl.setText(("MEM/WB: " + Decoder.decodeInstruction(MEMWB.getMEMWBInstruction())) + "\n");
MEMWBl.setFont(new Font("Arial", Font.BOLD, 12));
JLabel rodape = new JLabel();
rodape.setText("=====================" + "\n");
rodape.setFont(new Font("Arial", Font.BOLD, 12));
painel.add(cabecalho); painel.add(IFIDl); painel.add(IDEXl); painel.add(EXMEMl); painel.add(MEMWBl); painel.add(rodape);

//System.out.println("=== Pipeline Stages " + "ciclo " + i + " ===" + "\n");
//System.out.println(("IF/ID: " + Decoder.decodeInstruction(IFID.getIFIDInstruction())) + "\n");
//System.out.println(("ID/EX: " + Decoder.decodeInstruction(IDEX.getIDEXInstruction())) + "\n");
//System.out.println(("EX/MEM: " + Decoder.decodeInstruction(EXMEM.getEXMEMInstruction())) + "\n");
//System.out.println(("MEM/WB: " + Decoder.decodeInstruction(MEMWB.getMEMWBInstruction())) + "\n");
//System.out.println("=====================" + "\n");
//System.out.println(i);

}
public static void printPipelineStages() {


System.out.println("=== Pipeline Stages ===");
System.out.println("IF/ID: " + Decoder.decodeInstruction(IFID.getIFIDInstruction()) + " " + IDEX.getRs1() + " " + IDEX.getImmediate());
System.out.println("ID/EX: " + Decoder.decodeInstruction(IDEX.getIDEXInstruction()));
System.out.println("EX/MEM: " + Decoder.decodeInstruction(EXMEM.getEXMEMInstruction()));
System.out.println("MEM/WB: " + Decoder.decodeInstruction(MEMWB.getMEMWBInstruction()));
System.out.println("=====================");
}

fw.write("=== Registradores(ciclo " + i + "): ===" + "\n");
for(int j=0; j<32; j++){
//if(regs[j]!=0){
fw.write("Registradores[" + j +"] = " + regs[j] + "\n");
fw.write("=====================" + "\n");
//}
}
fw.write("\n");

fw.write("=== Memória(ciclo " + i + "): ===" + "\n");
for (int k=0; k<1000; k++){
if (memoria[k]!=null){
String linha = memoria[k];
int conv = Integer.parseInt(linha, 2);
if(conv!=0){
String convhex = Integer.toHexString(conv).toUpperCase();
fw.write(convhex + "; " );
}
}
}
fw.write("\n");
fw.write("=====================" + "\n");
//try{
//Thread.sleep(500);
//}
//catch(Exception e){
//System.out.println("Error!");
//}


}
JLabel cabecalhoReg = new JLabel();
cabecalhoReg.setText("=== Registradores ===" + "\n");
cabecalhoReg.setFont(new Font("Arial", Font.BOLD, 10));
JLabel bancoReg1 = new JLabel();
JLabel bancoReg2 = new JLabel();
JLabel bancoReg3 = new JLabel();
JLabel bancoReg4 = new JLabel();
String linhaLabel1 = "";
String linhaLabel2 = "";
String linhaLabel3 = "";
String linhaLabel4 = "";
for(int j=0; j<32; j++){
if(j<8){
linhaLabel1 = (linhaLabel1 + "Registradores[" + j +"] = " + regs[j] + "; ");
}
if(j>=8 && j<16){
linhaLabel2 = (linhaLabel2 + "Registradores[" + j +"] = " + regs[j] + "; ");
}
if(j>=16 && j<24){
linhaLabel3 = (linhaLabel3 + "Registradores[" + j +"] = " + regs[j] + "; ");
}
if(j>=24){
linhaLabel4 = (linhaLabel4 + "Registradores[" + j +"] = " + regs[j] + "; ");
}
}
bancoReg1.setText(linhaLabel1);
bancoReg1.setFont(new Font("Arial", Font.BOLD, 12));
bancoReg2.setText(linhaLabel2);
bancoReg2.setFont(new Font("Arial", Font.BOLD, 12));
bancoReg3.setText(linhaLabel3);
bancoReg3.setFont(new Font("Arial", Font.BOLD, 12));
bancoReg4.setText(linhaLabel4);
bancoReg4.setFont(new Font("Arial", Font.BOLD, 12));
painel.add(cabecalhoReg);
painel.add(bancoReg1);
painel.add(bancoReg2);
painel.add(bancoReg3);
painel.add(bancoReg4);
fw.close();
frame.add(painel);
frame.setVisible(true);

//public static void printPipelineStages() {
//cabecalho.setText("=== Pipeline Stages ===");
//System.out.println("IF/ID: " + Decoder.decodeInstruction(IFID.getIFIDInstruction()));
//System.out.println("ID/EX: " + Decoder.decodeInstruction(IDEX.getIDEXInstruction()));
//System.out.println("EX/MEM: " + Decoder.decodeInstruction(EXMEM.getEXMEMInstruction()));
//System.out.println("MEM/WB: " + Decoder.decodeInstruction(MEMWB.getMEMWBInstruction()));
//System.out.println("=====================");
//}
}
catch(IOException e){
System.out.println("An error occurred.");
e.printStackTrace();
}
System.out.println("END!");
}
}
4 changes: 3 additions & 1 deletion UnidadeFuncionais/BancoRegistradores.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,9 @@ public class BancoRegistradores {
registers[0] = 0;
}


public static int[] getRegisters(){
return (registers);
}
public static int getRegisterValue(int registerNumber) {
if (registerNumber < 0 || registerNumber >= 32) {
System.err.println("Erro: Tentativa de ler registrador inválido: " + registerNumber);
Expand Down
4 changes: 4 additions & 0 deletions UnidadeFuncionais/Memoria.java
Original file line number Diff line number Diff line change
Expand Up @@ -69,5 +69,9 @@ public static void writeWord(int value, int address) {
memory[address + 2] = binaryString.substring(16, 24);
memory[address + 3] = binaryString.substring(24, 32);
}

public static String[] getMemoria(){
return(memory);
}

}
Loading