Results 1 to 8 of 8
Thread: Simple Instruction Set Computer
- 12-12-2010, 06:36 AM #1
Member
- Join Date
- Dec 2010
- Posts
- 4
- Rep Power
- 0
- 12-12-2010, 09:50 AM #2
- Join Date
- Sep 2008
- Location
- Voorschoten, the Netherlands
- Posts
- 11,408
- Blog Entries
- 7
- Rep Power
- 17
- 12-13-2010, 04:33 AM #3
Member
- Join Date
- Dec 2010
- Posts
- 4
- Rep Power
- 0
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.I was asked if I could get this done by Tuesday and so far it's only going so so. Any help is appreciated.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.
- 12-13-2010, 09:32 AM #4
- Join Date
- Sep 2008
- Location
- Voorschoten, the Netherlands
- Posts
- 11,408
- Blog Entries
- 7
- Rep Power
- 17
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:
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.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; }
kind regards,
JosWhen people rob a bank they get a penalty; when banks rob people they get a bonus.
- 12-13-2010, 01:58 PM #5
Member
- Join Date
- Dec 2010
- Posts
- 4
- Rep Power
- 0
I have the list of Opcodes and Operands on a sheet that I can write down if you'd like.
- 12-13-2010, 02:39 PM #6
- Join Date
- Sep 2008
- Location
- Voorschoten, the Netherlands
- Posts
- 11,408
- Blog Entries
- 7
- Rep Power
- 17
We can't implement those three programs if we don't know the instruction set, can we?
Basically we need a (big) array:
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)?)Java Code:int[] memory= new int[MAX_MEM];
kind regards,
JosWhen people rob a bank they get a penalty; when banks rob people they get a bonus.
- 12-13-2010, 02:59 PM #7
Member
- Join Date
- Dec 2010
- Posts
- 4
- Rep Power
- 0
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(){ }
- 12-13-2010, 04:21 PM #8
- Join Date
- Sep 2008
- Location
- Voorschoten, the Netherlands
- Posts
- 11,408
- Blog Entries
- 7
- Rep Power
- 17
You're trying to cram too much in a single class; crucial to your processor is this little list:
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.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};
kind regards,
JosWhen people rob a bank they get a penalty; when banks rob people they get a bonus.
Similar Threads
-
instruction apparently not executed
By rippon in forum AWT / SwingReplies: 4Last Post: 11-30-2010, 01:30 AM -
Help with instruction
By diegoyj in forum New To JavaReplies: 1Last Post: 01-27-2010, 10:09 PM -
I am new, can anyone help me in Computer Vision?
By howardL in forum IntroductionsReplies: 0Last Post: 04-23-2009, 09:37 AM -
Is there anyone can give a instruction about Myoodb
By ibmzz in forum JDBCReplies: 0Last Post: 01-19-2008, 09:04 AM -
First Typed via video instruction
By ZAXTHEGREAT in forum New To JavaReplies: 15Last Post: 07-23-2007, 04:27 PM


LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks