Only RAM[6] comparison failure between NestedCall.out and NestedCall.cmp

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

Only RAM[6] comparison failure between NestedCall.out and NestedCall.cmp

w

NestedCall.out

| RAM[0] | RAM[1] | RAM[2] | RAM[3] | RAM[4] | RAM[5] | RAM[6] |
|    261 |    261 |    256 |   4000 |   5000 |    135 |   5041 |

NestedCall.cmp

| RAM[0] | RAM[1] | RAM[2] | RAM[3] | RAM[4] | RAM[5] | RAM[6] |
|    261 |    261 |    256 |   4000 |   5000 |    135 |    246 |

My NestedCall.asm is:

@256
D=A
@SP
M=D

@ret.0
D=A
@SP
A=M
M=D
@SP
M=M+1
@LCL
D=M
@SP
A=M
M=D
@SP
M=M+1
@ARG
D=M
@SP
A=M
M=D
@SP
M=M+1
@THIS
D=M
@SP
A=M
M=D
@SP
M=M+1
@THAT
D=M
@SP
A=M
M=D
@SP
M=M+1
@5
D=A
@SP
D=M-D
@0
D=D-A
@ARG
M=D
@SP
D=M
@LCL
M=D
@Sys.init
0;JMP
(ret.0)

(Sys.init)
@4000
D=A
@SP
A=M
M=D
@SP
M=M+1

@SP
M=M-1
A=M
D=M
@THIS
M=D

@5000
D=A
@SP
A=M
M=D
@SP
M=M+1

@SP
M=M-1
A=M
D=M
@THAT
M=D

@Sys.init$ret.0
D=A
@SP
A=M
M=D
@SP
M=M+1
@LCL
D=M
@SP
A=M
M=D
@SP
M=M+1
@ARG
D=M
@SP
A=M
M=D
@SP
M=M+1
@THIS
D=M
@SP
A=M
M=D
@SP
M=M+1
@THAT
D=M
@SP
A=M
M=D
@SP
M=M+1
@5
D=A
@SP
D=M-D
@0
D=D-A
@ARG
M=D
@SP
D=M
@LCL
M=D
@Sys.main
0;JMP
(Sys.init$ret.0)

@SP
M=M-1
A=M
D=M
@6
M=D

(Sys.init$LOOP)

@Sys.init$LOOP
0;JMP

(Sys.main)
@0
D=A
@SP
A=M
M=D
@SP
M=M+1

@0
D=A
@LCL
D=D+M
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T
M=D
@2
D=A
@R13
A=M-D
D=M
@THIS
M=D
@3
D=A
@R13
A=M-D
D=M
@ARG
M=D
@4
D=A
@R13
A=M-D
D=M
@LCL
M=D
@R14
A=M
0;JMP

Reply | Threaded
Open this post in threaded view
|

Re: Only RAM[6] comparison failure between NestedCall.out and NestedCall.cmp

WBahn
Administrator
We are not going to debug your code for you.

You can see that the problem is that RAM[6] is not what it is supposed to be.

The first step is to make sure that you agree that it should be 246 and why.

Then work through your code to see if you can determine either why it is making 5041 or why it is not making it 246 (those are somewhat different objectives).

The place to start is NOT with the assembly code listing, but at the VM code level. Determine which statements should be affecting RAM[6] and which ones should not.

Then look at the assembly code that implement those statements.

Do yourself a HUGE favor and have your VM Translator output comments to the ASM file. At the very least, but a comment containing the VM command that is about to be translated followed by the block of ASM code that implements that command.


w
Reply | Threaded
Open this post in threaded view
|

Re: Only RAM[6] comparison failure between NestedCall.out and NestedCall.cmp

w
Thanks!
I realized that I was doing a silly mistake, in the function definition, my VMtranslator was unnecessarily Poping local values.
Now it worked.