PDA

View Full Version : Input into Memory help



drummond
04-27-2007, 02:57 AM
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.

Twey
04-27-2007, 10:06 AM
"Having difficulty" how?

mburt
04-27-2007, 10:58 AM
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.

drummond
04-28-2007, 08:54 AM
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.

ken_
05-27-2007, 06:57 PM
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 (http://www.hoobin.com)