Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

reseting

Posted on 2004-03-29
4
Medium Priority
?
205 Views
Last Modified: 2010-03-31
Guys I got a problem. I am working on my CPU simulator. Now I want to implement the reset button that when I press the simulator goes to its original state.

I have got a textArea where I put the assembly code. So I have to take the code and break it and put into the memory of the simulator. I am able to break the code using the stringtokenizer and put it into the memory of the simulator.

To reset, I set all the strings to null string and all the numbers to 0. When I press the reset button, it clears every nicely, but the problem is when I change the assembly code, it does not take the new code and put it into the memory of the simulator, it uses the old previous code. Why because I cleared everthing? How can I do it successfully?

Here is my Reset method:

 public void reset()
{
      ypos=70;
      xpos=245;
      clearRegisters();
      clear();
      repaint(xpos-dx,ypos-dy,r,r);
      stop();
   repaint();

}

Reset is calling clearRegisters and clear, and they as follows:

public void clear()
{
      PCint = 0;
      MARint = 0;
      MBRint = 0;
      ACint = 0;
      ALU = "";
      trackOp = "";
      AC = "";

      content0 = "";
      content1 = "";
      content2 = "";
      content3 = "";
      content4 = "";
      content5 = "";
      content6 = "";
      content7 = "";
      content8 = "";
      content9 = "";
      content10 = "";

      tempc0 = "";
      tempc1 = "";
      tempc2 = "";
      tempc3 = "";
      tempc4 = "";
      tempc5 = "";
      tempc6 = "";
      tempc7 = "";
      tempc8 = "";
      tempc9 = "";
      dataAddress1 = "";
      dataAddress2 = "";
      dataAddress3 = "";
      dataAddress4 = "";
      dataAddress5 = "";
      dataAddress6 = "";
      dataAddress7 = "";
      dataAddress8 = "";
      dataAddress9 = "";
      dataAddress10 = "";
      operation = "";
      r=0;
      
}

public  void clearRegisters()
{      
      PC = "00000000";
      MAR = "00000000";
      MBR = "00000000";
      AC = "00000000";
      IR = "00000000";
}

All this strings I use to fill the registers and memory. content0 to content10 is for memory.

The following code I use to break the code I get from the textArea:

public void BreakCode(String text)
{
      int i=0;
   int j=0;
      int opInd=0;
      int datInd=0;
      int output=0;
      
      StringTokenizer st = new StringTokenizer(text, "\n \\s");
      
      while (st.hasMoreTokens()){      
      
            v.addElement(st.nextToken());

            
            if ((j%2) == 1) {
                  if ((v.elementAt(j-1).toString()).equalsIgnoreCase("LDA"))
                        output = Integer.parseInt(v.elementAt(j).toString());
                  else if ((v.elementAt(j-1).toString()).equalsIgnoreCase("ADD"))
                        output = output +      Integer.parseInt(v.elementAt(j).toString());       
                  else if ((v.elementAt(j-1).toString()).equalsIgnoreCase("SUB"))
                        output = output - Integer.parseInt(v.elementAt(j).toString());
            }
      

      switch(i)
            {
                  case 0:tempc0 = v.elementAt(i).toString();
                               break;
                  case 1:tempc1 = v.elementAt(i).toString();
                               break;
                  case 2:tempc2 = v.elementAt(i).toString();
                               break;
                  case 3:tempc3 = v.elementAt(i).toString();
                               break;
                  case 4:tempc4 = v.elementAt(i).toString();
                               break;
                  case 5:tempc5 = v.elementAt(i).toString();
                               break;
                  case 6:tempc6 = v.elementAt(i).toString();
                               break;
                  case 7:tempc7 = v.elementAt(i).toString();
                               break;
                  case 8:tempc8 = v.elementAt(i).toString();
                               break;
                  case 9:tempc9 = v.elementAt(i).toString();
        }
   
            if ( tempc0.equalsIgnoreCase ("ADD" ) ){
                   content0 = opcodeADD;
                   dataAddress1 = "001";
            }
            else if ( tempc0.equalsIgnoreCase ("SUB" ) ){
                   content0 = opcodeSUB;
                   dataAddress1 = "001";
            }
            else if ( tempc0.equalsIgnoreCase ("LDA" ) ){
                   content0 = opcodeLDA;
                   dataAddress1 = "001";
            }
            else if ( tempc0.equalsIgnoreCase ("INC" ) ){
                   content0 = opcodeINC;
                   dataAddress1 = "001";
            }
            else
                   content0 = tempc0;


            if ( tempc1.equalsIgnoreCase ("ADD" ) ){
                   content1 = opcodeADD;
                   dataAddress2 = "002";
            }
            else if ( tempc1.equalsIgnoreCase ("SUB" ) ){
                   content1 = opcodeSUB;
                   dataAddress2 = "002";
            }
            else if ( tempc1.equalsIgnoreCase ("LDA" ) ){
                   content1 = opcodeLDA;
                   dataAddress2 = "002";
            }
            else if ( tempc1.equalsIgnoreCase ("INC" ) ){
                   content1 = opcodeINC;
                   dataAddress2 = "002";
            }
            else
                   content1 = tempc1;


            if ( tempc2.equalsIgnoreCase ("ADD" ) ) {
                   content2 = opcodeADD;
                   dataAddress3 = "003";
            }
            else if ( tempc2.equalsIgnoreCase ("SUB" ) ){
                   content2 = opcodeSUB;
                   dataAddress3 = "003";
            }
            else if ( tempc2.equalsIgnoreCase ("LDA" ) ){
                   content2 = opcodeLDA;
                    dataAddress3 = "003";
            }
            else if ( tempc2.equalsIgnoreCase ("INC" ) ){
                   content2 = opcodeINC;
                   dataAddress3 = "003";
            }
            else
                   content2 = tempc2;


            if ( tempc3.equalsIgnoreCase ("ADD" ) ){
                   content3 = opcodeADD;
                   dataAddress4 = "004";
            }
            else if ( tempc3.equalsIgnoreCase ("SUB" ) ){
                   content3 = opcodeSUB;
                   dataAddress4 = "004";
            }

            else if ( tempc3.equalsIgnoreCase ("LDA" ) ){
                   content3 = opcodeLDA;
                   dataAddress4 = "004";
            }

            else if ( tempc3.equalsIgnoreCase ("INC" ) ){
                   content3 = opcodeINC;
                   dataAddress4 = "004";
            }

            else
                   content3 = tempc3;


            if ( tempc4.equalsIgnoreCase ("ADD" ) ) {
                   content4 = opcodeADD;
                   dataAddress5 = "005";
            }

            else if ( tempc4.equalsIgnoreCase ("SUB" ) ){
                   content4 = opcodeSUB;
                   dataAddress5 = "005";
            }
            else if ( tempc4.equalsIgnoreCase ("LDA" ) ){
                   content4 = opcodeLDA;
                   dataAddress5 = "005";
            }
            else if ( tempc4.equalsIgnoreCase ("INC" ) ){
                   content4 = opcodeINC;
                   dataAddress5 = "005";
            }
            else
                   content4 = tempc4;


            if ( tempc5.equalsIgnoreCase ("ADD" ) ){
                   content5 = opcodeADD;
                   dataAddress6 = "006";
            }
            else if ( tempc5.equalsIgnoreCase ("SUB" ) ){
                   content5 = opcodeSUB;
                   dataAddress6 = "006";
            }
            else if ( tempc5.equalsIgnoreCase ("LDA" ) ){
                   content5 = opcodeLDA;
                   dataAddress6 = "006";
            }
            else if ( tempc5.equalsIgnoreCase ("INC" ) ){
                   content5 = opcodeINC;
                   dataAddress6 = "006";
            }
            else
                   content5 = tempc5;


            if ( tempc6.equalsIgnoreCase ("ADD" ) ) {
                   content6 = opcodeADD;
                   dataAddress7 = "007";
            }
            else if ( tempc6.equalsIgnoreCase ("SUB" ) ){
                   content6 = opcodeSUB;
                   dataAddress7 = "007";
            }
            else if ( tempc6.equalsIgnoreCase ("LDA" ) ){
                   content6 = opcodeLDA;
                   dataAddress7 = "007";
            }
            else if ( tempc6.equalsIgnoreCase ("INC" ) ){
                   content6 = opcodeINC;
                   dataAddress7 = "007";
            }
            else
                   content6 = tempc6;



            if ( tempc7.equalsIgnoreCase ("ADD" ) ){
                   content7 = opcodeADD;
                   dataAddress8 = "008";
            }
            else if ( tempc7.equalsIgnoreCase ("SUB" ) ){
                   content7 = opcodeSUB;
                   dataAddress8 = "008";
            }
            else if ( tempc7.equalsIgnoreCase ("LDA" ) ){
                   content7 = opcodeLDA;
                   dataAddress8 = "008";
            }
            else if ( tempc7.equalsIgnoreCase ("INC" ) ){
                   content7 = opcodeINC;
                   dataAddress8 = "008";
            }
            else
                   content7 = tempc7;

      

            if ( tempc8.equalsIgnoreCase ("ADD" ) ) {
                   content8 = opcodeADD;
                   dataAddress9 = "009";
            }
            else if ( tempc8.equalsIgnoreCase ("SUB" ) ){
                   content8 = opcodeSUB;
                   dataAddress9 = "009";
            }
            else if ( tempc8.equalsIgnoreCase ("LDA" ) ){
                   content8 = opcodeLDA;
                   dataAddress9 = "009";
            }
            else if ( tempc8.equalsIgnoreCase ("INC" ) ){
                   content8 = opcodeINC;
                   dataAddress9 = "009";
            }
            else
                   content8 = tempc8;


            if ( tempc9.equalsIgnoreCase ("ADD" ) ){
                   content9 = opcodeADD;
                   dataAddress10 = "010";
            }
            else if ( tempc9.equalsIgnoreCase ("SUB" ) ){
                   content9 = opcodeSUB;
                   dataAddress10 = "010";
            }
            else if ( tempc9.equalsIgnoreCase ("LDA" ) ){
                   content9 = opcodeLDA;
                   dataAddress10 = "010";
            }
            else if ( tempc9.equalsIgnoreCase ("INC" ) ){
                   content9 = opcodeINC;
                   dataAddress10 = "010";
            }
            else
                   content9 = tempc9;

            j+=1;
            i+=1;
      }
      //repaint();
      result = Integer.toString(output);

}




