Last active
July 17, 2018 21:25
-
-
Save SilvaEmerson/d789e3276b664d73fcb156d4a96dc60f to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class Main { | |
public static void main(String[] args){ | |
Process processo1 = new Process("Processo1"); | |
Process processo2 = processo1.fork("Processo2"); | |
System.out.println("Processo 1 UID: " + processo1.getOwner()); | |
System.out.println("Processo 2 UID: " + processo2.getOwner()); | |
System.out.println("Data de criação do Processo 1: " + processo1.getCreationDateTime()); | |
System.out.println("Data de criação do Processo 2: " + processo1.getCreationDateTime()); | |
System.out.println("Processo 1 PID: " + processo1.getPid()); | |
System.out.println("Processo 2 PID: " + processo2.getPid()); | |
System.out.println("PID do Processo Pai do Processo 2: " + processo2.getFatherProcess()); | |
System.out.println("PID do Processo Pai do Processo 1: " + processo1.getFatherProcess()); | |
Register tempRegister = new Register(); | |
System.out.println("Valor no registrador de endereço " + processo1.getRegister().getAdress() | |
+ ": " + processo1.getRegister().getData()); | |
System.out.println("Valor no registrador de endereço " + processo2.getRegister().getAdress() | |
+ ": " + processo2.getRegister().getData()); | |
String sumResultString = processo2.sumString(processo1, tempRegister); | |
System.out.println("Instruções no formato MIPS: " + sumResultString); | |
tempRegister.setData(processo2.sum(processo1)); | |
System.out.println("Soma: " + tempRegister.getData()); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
run: | |
javac Main.java && java Main |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.util.*; | |
import java.text.*; | |
import java.util.concurrent.ThreadLocalRandom; | |
public class Process { | |
private String name; | |
private int pid; | |
private static int owner = 777; | |
private int fatherProcess; | |
private String creationDatetime; | |
private Register referenceRegister; | |
public Process(){} | |
public Process(String name){ | |
this.pid = ThreadLocalRandom.current().nextInt(1, 100 + 1); | |
this.name = name; | |
this.creationDatetime = new SimpleDateFormat("dd/MM/yyyy, HH:mm:ss").format(Calendar.getInstance().getTime()); | |
this.referenceRegister = new Register(ThreadLocalRandom.current().nextInt(0, 100 + 1)); | |
} | |
Process fork(String subprocessName){ | |
Process tempProcess = new Process(subprocessName); | |
tempProcess.setFatherProcess(this.pid); | |
return tempProcess; | |
} | |
void setFatherProcess(int pid){ | |
this.fatherProcess = pid; | |
} | |
int getPid(){ | |
return this.pid; | |
} | |
static int getOwner(){ | |
return owner; | |
} | |
int getFatherProcess(){ | |
return this.fatherProcess; | |
} | |
String getCreationDateTime(){ | |
return this.creationDatetime; | |
} | |
Register getRegister(){ | |
return this.referenceRegister; | |
} | |
int sum(Process process){ | |
return this.referenceRegister.sum(process.getRegister()); | |
} | |
public String sumString(Process process, Register register){ | |
return this.referenceRegister.sumString(process.getRegister(), register); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class Register { | |
private int adress = 0; | |
private static int previusVal = 0; | |
private String dataBin; | |
private int dataDec; | |
private final String sumOpCode = "0"; | |
private final String shift = "0"; | |
private final String func = "100000"; | |
public Register(){ | |
this.adress = previusVal; | |
previusVal++; | |
} | |
public Register(int data){ | |
this.dataDec = data; | |
this.adress = previusVal; | |
previusVal++; | |
} | |
int getData(){ | |
return this.dataDec; | |
} | |
public void setData(int newData){ | |
this.dataDec = newData; | |
} | |
public String toBin(int number){ | |
return Integer.toBinaryString(number); | |
} | |
public int toDec(String binNumber){ | |
return Integer.parseInt(binNumber, 2); | |
} | |
int getAdress(){ | |
return this.adress; | |
} | |
public String sumString(Register register, Register targetRegister){ | |
return this.sumOpCode + " " + this.toBin(targetRegister.getAdress()) + " " | |
+ this.toBin(register.getAdress()) | |
+ " " + this.toBin(this.getAdress()) | |
+ " " + this.shift + " " + this.func; | |
} | |
public int sum(Register register){ | |
return this.dataDec + register.getData(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment