Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.*;
- import java.io.*;
- public class Assembly {
- public static void main(String[]args) throws IOException {
- Scanner in = new Scanner(new File("assembly.in"));
- Map<String, Integer> map = new HashMap<String, Integer>();
- String[]list = in.nextLine().split(" ");
- while(!list[0].equals("END")){
- if (list[1].equals("DC")) {
- map.put(list[0], Integer.parseInt(list[2]));
- }
- else if(list[0].equals("PRINT")){
- System.out.println(map.get(list[1]));
- }
- else if(list[0].equals("LOAD")){
- map.put("ACC",map.get(list[1]));
- }
- else if(list[0].equals("STORE")){
- map.put(list[1],map.get("ACC"));
- }
- else if(list[0].equals("ADD")){
- map.put("ACC",map.get("ACC")+map.get(list[1]));
- }
- else if(list[0].equals("SUB")){
- map.put("ACC",map.get("ACC")-map.get(list[1]));
- }
- else if(list[0].equals("MULT")){
- map.put("ACC",map.get("ACC")*map.get(list[1]));
- }
- else if(list[0].equals("DIV")){
- map.put("ACC",map.get("ACC")/map.get(list[1]));
- }
- list = in.nextLine().split(" ");
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement