Results 1 to 19 of 19
Thread: hELP WITH A PROCESSOR SIMULATION
- 03-23-2011, 12:58 AM #1
hELP WITH 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!!!
- 03-23-2011, 01:16 AM #2
Spell words out in full. Using plz makes you look childish.
Do not use caps. Nobody likes being shouted at.
Help with what? Ask a specific question and get a specific answer.
- 03-23-2011, 01:23 AM #3
Another thing do not double post.
- 03-23-2011, 01:27 AM #4
thank you for all of your Critique I will take it into consideration on my next post. my first question would be based on all the information provided above how would i store the data that is being read into java from the text file Im using (memory.txt)
- 03-23-2011, 01:33 AM #5
Can you post the contents of memory.txt?
- 03-23-2011, 01:35 AM #6
the contents of memory.txt:
0100:00:2039
0101:00:0293
0102:00:1349
0103:00:0032
0104:00:6002
1105:01:0101
1106:02:0104
1107:02:0102
1108:03:0101
1109:04:1113
1110:02:0100
1111:02:0102
1112:04:0100
1113:05:0101
1114:15:0000
- 03-23-2011, 01:49 AM #7
Since this is a simulation you would use variables and/or arrays to represent memory and registers. Read the entire file and store the instructions somewhere. Then begin processing the instructions which will require you to update your "memory" and "registers".
- 03-23-2011, 01:53 AM #8
ok thanks. im working on it right now. ill post what i have in a bit.
- 03-23-2011, 02:21 AM #9
A small bit of what im doing but im stuck. im trying to take each line thats being read in, assign it to pc:mar:ac and execute the instructions but i honestly dont know how to do it.
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) {
int pc, ac, mar;
strLine = pc:mar:ac;
private final int maxMAR = 15;
public void Count ()
{
if (mar < maxMAR) mar++;
else return HALT;
}
- 03-23-2011, 02:26 AM #10
Member
- Join Date
- Mar 2011
- Posts
- 2
- Rep Power
- 0
Lolol Njit cs332 wed night class? its cool I need help too :)
- 03-23-2011, 02:36 AM #11
zbest, how far have you gotten with the program?
- 03-23-2011, 02:37 AM #12
Member
- Join Date
- Mar 2011
- Posts
- 2
- Rep Power
- 0
I'm further behind then you are dude, honestly programing isnt my strongest suit
- 03-23-2011, 02:38 AM #13
Not much of your code makes any sense.
I'm sorry but this is a complete mess. It appears you do not have much idea of what you are doing. I suggest talking to your teacher or a tutor and getting some one-on-one help.Java Code:while ((strLine = br.readLine()) != null) { // ok upto here int pc, ac, mar; // each time around the loop you get new variables. You could do this but I would declare them once and just update their values strLine = pc:mar:ac; // you read a line into strLine above and then throw it away here. Plus this is not even legal syntax. private final int maxMAR = 15; // cannot declare a private int here. Plus what is for? public void Count () // not legal, cannot declare a method inside the main method. Plus what is it for? { if (mar < maxMAR) mar++; else return HALT; // what is HALT? Plus the method is void so you cannot return anything }
- 03-23-2011, 02:59 AM #14
i agree. im just trying out different method. i have a different version of the program written down.
import java.io.*;
class Simulator
{
public static void main(String args[])
{
try {
FileOutputStream fos = new FileOutputStream("memory.txt");
ObjectOutputStream oos = new ObjectOutputStream(fos);
//Flush and close the ObjectOutputStream
oos.flush();
oos.close();
//Now that the data is saved. Its time to bring it back and execute instructions
FileInputStream fstream = new FileInputStream("memory.txt");
ObjectInputStream ois = new ObjectInputStream(fstream);
ois.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
But with this one I still need to set variables for my memory and registers however i dont quite know how to do that. any suggestions?
- 03-23-2011, 03:11 AM #15
0100:00:2039
I'm still unsure what the instructions should do. I'm guessing this means store 2039 in memory location 100 but not 100% sure. I would speak to your lecturer to clarify.
Also insturctions say that PC should increment by 1 but after 0104 it jumps 1001 to 1105. Seek clarification.
You need to look at each instruction, spilt it into the three parts. Use String.split on :. Then you know what instruction is to be performed (the middle value) and which registers/memory locations need to accessed and values retrieved or set.
I cannot stress enough that if you are not understanding this assignment go and talk to the lecturer as he/she knows and I'm only guessing.
- 03-23-2011, 03:15 AM #16
thank you for all of your help. i will definitely be going to speck to my professor tomorrow. we just came off of spring break and he was unreachable. but once again thanks for the help. if anything changes with the program ill post it.
- 03-23-2011, 03:18 AM #17
oh and by the way this is the output he has:
CPU halted.
------------
0100:00:2039
0101:00:7351
0102:00:1349
0103:00:0032
0104:00:6002
1105:01:0101
1106:02:0104
1107:02:0102
1108:03:0101
1109:04:1113
1110:02:0100
1111:02:0102
1112:04:0100
1113:05:0101
1114:15:0000
------------
PC = 1113
AC = 7351
MAR = 101
------------
- 03-23-2011, 07:29 AM #18
- Join Date
- Sep 2008
- Location
- Voorschoten, the Netherlands
- Posts
- 11,408
- Blog Entries
- 7
- Rep Power
- 17
When people rob a bank they get a penalty; when banks rob people they get a bonus.
- 03-23-2011, 08:32 PM #19
hello everyone, I talked to my TA today because he was the one that actually created the assignment and when I brought up the points that you guys had made about the programs instructions he said they were perfectly fine. So with that being said this is what I have so far; I know there are syntax errors, I need help debugging.
import java.io.*;
import java.util.*;
class Simulation
{
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;
int pc = strLine.substring(0,3);
int mar = strLine.substring(4,5);
int ac = strLine.substring(6,9);
//Read File Line By Line
while ((strLine = br.readLine()) != null) {
class HashTable{
int pc, mar, ac;
HashTable <String> mem = new HashTable <String>();
mem.pc(index, line);
mem.get(pc);
if(mar = 01){
mem.get(pc);
ac = ac;
pc++;
}else if(mar = 02){
mem.get(pc);
ac = ac+pc;
pc++;
} else if(mar = 03){
mem.get(pc);
ac = ac-pc;
pc++;
}else if(mar = 04){
mem.get(pc);
pc = ac;
pc++;
} else if(mar = 05){
mem.get(pc);
ac = ac;
pc++;
}else if(mar = 15){
System.exit(0);
}
}
}
//Close the input stream
in.close();
}catch (Exception e){//Catch exception if any
System.err.println("Error: " + e.getMessage());
}
// Print the content on the console
System.out.println (strLine);
}
}
Similar Threads
-
Create a Processor Simulation
By Quan567 in forum Advanced JavaReplies: 2Last Post: 03-23-2011, 01:28 AM -
Java Picture Processor: PGM files and Arrays
By snow_mac in forum New To JavaReplies: 0Last Post: 11-30-2010, 01:16 PM -
Simulation in Java
By Eranga in forum Advanced JavaReplies: 15Last Post: 08-15-2010, 04:32 AM -
beehive simulation
By BlueF4re in forum New To JavaReplies: 2Last Post: 12-02-2009, 08:31 AM -
Address space with 32-bit processor
By GlideKensington in forum New To JavaReplies: 1Last Post: 04-06-2009, 07:31 PM


LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks