Results 1 to 3 of 3
  1. #1
    Quan567's Avatar
    Quan567 is offline Member
    Join Date
    Mar 2011
    Posts
    11
    Rep Power
    0

    Default Create a Processor Simulation

    Hello All,

    Im trying to create a simple processor simulation but Im having the toughest time storing my file and then creating the Algorithms needed for my PC, AC, and MAR registers.

    Heres the instructions for the algorithm:

    00 (DATA) Not an instruction. Memory location holds some data value.
    01 LOAD Load memory into AC register
    02 ADD Add memory into AC register
    03 SUB Subtract memory from AC register
    04 JUMP Set PC Register to memory
    05 MOV Copy AC into Memory
    15 HALT Stop all execution. Your program ends here. Output the current state of memory and all register values.

    *Numbers on the side is the opcode
    The maximum value for an opcode is 15. The maximum value for a memory address or a memory value is 9999.

    Constraints:

    The only available memory is what is given in the initial text file.
    All lines are separated by newline characters (\n). All characters in the textfile are encoded using standard ASCII.
    There will not be any invalid instructions in memory.
    Upon starting the PC register will always point to valid memory.
    The PC register will be incremented by one after each instruction, except when you encounter a JUMP. Just set the PC register to the proper value when you encounter a JUMP.
    No JUMP instruction will ever take you to non-executable memory.
    You should interpret all integer values in the text file as base-10 (decimal) numbers.
    When you reach a HALT instruction, you are done executing.
    A MOV instruction leaves the AC intact.
    The MAR changes in accordance with the memory address last accessed by a LOAD, ADD, SUB, JUMP, or MOV instruction.

    Code I have thus far:

    import java.io.*;
    class Simulator
    {
    public static void main(String args[])
    {
    try{
    // Open the file that is the first
    // command line parameter
    FileInputStream fstream = new FileInputStream("memory.txt");
    // Get the object of DataInputStream
    DataInputStream in = new DataInputStream(fstream);
    BufferedReader br = new BufferedReader(new InputStreamReader(in));
    String strLine;
    //Read File Line By Line
    while ((strLine = br.readLine()) != null) {
    // Print the content on the console
    System.out.println (strLine);
    }
    //Close the input stream
    in.close();
    }catch (Exception e){//Catch exception if any
    System.err.println("Error: " + e.getMessage());
    }
    }
    }

    SOMEONE PLZ HELP ME!!! :confused:

  2. #2
    Junky's Avatar
    Junky is offline Grand Poobah
    Join Date
    Jan 2011
    Location
    Dystopia
    Posts
    3,800
    Rep Power
    7

    Default

    Duplicate post

  3. #3
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,315
    Blog Entries
    1
    Rep Power
    26

Similar Threads

  1. Java Picture Processor: PGM files and Arrays
    By snow_mac in forum New To Java
    Replies: 0
    Last Post: 11-30-2010, 02:16 PM
  2. Simulation in Java
    By Eranga in forum Advanced Java
    Replies: 15
    Last Post: 08-15-2010, 05:32 AM
  3. beehive simulation
    By BlueF4re in forum New To Java
    Replies: 2
    Last Post: 12-02-2009, 09:31 AM
  4. Address space with 32-bit processor
    By GlideKensington in forum New To Java
    Replies: 1
    Last Post: 04-06-2009, 08:31 PM
  5. Pulley Simulation..HELP
    By dazza-s in forum Java 2D
    Replies: 2
    Last Post: 06-18-2008, 11:51 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
  •