Solved

reseting

Posted on 2004-03-29
4
203 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 500 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

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Are you developing a Java application and want to create Excel Spreadsheets? You have come to the right place, this article will describe how you can create Excel Spreadsheets from a Java Application. For the purposes of this article, I will be u…
In this post we will learn different types of Android Layout and some basics of an Android App.
Viewers learn about the scanner class in this video and are introduced to receiving user input for their programs. Additionally, objects, conditional statements, and loops are used to help reinforce the concepts. Introduce Scanner class: Importing…
Viewers will learn about if statements in Java and their use The if statement: The condition required to create an if statement: Variations of if statements: An example using if statements:

617 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