Advanced Search

Results 1 to 5 of 5

Thread: Input into Memory help

  1. #1
    Join Date
    Apr 2007
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Question Input into Memory help

    Hi I'm having difficulting creating a class called Input to accept the users input, I then want this input to go to my class called Memory.

    I'm truely stumped does anyone have any idea? or could point me in the right direction?

    Thank You
    Cameron.

  2. #2
    Join Date
    Jun 2005
    Location
    英国
    Posts
    11,878
    Thanks
    1
    Thanked 180 Times in 172 Posts
    Blog Entries
    2

    Default

    "Having difficulty" how?
    Twey | I understand English | 日本語が分かります | mi jimpe fi le jbobau | mi esperanton komprenas | je comprends franšais | entiendo espa˝ol | t˘i Ýt hiểu tiếng Việt | ich verstehe ein bisschen Deutsch | beware XHTML | common coding mistakes | tutorials | various stuff | argh PHP!

  3. #3
    Join Date
    Jul 2006
    Location
    Canada
    Posts
    2,581
    Thanks
    13
    Thanked 28 Times in 28 Posts

    Default

    I then want this input to go to my class called Memory
    Er... what exactly do you mean? We'll need more info to help you out.
    - Mike

  4. #4
    Join Date
    Apr 2007
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Question

    Sorry for being so vauge in my last post, I am trying to simulate the process of a computer.

    What I need to do is write lines on the console at the end of each step in the program from a text file. This text file represents the machine code instruction for a cpu.

    The cpu instruction set is:

    1/ Read next instruction into memory.
    2/ Input from keyboard.
    3/ Write memory to output.
    4/ Push memory onto Stack.
    5/ Add stack to memory.
    6/ Pop stack into memory.
    7. Halt.

    The lines being output to the console will be in columns such as:

    Instruction
    1
    adding
    3
    2

    Input



    10

    Memory
    0
    adding
    adding
    10

    Stack
    0
    0
    0
    0

    Output


    adding
    adding


    (there is more but this is the start)


    The instruction column shows each line in the program text file.
    I'm using classes that represent components in the computer e.g. CPU, PROGRAM, MEMORY, INPUT, ALU etc.

    Now I don't want you guys to think I'm one of those posters who has joined asking you to do this for me, it's just that I have no idea what to do next I have done a basic INPUT class but not the kind of INPUT I need to accomplish this task.

    My input class:

    import java.io.*;
    import java.util.*;

    /**
    * Used to recieve input from the user.
    *
    * Cameron Lett
    * 8/4/07
    */


    public class Input
    {

    /**
    * Constructor for objects of class input
    */

    public static void main (String[] args) throws java.io.IOException
    {
    try
    {

    BufferedReader stdin = new BufferedReader(new InputStreamReader(System.in));
    System.out.print("Input a number: ");
    String line = stdin.readLine();
    System.out.println("Adding");
    stdin.close();
    }
    catch (IOException io)
    {
    System.err.println("IO Exception Caught");
    io.printStackTrace();
    }
    }



    }

    So any pointers or advice would be greatly appreciated.
    Thanks.
    Last edited by drummond; 04-28-2007 at 08:09 AM.

  5. #5
    Join Date
    May 2007
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    fair enough, I will try to help ...
    it's not a working code but something like that ...

    BufferedReader stdin = new BufferedReader(new InputStreamReader(System.in));
    System.out.print("Input a number: ");
    String line = stdin.readLine();
    boolean is_loop = true;
    while (is_loop) {
    switch (line.strim()) {
    case "1": //read instruction into memory
    String line = stdin.readLine();
    Momory.push(line); //momory should be stack.
    break;
    case "2": line = stdin.readLine();
    3/ Write memory to output.
    4/ Push memory onto Stack.
    5/ Add stack to memory.
    6/ Pop stack into memory.

    break;
    case "7": is_loop = false;
    default: //do nothing
    break;
    }
    }

    stdin.close();


    ken
    Hoobin.com

Bookmarks

Posting Permissions

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