Advertisement
jsmith1016

Untitled

Oct 27th, 2018
125
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 24.52 KB | None | 0 0
  1. package com.jamessmith;
  2.  
  3. import java.io.*;
  4.  
  5.  
  6.  
  7. class ErrorTable {
  8.  
  9.     public static String report(int status){
  10.         String s = "ERROR: ";
  11.         switch(status){
  12.             case 100:
  13.                 s += "Invalid Mneumonic";
  14.                 break;
  15.             case 200:
  16.                 s += "Invalid Instruction Format";
  17.                 break;
  18.             default:
  19.                 s += "Some error occured";
  20.                 break;
  21.         }
  22.  
  23.         return s;
  24.     }
  25. }
  26.  
  27. class Program {
  28.  
  29.     private LinkedList instructions;
  30.     private PrintWriter writer;
  31.     /**
  32.      * Constructor for program
  33.      * @param f - the input file containing source code
  34.      * @throws IOException
  35.      */
  36.     public Program(File f) throws IOException{
  37.         instructions = new LinkedList();
  38.         readInput(f);
  39.         instructions.calculateAddresses();
  40.         createLST();
  41.         createOBJ();
  42.     }
  43.  
  44.     /**
  45.      * Reads the files for finding and deleting
  46.      * @throws IOException
  47.      */
  48.     public void readInput(File f) throws IOException{
  49.         FileReader reader;
  50.         BufferedReader bReader;
  51.         String input;
  52.         String content;
  53.  
  54.         reader = new FileReader(f);
  55.         bReader = new BufferedReader(reader);
  56.         input = "";
  57.         content = "";
  58.         while((input = bReader.readLine()) != null){
  59.             if(input.split("\\s+").length > 0){
  60.                 instructions.insert(input);
  61.             }//checks if there is an empty line
  62.         }
  63.         bReader.close();
  64.         reader.close();
  65.  
  66.     }//end readInput
  67.  
  68.     public void display(){
  69.         instructions.display();
  70.     }
  71.  
  72.     public void createLST() throws FileNotFoundException, UnsupportedEncodingException{
  73.         writer = new PrintWriter("pgm.lst","UTF-8");
  74.         writer.println(instructions.toLST());
  75.         writer.close();
  76.     }
  77.  
  78.     public void createOBJ() throws FileNotFoundException, UnsupportedEncodingException{
  79.         writer = new PrintWriter("pgm.obj","UTF-8");
  80.         writer.println(instructions.toOBJ());
  81.         writer.close();
  82.     }
  83.  
  84.  
  85. }//end program
  86.  
  87. class SymbolTable {
  88.  
  89.     public static HashTable table;
  90.     //Variables for hashing
  91.     private static String[] inputArr;   //The string array of the inputs
  92.     private static int size;    //Size of the HashTables
  93.  
  94.  
  95.     public static void setupTable() throws IOException{
  96.         table = new HashTable(size);
  97.         createTable();
  98.     }
  99.  
  100.     /**
  101.      * Reads the files for finding and deleting
  102.      * @throws IOException
  103.      */
  104.     public static String readInput() throws IOException{
  105.         FileReader reader;
  106.         BufferedReader bReader;
  107.         String input;
  108.         String content;
  109.  
  110.         reader = new FileReader(new File("SICOPS.txt"));
  111.         bReader = new BufferedReader(reader);
  112.         input = "";
  113.         content = "";
  114.         while((input = bReader.readLine()) != null){
  115.             content+=input+";";
  116.         }
  117.         return content;
  118.     }
  119.  
  120.     /**
  121.      * Inserts the data into the tables
  122.      * @throws IOException
  123.      */
  124.     public static void createTable() throws IOException{
  125.         String s = readInput();//read input into string
  126.         inputArr = s.split(";");    //Split string into array
  127.         size=(2*inputArr.length);   //Create odd size array
  128.  
  129.         int arrSize = findNextPrime(size);
  130.         table = new HashTable(arrSize);
  131.  
  132.         //For each element inert into the table
  133.         for(String element : inputArr){
  134.             table.insert(new DataItem(element,false));
  135.         }
  136.  
  137.     }//end insertions
  138.  
  139.     public static void insertWord(String data){
  140.         table.insert(new DataItem(data,true));
  141.     }
  142.  
  143.     /**
  144.      * Finds the next prime greater than a min value
  145.      * @param min - the value to find the next prime
  146.      * @return - the next prime number
  147.      */
  148.     public static int findNextPrime(int min){
  149.         boolean isPrime = true;
  150.         boolean isFound = false;
  151.         int num = min+1;
  152.         while(!isFound){
  153.             isPrime = true;
  154.             for(int x=2;x<Math.sqrt(num) && isPrime;x++){
  155.                 if(num%x==0){
  156.                     isPrime = false;
  157.                 }//if the number is divisible by x
  158.             }//for every number up to the square root(test it's primeness)
  159.             if(!isPrime){
  160.                 num+=1;
  161.             }else{
  162.                 isFound = true;
  163.             }
  164.         }//while the number isn't prime
  165.         return num;
  166.     }//end findNextPrime
  167.  
  168.     public static HashTable getTable(){
  169.         return table;
  170.     }
  171. }
  172.  
  173. class DataItem {
  174.  
  175.     private String instruction;//Used for any type of data
  176.     private boolean format4;
  177.     private boolean sic;
  178.     private String optCode;
  179.     private int bytes;
  180.     private boolean word;
  181.  
  182.     public DataItem(String s,boolean isWord){
  183.         assignValues(s,isWord);
  184.     }
  185.  
  186.     public void assignValues(String s,boolean isWord){
  187.         word = isWord;
  188.         String[] temp = s.split("\\s+");
  189.         instruction = temp[0];
  190.         optCode = temp[1];
  191.         bytes = Integer.parseInt(temp[2]);
  192.         if(temp[0].charAt(0) == '+'){
  193.             format4 = true;
  194.         }else if(temp[0].charAt(0) == '*'){
  195.             sic = true;
  196.         }else{
  197.             sic=false;
  198.             format4=false;
  199.         }
  200.     }
  201.  
  202.     //gets the content of the item
  203.     public String getContent(){
  204.         return String.format("%8s %8d",instruction,bytes);
  205.     }
  206.  
  207.     public String getOptCode(){
  208.         return optCode;
  209.     }
  210.  
  211.     public boolean isWordStorage(){
  212.         return word;
  213.     }
  214.  
  215.     public int getBytes(){
  216.         return bytes;
  217.     }
  218.     public String getInstruction(){
  219.         return instruction;
  220.     }
  221.  
  222.     public boolean compareTo(String s){
  223.         return (s == instruction);
  224.     }
  225.  
  226. }//end DataItem
  227.  
  228. class HashTable {
  229.  
  230.     private DataItem[] arr; // the array of items
  231.     private int size;   //The size of the array
  232.     private int maxSearch;
  233.     /**
  234.      * Constructor for the HashTable
  235.      * @param size - the size of the table
  236.      */
  237.     public HashTable(int size){
  238.         this.size = size;
  239.         arr = new DataItem[size];
  240.         maxSearch = 1;
  241.     }//end HashTable
  242.  
  243.     public DataItem find(String key){
  244.         int walker;//walker to walk on array
  245.         int count = 1;//counter for probing
  246.         int  newHash;
  247.         boolean found = false;
  248.         int hash = hash(key);
  249.         if(arr[hash] != null && arr[hash].getInstruction().equals(key)){
  250.             return arr[hash];
  251.         }
  252.         while(!found){
  253.             walker = hash;
  254.             newHash = quadP(count++);
  255.             for(int x=newHash;x>0;x--){
  256.                 if(++walker == arr.length){
  257.                     walker = 0;
  258.                 }
  259.             }
  260.             if(arr[walker] != null && arr[walker].getInstruction().equals(key)){
  261.                 return arr[walker];
  262.             }//if the array item is null or
  263.             if(count>maxSearch){
  264.                 break;
  265.             }
  266.  
  267.  
  268.         }
  269.         return null;
  270.     }
  271.  
  272.     /**
  273.      * Hashes the given string
  274.      * @param s - the string to hash
  275.      * @return - the value of the hashed string
  276.      */
  277.     public int hash(String s){
  278.         int hash = 0;
  279.         char[] arr = s.toCharArray();
  280.         hash=arr[0];
  281.         for(int x=1;x<arr.length;x++){
  282.             hash=(hash*26+arr[x])%size;
  283.         }//hash the string
  284.         hash%=size;//Just in case its one character(will not affect if more)
  285.         return hash;
  286.     }//end hash
  287.  
  288.     /**
  289.      * Displays the insertions of the data
  290.      * @return - the formated string of info
  291.      */
  292.     public String displayTable(){
  293.         String s ="";
  294.         for(int x=0;x<arr.length;x++){
  295.             if(arr[x] != null){
  296.                 s+=(String.format("Memory Locatiom:%-10d%-10s\n",x,arr[x].getContent()));
  297.             }
  298.         }
  299.         return s;
  300.     }//end displayInsertions
  301.  
  302.     public String displayWordStorage(){
  303.         String s = String.format("\n%-10s%8s%8s\n","Table Location","Label","Address");
  304.         for(int x=0;x<arr.length;x++){
  305.             if(arr[x] != null && arr[x].isWordStorage()){
  306.                 s+=(String.format("%-18d%-8s%-10s\n",x,arr[x].getInstruction(),Integer.toHexString(Integer.parseInt(arr[x].getOptCode())).toUpperCase()));
  307.             }
  308.         }
  309.         return s;
  310.     }
  311.  
  312.  
  313.     /**
  314.      * Insertion method for hash table
  315.      * @param item - the item to be inserted
  316.      */
  317.     public void insert(DataItem item){
  318.         //Hash
  319.         String s = item.getInstruction();
  320.         int hash = hash(s);
  321.  
  322.         //insert
  323.         if(arr[hash] == null){
  324.             arr[hash] = item;
  325.         }else{//if the index is null or there is a deleted item
  326.             probeInsert(hash,item);
  327.         }//else probe until valid insertion
  328.     }//end insert
  329.  
  330.     /**
  331.      * probeInsertion
  332.      * @param hash - the hash value of the string
  333.      * @param item - the item to be inserted
  334.      */
  335.     public void probeInsert(int hash,DataItem item){
  336.         boolean isFound = false;//boolean to know when found
  337.         int walker = hash;//walker to walk on array
  338.         int count = 1;//counter for probing
  339.         int  newHash = hash;//New hash value
  340.  
  341.         while(!isFound){
  342.             walker = hash;
  343.             newHash = quadP(count++);
  344.             for(int x=newHash;x>0;x--){
  345.                 if(++walker == arr.length){
  346.                     walker = 0;
  347.                 }
  348.             }
  349.             if(arr[walker]== null){
  350.                 arr[walker] = item;
  351.                 isFound = true;
  352.             }//if the array item is null or
  353.         }//while the item position isn't found
  354.         if(count>maxSearch){
  355.             maxSearch = count;
  356.         }
  357.     }//end probeInsert
  358.  
  359.  
  360.  
  361.     //Used if using quadratic probing
  362.     public int quadP(int x){
  363.         return x*x;
  364.     }//end quadP
  365.  
  366. }//end HashTable
  367.  
  368. class LinkedList{
  369.     private Link first;
  370.     private Link last;
  371.     private int baseAdd;
  372.  
  373.     public LinkedList(){
  374.         first = null;
  375.         last = null;
  376.     }
  377.  
  378.     public String delete(){
  379.         String data = first.getDisplayFormat();
  380.         first = first.next;
  381.         return data;
  382.     }
  383.  
  384.     public void reset(){
  385.         first = null;
  386.         last = null;
  387.     }
  388.  
  389.     public String getPeek(){
  390.         return first.getDisplayFormat();
  391.     }
  392.  
  393.     public boolean isEmpty(){
  394.         return (first == null);
  395.     }
  396.  
  397.     public void insert(String data){
  398.         if(first == null){
  399.             first = new Link(data,-1);
  400.             last = first;
  401.         }else{
  402.             Link newLink = new Link(data,last.nextAddress());
  403.             last.next = newLink;
  404.             last = newLink;
  405.         }
  406.     }
  407.  
  408.     public void display(){
  409.         Link temp = first;
  410.         System.out.println("****************************\nKyle Gray: SIC/XE Assembler\nVersion Date 04/14/17\n****************************");
  411.         System.out.println(String.format("ASSEMBLER REPORT\n-----------------\n%8s %13s %15s","Loc","Object Code","Source Code"));
  412.         System.out.println(String.format("%8s %13s %16s","---","-----------","-----------"));
  413.         int line = 1;
  414.         while(temp != null){
  415.             System.out.println(String.format("%03d- %s",line++,temp.getDisplayFormat()));
  416.             temp = temp.next;
  417.         }
  418.     }
  419.  
  420.     public String toLST(){
  421.         Link temp = first;
  422.         String output = "";
  423.         output+="****************************\nKyle Gray: SIC/XE Assembler\nVersion Date 04/14/17\n****************************\n";
  424.         output+=String.format("ASSEMBLER REPORT\n-----------------\n%8s %13s %15s\n","Loc","Object Code","Source Code");
  425.         output+=String.format("%8s %13s %16s\n","---","-----------","-----------");
  426.         int line = 1;
  427.         while(temp != null){
  428.             output+=String.format("%03d- %s\n",line++,temp.getDisplayFormat());
  429.             temp = temp.next;
  430.         }
  431.         return output;
  432.     }
  433.  
  434.     public String toOBJ(){
  435.         Link temp = first;
  436.         String output = "";
  437.         while(temp != null){
  438.             output+=String.format("%s\n",temp.getObjectCode().toString());
  439.             temp = temp.next;
  440.         }
  441.         return output+"!";
  442.     }
  443.  
  444.     public void findBase(){
  445.         //Base Find
  446.         Link temp = first;
  447.         while(temp.next != null){
  448.             if(temp.getMneumonic().equals("BASE")){
  449.                 break;
  450.             }
  451.             temp = temp.next;
  452.         }
  453.         String base = temp.getOperand();
  454.         temp = temp.next;
  455.         while(temp.next != null){
  456.             if(temp.getOperand() == base){
  457.                 baseAdd = temp.getAddress();
  458.                 break;
  459.             }
  460.             temp = temp.next;
  461.         }
  462.     }//end findBase
  463.  
  464.     public void calculateAddresses(){
  465.         findBase();
  466.         Link temp = first;
  467.         while(temp.next != null){
  468.             switch(temp.getMneumonic()){
  469.                 case "START":
  470.                 case "END":
  471.                 case "RESW":
  472.                 case "WORD":
  473.                 case "BASE":
  474.                     break;
  475.                 default:
  476.                     boolean address = false;
  477.                     if(temp.getObjectCode().isExtended()){//if extended
  478.                         String key = temp.getOperand();
  479.                         if(key.charAt(0) == '#' || key.charAt(0) == '@'){
  480.                             key = key.substring(1);
  481.                         }
  482.                         Link link = first;
  483.                         while(link.next != null){
  484.                             if(link.getLabel().equals(key) && !link.compareTo(temp)){
  485.                                 temp.getObjectCode().setAddress(link.getAddress());
  486.                                 break;
  487.                             }else{
  488.                                 link = link.next;
  489.                             }
  490.                         }
  491.                     }else if(SymbolTable.table.find(temp.getMneumonic()).getBytes() == 2){//if Resistor operation
  492.                         String[] registers = temp.getOperand().split(",");
  493.                         for(int i=0;i<2;i++){
  494.                             switch(registers[i]){
  495.                                 case "A":
  496.                                     registers[i] = "0";
  497.                                     break;
  498.                                 case "T":
  499.                                     registers[i] = "5";
  500.                                     break;
  501.                             }
  502.                         }//end for
  503.  
  504.                         temp.getObjectCode().setAddress(Integer.parseInt((registers[0]+registers[1]),16));
  505.                     }else{//if its a 6 byte instruction
  506.                         String key = temp.getOperand();
  507.                         if(key.charAt(0) == '#' || key.charAt(0) == '@'){
  508.                             key = key.substring(1);
  509.                         }
  510.                         Link link = first;
  511.                         while(link.next != null){
  512.                             if(link.getLabel().equals(key) && !link.compareTo(temp)){//if we found the label
  513.                                 if(link.getAddress() - temp.next.getAddress() > 2048){
  514.                                     //Base
  515.                                     temp.getObjectCode().setAddress(link.getAddress()-baseAdd);
  516.                                     temp.getObjectCode().modifyPC();
  517.                                 }else{
  518.                                     temp.getObjectCode().setAddress(link.getAddress()-temp.nextAddress());
  519.                                     break;
  520.                                 }
  521.                                 break;
  522.                             }else{
  523.                                 link = link.next;
  524.                             }
  525.                         }
  526.                     }//end if
  527.                     break;
  528.             }//end swtich
  529.             temp = temp.next;
  530.         }
  531.     }
  532.  
  533.  
  534. }//end List
  535.  
  536. class Link{
  537.     public ObjectCode objectCode;//ObjectCode String
  538.     public Link next;
  539.     private String mneumonic;
  540.     private String operand;
  541.     private int address;
  542.     private String label;
  543.     private String comment;
  544.     private int status;
  545.  
  546.     public Link(String data,int add){
  547.         objectCode = new ObjectCode();
  548.         status = -1;
  549.         if(add == -1){
  550.             this.address = (int)(Long.parseLong(data.substring(19,28).trim(),16));
  551.         }else{
  552.             this.address = add;
  553.         }
  554.  
  555.         //Checks label
  556.         label = data.substring(0,7).trim();
  557.  
  558.         //Checks format
  559.         if(data.charAt(9) == '+'){
  560.             objectCode.setExtended(true);
  561.         }
  562.  
  563.         //Instruction
  564.         mneumonic = data.substring(10,16).trim();
  565.         try{
  566.             if(SymbolTable.table.find(this.mneumonic).getBytes() == 2){
  567.                 objectCode.setResistor(true);
  568.             }
  569.         }catch(NullPointerException e){
  570.  
  571.         }
  572.  
  573.         //Operand
  574.         try{
  575.             operand = data.substring(18,28).trim();
  576.         }catch(StringIndexOutOfBoundsException e){
  577.             operand = data.substring(18).trim();
  578.         }
  579.  
  580.         //Comments
  581.         try{
  582.             comment = data.substring(31);
  583.         }catch(StringIndexOutOfBoundsException e){
  584.             comment = "";
  585.         }
  586.  
  587.  
  588.         if(mneumonic.equals("RESW") && !label.isEmpty()){
  589.             SymbolTable.insertWord(String.format("%s %s %d",label,address,Integer.parseInt(operand)*3));
  590.         }else if(mneumonic.equals("WORD") && !label.isEmpty()){
  591.             SymbolTable.insertWord(String.format("%s %s %d",label,address,3));
  592.         }
  593.  
  594.         //Append the first part of object code
  595.         switch(this.mneumonic){
  596.             case "START":
  597.             case "BASE":
  598.             case "END":
  599.                 break;
  600.             case "WORD":
  601.                 objectCode.setAddress(Integer.parseInt(operand,16));
  602.                 break;
  603.             case "RESW":
  604.                 objectCode.setAddress(Integer.parseInt("FFFFFF",16));
  605.                 break;
  606.             default:
  607.                 try{
  608.                     objectCode.setOptCode(Integer.parseInt(SymbolTable.table.find(this.mneumonic).getOptCode(),16));
  609.                     switch(data.charAt(18)){
  610.                         case '#':
  611.                             try{
  612.                                 if(Integer.parseInt(operand) == Integer.parseInt(operand,10)){
  613.                                     objectCode.calcNI(false,true);
  614.                                 }
  615.                             }catch(NumberFormatException e){
  616.                                 objectCode.calcNI(true, true);
  617.                             }
  618.                             break;
  619.                         case '@':
  620.                             objectCode.calcNI(true, false);
  621.                             break;
  622.                         default:
  623.                             if(objectCode.isResistor()){
  624.                                 objectCode.calcNI(false, false);
  625.                             }else{
  626.                                 objectCode.calcNI(true, true);
  627.                             }
  628.                             break;
  629.                     }
  630.                 }catch(NullPointerException e){
  631.                 }
  632.  
  633.                 //Calculate Flags
  634.                 int temp = 0;
  635.                 if(objectCode.isExtended()){
  636.                     temp+=1;
  637.                 }else if(!objectCode.isImmediate() && SymbolTable.table.find(this.mneumonic).getBytes() != 2){
  638.                     temp+=2;
  639.                 }
  640.                 if(operand.contains(",X") && operand.length() != 3){
  641.                     temp+=8;
  642.                 }
  643.                 objectCode.setFlags(temp);
  644.  
  645.         }//end switch
  646.     }//end Constructor
  647.  
  648.     public ObjectCode getObjectCode(){
  649.         return objectCode;
  650.     }
  651.  
  652.     public int nextAddress(){
  653.         int inc;
  654.         if(mneumonic.equals("RESW")){
  655.             inc = 3*Integer.parseInt(operand);
  656.         }else if(this.mneumonic == null || this.mneumonic.equals("")){
  657.             status = 200;
  658.             inc = 0;
  659.         }else{
  660.             inc = SymbolTable.getTable().find(this.mneumonic).getBytes();
  661.         }
  662.  
  663.         if(inc == -1){
  664.             status = 100;
  665.             inc = 0;
  666.         }
  667.         return incrementAddress(inc);
  668.     }
  669.  
  670.     public int incrementAddress(int count){
  671.         return (int)(Long.parseLong(Integer.toString(address))+Long.parseLong(Integer.toString(count)));
  672.     }
  673.  
  674.     public String getMneumonic(){
  675.         return mneumonic;
  676.     }
  677.  
  678.     public String getOperand(){
  679.         return operand;
  680.     }
  681.  
  682.     public int getAddress(){
  683.         return address;
  684.     }
  685.  
  686.     public String getLabel(){
  687.         return label;
  688.     }
  689.     public String getDisplayFormat(){
  690.         if(status == -1){
  691.             String addy = Integer.toHexString(address);
  692.             while(addy.length() != 5){
  693.                 addy=("0"+addy);
  694.             }
  695.             String mnu = mneumonic;
  696.             if(objectCode.isExtended()){
  697.                 mnu = "+"+mnu;
  698.             }
  699.             return String.format("%-6s%-15s%-8s%-7s%-7s%-10s",addy.toUpperCase(),objectCode.toString().toUpperCase(),label,mnu,operand,comment);
  700.         }else{
  701.             return ErrorTable.report(status);
  702.         }
  703.     }
  704.  
  705.     public boolean compareTo(Link link){
  706.         return (this.address == link.address);
  707.     }
  708. }
  709.  
  710. class ObjectCode {
  711.  
  712.     private int optCode;
  713.     private int flags;
  714.     private int address;
  715.     private boolean extended;
  716.     private boolean immediate;
  717.     private boolean pc;
  718.     private boolean resistor;
  719.  
  720.     public ObjectCode(){
  721.         extended = false;
  722.         immediate = false;
  723.         pc = false;
  724.         resistor = false;
  725.         optCode=0;
  726.         flags=0;
  727.     }
  728.  
  729.     public String toString(){
  730.         if(optCode == flags){
  731.             String temp = Integer.toHexString(address);
  732.             while(temp.length()!=6){
  733.                 temp = ("0"+temp);
  734.             }
  735.             return temp;
  736.         }else if(resistor){
  737.             return(Integer.toHexString(optCode)+Integer.toHexString(address));
  738.         }else{
  739.             String tempObj = Integer.toHexString(optCode);
  740.             while(tempObj.length() != 2){
  741.                 tempObj = ("0"+tempObj);
  742.             }
  743.             String tempAddy;
  744.             if(address < 0){
  745.                 tempAddy = Integer.toHexString(address).substring(Integer.toHexString(address).length()-3).toUpperCase();
  746.             }else{
  747.                 tempAddy = Integer.toHexString(address);
  748.             }
  749.             if(extended){
  750.                 while(tempAddy.length() != 5){
  751.                     tempAddy = "0"+tempAddy;
  752.                 }
  753.             }else if(!resistor){
  754.                 while(tempAddy.length() != 3){
  755.                     tempAddy = "0"+tempAddy;
  756.                 }
  757.             }
  758.             return (tempObj+Integer.toHexString(flags)+tempAddy);
  759.         }
  760.     }
  761.  
  762.     public void setOptCode(int optCode){
  763.         this.optCode = optCode;
  764.     }
  765.  
  766.     public void calcNI(boolean indirect,boolean immediate){
  767.         if(indirect && immediate){
  768.             optCode+= 3;
  769.         }else if(indirect && !immediate){
  770.             optCode+= 2;
  771.         }else if(immediate && !indirect){
  772.             this.immediate = true;
  773.             optCode+= 1;
  774.         }
  775.     }
  776.  
  777.     public void setFlags(int num){
  778.         flags = num;
  779.     }
  780.  
  781.     public void setAddress(int address){
  782.         this.address = address;
  783.     }
  784.     public boolean isImmediate(){
  785.         return immediate;
  786.     }
  787.  
  788.     public void setExtended(boolean e){
  789.         extended = e;
  790.     }
  791.  
  792.     public boolean isExtended(){
  793.         return extended;
  794.     }
  795.  
  796.     public void setPc(boolean p){
  797.         pc = p;
  798.     }
  799.  
  800.     public void modifyPC(){
  801.         flags= flags+2;
  802.     }
  803.  
  804.     public boolean isResistor(){
  805.         return resistor;
  806.     }
  807.  
  808.     public void setResistor(boolean is){
  809.         resistor = is;
  810.     }
  811.  
  812.     public boolean isPC(){
  813.         return pc;
  814.     }
  815.  
  816. }
  817.  
  818. public class Main {
  819.  
  820.     private Program program;
  821.  
  822.  
  823.     public void readProgram(String filename) throws IOException {
  824.         try {
  825.             program = new Program(new File(filename));
  826.             program.display();
  827.         } catch (Exception e) {
  828.             // TODO Auto-generated catch block
  829.             e.printStackTrace();
  830.         }
  831.  
  832.     }
  833.  
  834.     //Main
  835.     public static void main(String[] args) throws IOException{
  836.         //Create instance of the mainClass
  837.         Main main = new Main();
  838.         SymbolTable.createTable();
  839.         main.readProgram(args[0]);
  840.         //Display the insertions
  841.         //System.out.println(SymbolTable.table.displayWordStorage());
  842.     }//end main
  843.  
  844. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement