StackTest execution not moving beyond a jump instruction

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

StackTest execution not moving beyond a jump instruction

kraftwerk1611
Hi,

I am stuck at testing StackTest.vm and finding no way to come up with a solution.

When I am running StackTest.vm my BasicTest.asm executes up to the line 503 and then it just keeps moving between line 502 and line 503 (screen shot attached). The lines are like these.
@502
0:JMP

The same code is also at previous lines 491 and 492 but code execution got pass that and did not stop there but then it is not moving beyond line 503.

The output file that comes out from this test is empty (attached).

I checked the previous posts on similar topics and heard some thing about unique labels. Could this be the cause of this problem?

If this is the case then what are the unique labels and how to create them and at what point and why are they required here?

The labels in my generated asm appear as

@EQUAL
D;JEQ
@STOP
0;JMP
(EQUAL)

When I run the assembly routines of lt, gt, eq for example they give the desired output but inside the asm file something has gone wrong.

Can someone please give some suggestion how to solve this issue?

Thanks.
StackTest.out

Reply | Threaded
Open this post in threaded view
|

Re: StackTest execution not moving beyond a jump instruction

cadet1620
Administrator
If you are not already doing so, you should write the VM source in the ASM output as comments. This makes it much easier to understand what you are looking at.
// push constant 17
    @17
    D=A
    @SP
    {There's more ASM here I'm not showing.}
// eq
    @RET$3
    D=A
    @$CMP_EQ$
    0;JMP
(RET$3)
// push constant 892
    @892
    D=A
    @SP

The same code is also at previous lines 491 and 492 but code execution got pass that and did not stop there but then it is not moving beyond line 503.
The code at 491 is an unconditional jump to 502, which is also an unconditional jump to 502.  The simulator is doing exactly what the code says to do.

The code at 484 looks like it puts a "true" on the stack and jumps to 502. The code at 493 looks like it puts "false" on the stack and executes directly to 502.

The code at 504 is the beginning of the code for "push constant 57" so you are at the end of all the eq/lt/gt VM commands.

This is strange because if the generated code for gt ends with this infinite loop, it ought to be hung after the  the first gt, not the last.  This makes me think of two possible problems:

1) Are you using the same label names in every compare command translation?  If so, the CPUEmulator's assembler will always jump to the last label with the same name.

2) Why is there an infinite loop at the end of the gt code? Is it accidentally left over from earlier testing?


Note: My code sample above shows my translation for eq doing an assembly language call to a helper routine that contains all the code required to actually do the eq command. This way there is only one copy of the long ASM code for eq.  The $CMP_EQ$ routine looks like
($CMP_JEQ$)     // EQ compare common code
    @R13
    M=D
{All to code that is needed for the eq command.}
    @R13
    A=M
    0;JMP

--Mark
Reply | Threaded
Open this post in threaded view
|

Re: StackTest execution not moving beyond a jump instruction

kraftwerk1611
Thanks for the reply.

I have spent many hours trying to figure out how to create unique labels but I could not find any way to do this.

I can manually create unique labels inside assembly files but first I dont think that is the right way to do it and secondly  I think what you meant in your reply is that if for example there are labels like (STOP) and (COMPARE) in assembly code for 'gt'. And then if this 'gt' is called say 3 times that in the final *.asm file, there should be lines like

(1$STOP)
(2$STOP)
(3$STOP)

Is this right?

Can you give some advice how to create these unique labels and at what point in the execution should we do it.

Also regarding second point in your reply, I did have following commands at the end of each individual assembly code for gt, lt, and eq. But when I remove those lines from code then CPU Emulator stops the execution much earlier after about 2 dozens lines.

(END)
@END
0:JMP


Thanks.

Reply | Threaded
Open this post in threaded view
|

Re: StackTest execution not moving beyond a jump instruction

cadet1620
Administrator
I got your mail and will reply off forum after I look at your code.

--Mark
Reply | Threaded
Open this post in threaded view
|

Re: StackTest execution not moving beyond a jump instruction

kraftwerk1611
The reasons for issue mentioned in this post were were found to be following.

-Every label in asm file should have a unique label. This was not the case with my code and was causing trouble. I assigned labels names like $xLabel where x gets incrmented for each label.

-A habit developed back in chapter 4 was to end assembly files with end loops of type 0:JMP. Unfortunately there were some such inifinite loops in the code,which were stopping the code execution in the middle of execution and that had to be removed.

-I had to go back and consult chapter 4 again and again when doing project 7 to see how each instruction was working.

Hope this helps ones running into same issue.
Reply | Threaded
Open this post in threaded view
|

Re: StackTest execution not moving beyond a jump instruction

linuxford
Yes, it was helpful. Thank you for follow-up post for us stragglers.