Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.Map;
- import java.io.IOException;
- public class Controller{
- public Map<String, Instruction> cnt;
- public Controller() {
- cnt = new HashMap<String, Instruction>();
- class ADD implements Instruction {
- public void execute(String [] args, CPUReg regFile)
- throws IOException {
- regFile.writeReg(args[1],regFile.readReg(args[2]) + regFile.readReg(args[3]));
- }
- }
- cnt.put("ADD", new ADD());
- // do that for all instructions
- public void executeInstruction(String [] args, CPUReg regFile)
- throws IOException {
- Instruction inst = cnt.get(args[0]);
- if(inst == null) throw new IOException("Cannot find instruction");
- inst.execute(args, regFile);
- }
- }
- }
- ^
- ^
Add Comment
Please, Sign In to add comment