0
Comment
Question by:krizmotlhala
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
4 Comments
 
LVL 5

Accepted Solution

by:
twobitadder earned 2000 total points
ID: 10707490
After you reset are you reading a new value in for the parameter 'text'?

You need this to be the new text from the textArea then you can pass it in to breakCode(String text)

Also:
stop() stops a thread by throwing it a ThreadDeath error.

You kill a thread when you reset.
0
 
LVL 37

Expert Comment

by:zzynx
ID: 10707664
>> it uses the old previous code

1) Your Strings are all cleared. That's for sure.
2) Nevertheless, when you call BreakCode() again it produces the same output

Conclusion: (as twobitadder said)

==> you call BreakCode() with the same text parameter as before.

btw. In java functions better start with a lower case letter: breakCode() [ while classes start with an upper case ]
0

Featured Post

Hire Technology Freelancers with Gigs

Work with freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely, and get projects done right.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Java had always been an easily readable and understandable language.  Some relatively recent changes in the language seem to be changing this pretty fast, and anyone that had not seen any Java code for the last 5 years will possibly have issues unde…
This was posted to the Netbeans forum a Feb, 2010 and I also sent it to Verisign. Who didn't help much in my struggles to get my application signed. ------------------------- Start The idea here is to target your cell phones with the correct…
Viewers learn how to read error messages and identify possible mistakes that could cause hours of frustration. Coding is as much about debugging your code as it is about writing it. Define Error Message: Line Numbers: Type of Error: Break Down…
This tutorial covers a step-by-step guide to install VisualVM launcher in eclipse.
Suggested Courses

670 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question