Pong Hack Comparison Troubleshoot - Please help!

classic Classic list List threaded Threaded
5 messages Options
Reply | Threaded
Open this post in threaded view
|

Pong Hack Comparison Troubleshoot - Please help!

thecoolio1
Anyone,

I have successfully created my assembler in java. It worked for all test files until I got to Pong. I'm lost on how to troubleshoot such a huge program. All I can tell is that it stops the comparison at line 150 @sys.init

The hack value should be 0110100110110010 (27058) but mine is spitting out 0110100111000101 (27077). My thought is that there is something wrong with my second pass.

Would someone please look at my code to see what I might be doing wrong? I'll happily send my files.

Thank you,

thecoolio1
Reply | Threaded
Open this post in threaded view
|

Re: Pong Hack Comparison Troubleshoot - Please help!

thecoolio1
I just noticed Maelstrom's post directly below mine. He seemed to have the same problem as me. I don't follow how he resolved the issue though. I designed my parser to search through the code for labels first and assign their location to the symbol table. I then remove the label from the code. Next I search through the revised code for @symbols that are not integers. I check if the @symbol is in the symbol table already, if not I add it to the symbol table with the currently available memory address starting at 16. I then increment the currently available memory address by 1. Then I continue searching through the code repeating the above steps. Is this correct?

I don't understand why it would work fine for a smaller program like Rect.asm or Max.asm but not scale up to Pong.

Still need help.

thecoolio1
Reply | Threaded
Open this post in threaded view
|

Re: Pong Hack Comparison Troubleshoot - Please help!

ybakos
If a label exists at line 16, are you attributing 16 to the label's symbol? If so, your first label is off by 1, your next is off by 2...
Reply | Threaded
Open this post in threaded view
|

Re: Pong Hack Comparison Troubleshoot - Please help!

thecoolio1
Here is my method to get the symbols from the code and assign them to the symbol table:

int currAddr = 16;

public void getSymbols() {
        for(int i=0; i<cmdArray.size(); i++) {
        String temp = cmdArray.get(i);
        if(temp.contains("(")) {
               String temp2 = temp.substring(1);
               String temp3 = temp2.replaceAll("\\)", "");
               String addr = String.format("%16s", Integer.toBinaryString(i)).replace(" ", "0");
               symTbl.addEntry(temp3, addr);
               cmdArray.remove(i);
        }
         }
         for(int i=0; i<cmdArray.size(); i++) {
        String temp = cmdArray.get(i);
        if(temp.contains("@")) {
               String temp2 = temp.substring(1);
               if(!(isInteger(temp2)) && !(symTbl.contains(temp2))) {
                String addr = String.format("%16s", Integer.toBinaryString(currAddr)).replace(" ", "0");
                symTbl.addEntry(temp2, addr);
                currAddr++;
               }
        }
        }
   }
Reply | Threaded
Open this post in threaded view
|

Re: Pong Hack Comparison Troubleshoot - Please help!

thecoolio1
I figured it out! I need to decrement "i' after I removed the (LABEL) from the cmdArray.

Here is the revised method:

int currAddr = 16;

public void getSymbols() {
        for(int i=0; i<cmdArray.size(); i++) {
        String temp = cmdArray.get(i);
        if(temp.contains("(")) {
               String temp2 = temp.substring(1);
               String temp3 = temp2.replaceAll("\\)", "");
               String addr = String.format("%16s", Integer.toBinaryString(i)).replace(" ", "0");
               symTbl.addEntry(temp3, addr);
               cmdArray.remove(i);
               i--; // Missing this is what was causing the error!
        }
        }
        for(int i=0; i<cmdArray.size(); i++) {
        String temp = cmdArray.get(i);
        if(temp.contains("@")) {
               String temp2 = temp.substring(1);
               if(!(isInteger(temp2)) && !(symTbl.contains(temp2))) {
                String addr = String.format("%16s", Integer.toBinaryString(currAddr)).replace(" ", "0");
                symTbl.addEntry(temp2, addr);
                currAddr++;
               }
            }
        }
   }