A built-in function tried to access memory outside the Heap or Screen range

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

A built-in function tried to access memory outside the Heap or Screen range

helios77
i am trying to run a program but this is the error after every string line. why is that
Reply | Threaded
Open this post in threaded view
|

Re: A built-in function tried to access memory outside the Heap or Screen range

helios77
nand2tetris.zip

This is the file downloaded it also has the jack and vm code. what's wrong?. Is there any thing wrong with the file i downloaded. Can you run the vm code and check
Reply | Threaded
Open this post in threaded view
|

Re: A built-in function tried to access memory outside the Heap or Screen range

ivant
A built-in function could be doing this because of the way it's called. As a rule of thumb, always check if your code is the problem before trying to find bugs elsewhere.

You can attach your code here or you can send it via email to me and I'll see what I can find.
Reply | Threaded
Open this post in threaded view
|

Re: A built-in function tried to access memory outside the Heap or Screen range

helios77
main.jack
main.vm

These are the files thanks for the help
Reply | Threaded
Open this post in threaded view
|

Re: A built-in function tried to access memory outside the Heap or Screen range

dolomiti7
In reply to this post by helios77
First of all, it would be helpful to place this question in one of the appropriate subfolders in this forum (in this case I would presume project 9 is the right place since it is Jack language related. Furthermore, it is easier to understand if you just include the relevant source code section directly in the post and describe exactly what you are trying to achieve and what didn't work.

I presume that your question is related to the file main.jack in the tools folder.

That shows already the first mistake: Jack is case sensitive. And by convention class names should begin with a capital letter. If you open a folder (not a file) with the VM Emulator it will look for Main.vm which should include the VM Code for the class Main (not main).
Therefore: rename the file to Main.jack, change the class name inside the file to Main, and recompile.

Secondly, your source code contains calls that are not complying with the defined API of the OS routines. Check in the book or in the nand2tetris documentation (or in the OS stub files under project 12) the API of the respective OS routines and which parameters are required.

Reply | Threaded
Open this post in threaded view
|

Re: A built-in function tried to access memory outside the Heap or Screen range

helios77
Sorry for the late answer, and thank you I will try that.
Reply | Threaded
Open this post in threaded view
|

Re: A built-in function tried to access memory outside the Heap or Screen range

helios77
Main.jack

Can you check what's wrong with the append in this file. Thank you very much for the help in the previous question. I can run the files now.
Reply | Threaded
Open this post in threaded view
|

Re: A built-in function tried to access memory outside the Heap or Screen range

ivant
Please describe the error or the bad behavior that you see.

One possible problem that I saw is with the line s.appendChar(33); Internally String objects contain arrays of ints (chars). If the array is already full, then this method should fail with an error. If it doesn't check properly, then it would just corrupt the memory and this can result in unpredictable behavior.

The string s is constructed by the call to Keyboard.readLine(). It very well might return a string that is just big enough to contain the read line.
Reply | Threaded
Open this post in threaded view
|

Re: A built-in function tried to access memory outside the Heap or Screen range

helios77
The error is as you mentioned with the s.append. Can you tell me, how do I make it work.
Reply | Threaded
Open this post in threaded view
|

Re: A built-in function tried to access memory outside the Heap or Screen range

ivant
Broadly speaking there are at least two ways. Firstly, you can create a bigger string, copy the existing one and add the additional characters that you need. In Jack the memory is managed manually, so you'll have to remember to free up the allocated memory.

The second approach is easier, at least for this specific case. You can just print the string as it is, and then print the additional exclamation mark as a separate call.
Reply | Threaded
Open this post in threaded view
|

Re: A built-in function tried to access memory outside the Heap or Screen range

helios77
Thank you very much for the help. The code is working now.
Reply | Threaded
Open this post in threaded view
|

Re: A built-in function tried to access memory outside the Heap or Sc

kanishkasj
In reply to this post by helios77
I am also facing the same problem in my VM emulator. how do i rectify it ?