# Simple Instruction Set Computer

• 12-12-2010, 07:36 AM
RKO
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.
• 12-12-2010, 10:50 AM
JosAH
Quote:

Originally Posted by RKO
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
• 12-13-2010, 05:33 AM
RKO
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.

Quote:

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.
Quote:

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.
Quote:

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.
• 12-13-2010, 10:32 AM
JosAH
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:

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
• 12-13-2010, 02:58 PM
RKO
I have the list of Opcodes and Operands on a sheet that I can write down if you'd like.
• 12-13-2010, 03:39 PM
JosAH
Quote:

Originally Posted by RKO
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:

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
• 12-13-2010, 03:59 PM
RKO
I've been trying to work on the assembler and here is what I have gotten so far.

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(){              }```
• 12-13-2010, 05:21 PM
JosAH
You're trying to cram too much in a single class; crucial to your processor is this little list:

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