Results 1 to 8 of 8
  1. #1
    RKO
    RKO is offline Member
    Join Date
    Dec 2010
    Posts
    4
    Rep Power
    0

    Default Simple Instruction Set Computer

    I was recently presented a problem to construct a SISC Emulator and Assembler however I've been unable to find any reading material on the subject and I am very confused. Can anyone help me? I can provide the details about what the Program itself it needs to do.

  2. #2
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,523
    Blog Entries
    7
    Rep Power
    20

    Default

    Quote Originally Posted by RKO View Post
    I was recently presented a problem to construct a SISC Emulator and Assembler however I've been unable to find any reading material on the subject and I am very confused. Can anyone help me? I can provide the details about what the Program itself it needs to do.
    Do you have to design the programming model, i.e. the instruction set yourself or is it defined already?

    kind regards,

    Jos
    cenosillicaphobia: the fear for an empty beer glass

  3. #3
    RKO
    RKO is offline Member
    Join Date
    Dec 2010
    Posts
    4
    Rep Power
    0

    Default

    The instruction set is already defined on a sheet that I was given and I've taken a shot at creating the assembler.
    It's probably a lot simpler than I am making it.
    Here's the basic outline of the project.

    Program 1. (Assembler)
    Read in an instruction (ex: READ which is eqivalent to opcode 10) and a byte operand (ex. 07). The opcode and operand are then converted to a 16 bit op code and a 16 bit operand and write out to a file. The logic given to store the opcode and operand on the same record I don't under stand it is as follows:
    int q = (opcode <<16) | operand;
    operand =( q & 65355)
    opcode = (q>>>16)

    If it will help I can show you what I have coded so far.
    Program 2 (Disassembler)
    Reads in the 32 bit record and convert it back to a 2 byte opcode and a two byte operand (ex: "10 07") and writes it to a file.
    Program 3 (Emulator)
    Will read the file from Program 2 and process it. (Ex: "10 07" will read integer from console and store it in memory location 07). This is almost completed except that I need to convert an integer value to ascii and print it. Not sure how to do the ascii conversion.
    I was asked if I could get this done by Tuesday and so far it's only going so so. Any help is appreciated.

  4. #4
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,523
    Blog Entries
    7
    Rep Power
    20

    Default

    If I understand the description right, every instruction takes 32 bits: a 16 bit opcode plus a 16 bit argument. Both are 'glued' together to make up a 32 bit instruction. That explains the bit shifting operations: the upper 16 bit make up the opcode while the lower 16 bits make up the argument/operand of the instruction. Better make a few small methods for that:

    Java Code:
    public int getOpcode(int word) {
       return word >>> 16;
    }
    public int getOperand(int word) {
       return word & 0xffff;
    }
    public int getInstruction(int opcode, int operand) {
       return opcode<<16 | operand;
    }
    I don't know what operands are defined for your SISC, not do I know the mnemomics so I can't help you any further.

    kind regards,

    Jos
    cenosillicaphobia: the fear for an empty beer glass

  5. #5
    RKO
    RKO is offline Member
    Join Date
    Dec 2010
    Posts
    4
    Rep Power
    0

    Default

    I have the list of Opcodes and Operands on a sheet that I can write down if you'd like.

  6. #6
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,523
    Blog Entries
    7
    Rep Power
    20

    Default

    Quote Originally Posted by RKO View Post
    I have the list of Opcodes and Operands on a sheet that I can write down if you'd like.
    We can't implement those three programs if we don't know the instruction set, can we?

    Basically we need a (big) array:

    Java Code:
    int[] memory= new int[MAX_MEM];
    And we have to play with it by assembling code, emulating code and disassembling it again. We don't know the programming model so we don't know what registers to define (program counter? stack pointer? general purpose register(s)?)

    kind regards,

    Jos
    cenosillicaphobia: the fear for an empty beer glass

  7. #7
    RKO
    RKO is offline Member
    Join Date
    Dec 2010
    Posts
    4
    Rep Power
    0

    Default

    I've been trying to work on the assembler and here is what I have gotten so far.

    Java Code:
    import java.util.*;
    import java.io.*;
    
    public class SISCAssembler {
        private Scanner x;
    //int[] intArray = new int[20];
    //  String[] stringArray = new String[20];
    //  String[] operandArray = new String[20];
        String opCodeW;
        String operand;
         
    	  String[]opValueArray =
    	    {"READ", "WRITE", "ASCIIW", "LOAD", "LOADA", "STORE", "ADD","SUB", "MUL", "DIV", "RMDR","BRA", "BRN", "BRZ", "BRNTZ", "NOP", "HALT"};
      int[] opCodeArray =
         {10, 11, 12, 20, 21, 22, 30, 31, 32, 33, 34, 40, 41, 42, 43, 00, 99};
             
    //  int i = 0;
    //  int j = 0;
         
    //   java.io.File file = new java.io.File("div.txt");
         
        public void openFile(){
            try{
               x = new Scanner(new File("div.asm"));
            }  
            catch(Exception e) {
                System.out.println("File not found");
            }
        }
         
        public void readFile(){
            while(x.hasNext()){
                opCodeW    = x.next();
                operand    = x.next();
                System.out.println(opCodeW + " " + operand);
    //          getOpcode();
    //          convertToBinary();
    //          writeBinaryFile();
                 
           }
        }
          
         
        //  for (int m = 0; m < 17; m++){
        //      System.out.println(opValueArray[m]);
        //      System.out.println( stringArray[m]);
        //      System.out.println(operandArray[m]);
     
     
        public int getOpcode(){
            System.out.println("Index\tValue");
            int sIndx = 0;
            int opCode = 0;
        //  int operandx = 0;
             
            for(int indx = 0; indx < opValueArray.length; indx++){
                System.out.println(indx +  "\t" + opValueArray[indx]);
                System.out.print(indx + "\t" + opCodeArray[indx]);
                sIndx = indx;
                if (this.opCodeW.equals(opValueArray[sIndx])){
                    opCode = opCodeArray[sIndx];
                    System.out.println("Opcode = " + opCode + "OpCode W = " + opCodeW);
                     
                }                  
            }
            return opCode;
        }  
         
        public void convertToBinary(int opcd){
             
            // int opcd = 33;  
            // int operand = 07;
             int operandx = 0;
              
              
             operandx = Integer.parseInt(operand);
                 
              
             int q = (opcd <<16)| operandx;
              
             
             operandx = q&65355;
             opcd = q>>>16;
              
             System.out.println("q = " + q);
              
             File binaryFile = new File("div.dat");
                try {
                FileOutputStream fOut = new FileOutputStream(binaryFile);
                String byOpCode = Integer.toBinaryString(opcd);
                System.out.println("Byte: " + byOpCode);
                String byoperand = Integer.toBinaryString(opcd);
                System.out.println("Byte: " + byoperand);
    //          q =
                fOut.writeUTF(byoperand);
                }
                catch(FileNotFoundException fnf) {
                   System.out.println("File was not found");
                }
                catch(IOException ioe){
                   System.out.println("An IO Exception has occurred");
                }
                catch(Exception e){
                    System.out.println("An error has occurred");
                     
    //             fOut.close();
                }
                 
            }
     
        public void closeFile(){     
            x.close();
    //      fOut.Close();
                     
        }
         
    //  public void writeBinaryFile(){
             
         
     }

  8. #8
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,523
    Blog Entries
    7
    Rep Power
    20

    Default

    You're trying to cram too much in a single class; crucial to your processor is this little list:

    Java Code:
    String[]opValueArray={ "READ", "WRITE", "ASCIIW", "LOAD", "LOADA", "STORE", "ADD","SUB", "MUL", "DIV", "RMDR","BRA", "BRN", "BRZ", "BRNTZ", "NOP", "HALT" };
    
    int[] opCodeArray =
         {10, 11, 12, 20, 21, 22, 30, 31, 32, 33, 34, 40, 41, 42, 43, 00, 99};
    I suggest you implement a Map<String, Integer> that maps a human readable instruction (a String) to its opcode; also implement a Map<Integer, String> that works the other way around. Encapsulate both Maps in a little class. Both the assembler and disassembler can use this class.

    kind regards,

    Jos
    cenosillicaphobia: the fear for an empty beer glass

Similar Threads

  1. instruction apparently not executed
    By rippon in forum AWT / Swing
    Replies: 4
    Last Post: 11-30-2010, 01:30 AM
  2. Help with instruction
    By diegoyj in forum New To Java
    Replies: 1
    Last Post: 01-27-2010, 10:09 PM
  3. I am new, can anyone help me in Computer Vision?
    By howardL in forum Introductions
    Replies: 0
    Last Post: 04-23-2009, 09:37 AM
  4. Replies: 0
    Last Post: 01-19-2008, 09:04 AM
  5. First Typed via video instruction
    By ZAXTHEGREAT in forum New To Java
    Replies: 15
    Last Post: 07-23-2007, 04:27 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •