Advertisement
kimo12

Untitled

May 24th, 2017
96
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.67 KB | None | 0 0
  1.     private void createAddressArray() {
  2.         // this method is used to calculate the addresses of the source code
  3.         int Address = 0;
  4.         String currentAddress = new String();
  5.         int ORGAddress = 0;
  6.         try {
  7.             Address = Integer.parseInt(operands.get(0), 16);
  8.             currentAddress = Integer.toHexString(Address).toUpperCase();
  9.             Addresses.add(currentAddress);
  10.             Addresses.add(currentAddress);
  11.         } catch (Exception e) {
  12.             currentAddress = Integer.toHexString(Address).toUpperCase();
  13.             Addresses.add(currentAddress);
  14.         }
  15.  
  16.         for (int i = 1; i < labels.size(); i++) {
  17.             if (labels.get(i) != null && labels.get(i).equals("*")) {
  18.                 if (operationCodes.get(i).charAt(1) == 'X') {
  19.                     Address += 1;
  20.                 } else {
  21.                     int length = operationCodes.get(i).length() - 4;
  22.                     Address += length;
  23.                 }
  24.             } else if (operationCodes.get(i).equals("WORD")) {
  25.                 Address += 3;
  26.             } else if (operationCodes.get(i).equals("BYTE")) {
  27.                 if (operands.get(i).charAt(0) == 'X') {
  28.                     Address += 1;
  29.                 } else {
  30.                     int length = operands.get(i).length() - 3;
  31.                     Address += length;
  32.                 }
  33.             } else if (operationCodes.get(i).equals("RESW")) {
  34.                 Address += (3 * Integer.parseInt(operands.get(i)));
  35.             } else if (operationCodes.get(i).equals("RESB")) {
  36.                 Address += (Integer.parseInt(operands.get(i)));
  37.             } else if (operationCodes.get(i).equals("EQU")) {
  38.                 if (!operands.get(i).equals("*")) {
  39.                     if (calculate(operands.get(i)) == null) {
  40.                         operands.set(i, "Error Forward Refernce Is Not Allowed is EQU");
  41.                         check = false;
  42.                     } else {
  43.                         System.out.println(Addresses.get(i));
  44.                         Addresses.set(i, calculate(operands.get(i)));
  45.                     }
  46.                     currentAddress = Integer.toHexString(Address).toUpperCase();
  47.                 }
  48.             } else if (operationCodes.get(i).equals("ORG")) {
  49.                 if (operands.get(i) != null) {
  50.                     if (calculate(operands.get(i)) == null) {
  51.                         currentAddress = Integer.toHexString(Address).toUpperCase();
  52.                         operands.set(i, "Error Forward Refernce Is Not Allowed is ORG");
  53.                         check = false;
  54.                     } else {
  55.                         ORGAddress = Address;
  56.                         Address = Integer.parseInt(calculate(operands.get(i)), 16);
  57.                         currentAddress = Integer.toHexString(Address).toUpperCase();
  58.                     }
  59.                 } else {
  60.                     Address = ORGAddress;
  61.                     currentAddress = Integer.toHexString(Address).toUpperCase();
  62.                 }
  63.  
  64.             } else if (operationCodes.get(i).equals("END") || operationCodes.get(i).equals("LTORG")) {
  65.  
  66.             } else {
  67.                 Address += 3;
  68.             }
  69.             if (operationCodes.get(i).equals("EQU") || operationCodes.get(i).equals("ORG")) {
  70.                 Addresses.add(currentAddress);
  71.             } else {
  72.                 currentAddress = Integer.toHexString(Address).toUpperCase();
  73.                 Addresses.add(currentAddress);
  74.             }
  75.         }
  76.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement