Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- private void createAddressArray() {
- // this method is used to calculate the addresses of the source code
- int Address = 0;
- String currentAddress = new String();
- int ORGAddress = 0;
- try {
- Address = Integer.parseInt(operands.get(0), 16);
- currentAddress = Integer.toHexString(Address).toUpperCase();
- Addresses.add(currentAddress);
- Addresses.add(currentAddress);
- } catch (Exception e) {
- currentAddress = Integer.toHexString(Address).toUpperCase();
- Addresses.add(currentAddress);
- }
- for (int i = 1; i < labels.size(); i++) {
- if (labels.get(i) != null && labels.get(i).equals("*")) {
- if (operationCodes.get(i).charAt(1) == 'X') {
- Address += 1;
- } else {
- int length = operationCodes.get(i).length() - 4;
- Address += length;
- }
- } else if (operationCodes.get(i).equals("WORD")) {
- Address += 3;
- } else if (operationCodes.get(i).equals("BYTE")) {
- if (operands.get(i).charAt(0) == 'X') {
- Address += 1;
- } else {
- int length = operands.get(i).length() - 3;
- Address += length;
- }
- } else if (operationCodes.get(i).equals("RESW")) {
- Address += (3 * Integer.parseInt(operands.get(i)));
- } else if (operationCodes.get(i).equals("RESB")) {
- Address += (Integer.parseInt(operands.get(i)));
- } else if (operationCodes.get(i).equals("EQU")) {
- if (!operands.get(i).equals("*")) {
- if (calculate(operands.get(i)) == null) {
- operands.set(i, "Error Forward Refernce Is Not Allowed is EQU");
- check = false;
- } else {
- System.out.println(Addresses.get(i));
- Addresses.set(i, calculate(operands.get(i)));
- }
- currentAddress = Integer.toHexString(Address).toUpperCase();
- }
- } else if (operationCodes.get(i).equals("ORG")) {
- if (operands.get(i) != null) {
- if (calculate(operands.get(i)) == null) {
- currentAddress = Integer.toHexString(Address).toUpperCase();
- operands.set(i, "Error Forward Refernce Is Not Allowed is ORG");
- check = false;
- } else {
- ORGAddress = Address;
- Address = Integer.parseInt(calculate(operands.get(i)), 16);
- currentAddress = Integer.toHexString(Address).toUpperCase();
- }
- } else {
- Address = ORGAddress;
- currentAddress = Integer.toHexString(Address).toUpperCase();
- }
- } else if (operationCodes.get(i).equals("END") || operationCodes.get(i).equals("LTORG")) {
- } else {
- Address += 3;
- }
- if (operationCodes.get(i).equals("EQU") || operationCodes.get(i).equals("ORG")) {
- Addresses.add(currentAddress);
- } else {
- currentAddress = Integer.toHexString(Address).toUpperCase();
- Addresses.add(currentAddress);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement