Guest User

Untitled

a guest
Feb 17th, 2019
59
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.67 KB | None | 0 0
  1. import java.util.Map;
  2. import java.io.IOException;
  3. public class Controller{
  4. public Map<String, Instruction> cnt;
  5.  
  6. public Controller() {
  7.  
  8. cnt = new HashMap<String, Instruction>();
  9.  
  10. class ADD implements Instruction {
  11. public void execute(String [] args, CPUReg regFile)
  12. throws IOException {
  13. regFile.writeReg(args[1],regFile.readReg(args[2]) + regFile.readReg(args[3]));
  14. }
  15. }
  16. cnt.put("ADD", new ADD());
  17. // do that for all instructions
  18.  
  19. public void executeInstruction(String [] args, CPUReg regFile)
  20. throws IOException {
  21.  
  22. Instruction inst = cnt.get(args[0]);
  23. if(inst == null) throw new IOException("Cannot find instruction");
  24.  
  25. inst.execute(args, regFile);
  26. }
  27. }
  28. }
  29.  
  30. ^
  31.  
  32. ^
Add Comment
Please, Sign In to add comment