Advertisement
intlissac

assembly

Jan 25th, 2020
75
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.36 KB | None | 0 0
  1. import java.util.*;
  2. import java.io.*;
  3.  
  4. public class Assembly {
  5. public static void main(String[]args) throws IOException {
  6. Scanner in = new Scanner(new File("assembly.in"));
  7. Map<String, Integer> map = new HashMap<String, Integer>();
  8. String[]list = in.nextLine().split(" ");
  9. while(!list[0].equals("END")){
  10.  
  11. if (list[1].equals("DC")) {
  12. map.put(list[0], Integer.parseInt(list[2]));
  13. }
  14. else if(list[0].equals("PRINT")){
  15. System.out.println(map.get(list[1]));
  16. }
  17. else if(list[0].equals("LOAD")){
  18. map.put("ACC",map.get(list[1]));
  19. }
  20. else if(list[0].equals("STORE")){
  21. map.put(list[1],map.get("ACC"));
  22. }
  23. else if(list[0].equals("ADD")){
  24. map.put("ACC",map.get("ACC")+map.get(list[1]));
  25. }
  26. else if(list[0].equals("SUB")){
  27. map.put("ACC",map.get("ACC")-map.get(list[1]));
  28. }
  29. else if(list[0].equals("MULT")){
  30. map.put("ACC",map.get("ACC")*map.get(list[1]));
  31. }
  32. else if(list[0].equals("DIV")){
  33. map.put("ACC",map.get("ACC")/map.get(list[1]));
  34. }
  35. list = in.nextLine().split(" ");
  36. }
  37.  
  38.  
  39. }
  40. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement