Error during StackTest.tst execution

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

Error during StackTest.tst execution

xor
This post was updated on .
"In line 1, unexpected end of line"

What is this about if first line in asm should be like @256 to bootstrap the hardware?  Which could be the possible mistakes?

P.S.: maybe I've found the mistake, but I don't know the cause. Practically in my fprintf i've putted the following asm line code: M=D-M but after the translation in the asm file appears M=M-D. How is that possible?

Thanks
Reply | Threaded
Open this post in threaded view
|

Re: Error during StackTest.tst execution

cadet1620
Administrator
xor wrote
"In line 1, unexpected end of line"

What is this about if first line in asm should be like @256 to bootstrap the hardware?  Which could be the possible mistakes?
You don't need to add any bootstrap code for StackTest.

The error message that you are getting happens if CPUEmulator encounters an incomplete instruction like
    D=
or
    @
It gets to the end of the line while it is looking for the next part of the instruction.

Warning: for the "@" command missing its argument, or a "(" command missing its label or ")", the line number appears always to be reported as "line 1" regardless of where the error actually occurred.
P.S.: maybe I've found the mistake, but I don't know the cause. Practically in my fprintf i've putted the following asm line code: M=D-M but after the translation in the asm file appears M=M-D. How is that possible?
I don't see this happening with M=M-D / M=D-M. It does happen with M=M+D / M=D+M.

M=M-D and M=D-M generate different machine instructions, but M=M+D and M=D+M generate the same machine instruction.

When CPUEmulator loads ASM code it translates the ASM to machine instructions and loads them into the ROM.  When it displays the code in the ROM panel, it disassembles the machine instructions.  Therefore it cannot know if the original ASM had "M+D" or "M-D". It always displays "D+M" which is how the instruction is documented in the book.

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

Re: Error during StackTest.tst execution

xor
This post was updated on .
Thanks for the quick answer. I've tried to check @command and labels. Effectively i've wrote (LABEL\r\n) instead of (LABEL)\r\n. But now the comparison fails at line 2 during StackTest.tst execution. I'm really struggling to find the mistake. Do you have some advices?

Due to the fact that SimpleAdd.tst gone fine and SimpleAdd.vm consists of just 3 vm line of codes,...

push constant 8
push constant 7
add

...while StackTest.vm starts with:

push constant 17
push constant 17
eq
...

....so I was thinking that my eq implementation was wrong. Anyway how can I know where exactly is the mistake within my nameFile.asm by looking at nameFile.out?
Reply | Threaded
Open this post in threaded view
|

Re: Error during StackTest.tst execution

cadet1620
Administrator
StackTest.out should show you the results of each of the operations on the stack.

Since there are no pops, each operation's result is left in incrementing addresses starting with 256.  Look at StackTest.out you should see these results for the comparisons:
  256  17 == 17       -1
  257  17 == 16        0
  258  16 == 17        0
  259  892 < 891       0
  260  891 < 892      -1
  261  891 < 891       0
  262  32767 > 32766  -1
  263  32766 > 32767   0
  264  32766 > 32766   0

One common error is to misunderstand the result value expected from the compare operators. Many people think that they should return 1 for TRUE instead of -1.

Another useful suggestion is to write the VM source lines as comments in the ASM output so that you can more easily find the code generated for individual VM commands.  My VM translator indents the comments to make them easier to read. [Don't look for clues here; this isn't real ASM code.]
    AM=M+1
    A=A-1
    @51
        // push this 3
    M=0
    A=M
    D=A
    M=D
    A=A-1
    @ARG
    D=A
    @$564
        // neg
    @5
    D=A
    D=A
    M=D
        // pop this 2
    @$19
    @LCL
    @SP

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

Re: Error during StackTest.tst execution

xor
This post was updated on .
Thank you again Mark. In my output file at RAM[0] i have 260 while in the cmp file is 266 is this related with the stack inizialization? Anyway I'm going to comment my asm file I'm sure it will help me. Thanks.

Below my asm code for some of the starting commands. I've read them again and again. Maybe I'm blind or I'm looking at the wrong place to find the mistake.  UPDATE: thiis my commented version of the asm code. I can't really understand that RAM[0]=266 in the cmp file and also RAM[0]=260 in my out file.
P.S. maybe is better that you copy/paste the code. In the preview it looks like ok but when I post the message it looks a mess.




My out file

|  RAM[0]  | RAM[256] | RAM[257] | RAM[258] | RAM[259] | RAM[260] |
|     260  |      -1  |       0  |      -1  |     -91  |      82  |
Reply | Threaded
Open this post in threaded view
|

Re: Error during StackTest.tst execution

cadet1620
Administrator
xor wrote
Thank you again Mark. In my output file at RAM[0] i have 260 while in the cmp file is 266 is this related with the stack inizialization? Anyway I'm going to comment my asm file I'm sure it will help me. Thanks.

Below my asm code for some of the starting commands. I've read them again and again. Maybe I'm blind or I'm looking at the wrong place to find the mistake.  UPDATE: thiis my commented version of the asm code. I can't really understand that RAM[0]=266 in the cmp file and also RAM[0]=260 in my out file.
P.S. maybe is better that you copy/paste the code. In the preview it looks like ok but when I post the message it looks a mess.
You can put <raw> and </raw> tags around your code and output samples and they will use a fixed pitch font. The tabs will be expanded and your code will look like this:
	//bootstrap  
@256				A=256	
D=A				        D=256
@SP				        A=0
M=D				        RAM[0]=256
	//push constant 17       
@17				        A=17
D=A				        D=17
  [...]
	//eq  
  [...]
@TRUEEQ
D;JEQ				D=0
  [...]
@ENDEQ
0;JMP
(TRUEEQ)
  [...]
@ENDEQ
0;JMP
(ENDEQ)
	 //push constant 17
  [...]
	//push constant 16
  [...]
	//eq
  [...]
@ENDEQ
0;JMP
(TRUEEQ)
  [...]
@ENDEQ
0;JMP
(ENDEQ)
	// push constant 16
	//push constant 17
	//eq
(TRUEEQ)
  [...]
@ENDEQ
0;JMP
(ENDEQ)

The problem that you are running into is that you are using the same label names in all three of the code segments generated for "eq".  When the first "eq" jumps, it jumps to the label in the last "eq", so the second and third "eq" tests get skipped.

I wrote a
    String uniqueLabel(String name)
function for my VM translator that adds '$' and an incrementing serial number to name. (The reason for the '$' is to make it impossible for the name to coincide with a legal symbol name from the Jack compiler.)

Please edit you post to remove the VM code now that we've identified the problem. We want students to be able to do their own work.

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

Re: Error during StackTest.tst execution

ivant
In reply to this post by xor
If I remember correctly, StackTest the other tests from project 7 should be run without the bootrstrap code. I think it was implemented in project 8.

The tests are written with that in mind and so they fail if you add bootstrapping.
xor
Reply | Threaded
Open this post in threaded view
|

Re: Error during StackTest.tst execution

xor
In reply to this post by cadet1620
Thanks Mark. I had two problem: M = M-1 command instead of A=M-1 and the one you said. I fixed both and finally I've ended StackTest.tst
Obviously now I've the same comparison failure at line 2 with BasicTest.tst   XD
xor
Reply | Threaded
Open this post in threaded view
|

Re: Error during StackTest.tst execution

xor
Should I initialize static segment at ram address 16? I mean if I have to translate pop static 4, is wrong to put the last number in the stack in RAM[4] (which should contain that theoretically).
Reply | Threaded
Open this post in threaded view
|

Re: Error during StackTest.tst execution

cadet1620
Administrator
xor wrote
Should I initialize static segment at ram address 16?
The static segment does not refer to any block of fixed memory addresses. Static variable are assembly language RAM variables.

From the book, chapter 7, Memory Segments Mapping
static: According to the Hack machine language specification, when a new symbol is encountered for the first time in an assembly program, the assembler allocates a new RAM address to it, starting at address 16. This convention can be exploited to represent each static variable number j in a VM file f as the assembly language symbol f.j. For example, suppose that the file Xxx.vm contains the command "push static 3". This command can be translated to the Hack assembly commands "@Xxx.3" and "D=M", followed by additional assembly code that pushes D’s value to the stack.
--Mark