tag:nand2tetris-questions-and-answers-forum.52.s1.nabble.com,2006:forum-32616Nabble - Chapter 72024-03-29T01:47:14Ztag:nand2tetris-questions-and-answers-forum.52.s1.nabble.com,2006:post-4037424how to test VM translator?2023-10-14T09:29:50Z2023-10-14T09:29:50Zthedumbone
I didn't make the assembler so this is my first project. (maybe I missed how to test in general in this section?) In the videos of chapter 7, prof describes how the VM emulator works but I think he didn't tell us how to test the push, pop and arithmetic-logical commands. Some help needed.
tag:nand2tetris-questions-and-answers-forum.52.s1.nabble.com,2006:post-4037370How do we confirm/test the programs in this chapter?2023-09-21T14:51:26Z2023-09-21T14:51:26Zburge91
I'm a little confused how we verify our program performs correctly. For example does it leave the stack in its proper condition? And are we saving the data to the correct memory location? I have for example written some ASM code for the "add" VM command, how do I test this in isolation?
tag:nand2tetris-questions-and-answers-forum.52.s1.nabble.com,2006:post-4037381book chapters missing2023-09-26T07:12:05Z2023-09-26T07:12:05ZMythicSword
When I open the projects page of the website all the chapters past 6 (so 7,8,9,10,11,12) the book chapters are missing. The image is still there, but it's greyed out and there's no link. Does anyone know why that is. I have talked to some others, and they also have this issue. Thanks.
tag:nand2tetris-questions-and-answers-forum.52.s1.nabble.com,2006:post-4028311How to get memory base adresses2014-08-11T03:21:53Z2014-08-11T03:21:53ZScatman_John
Hello,
<br/><br/>I'm wondering on how we are supposed to acquire the base adresses for the different memory segments.
<br/>Are our programs supposed to read them from the .tst files? When I have the adresses I was thinking of handling the segments with a seperate class(java) and an arraylist.
tag:nand2tetris-questions-and-answers-forum.52.s1.nabble.com,2006:post-4037202Stack-structure is for RAM but program counter only connected with ROM2023-05-22T02:26:54Z2023-05-22T02:26:54ZBigBang
I completed the first part of nand2tetris (great experience btw) and now I take part 2.
<br/><br/>I just don't understand one thing:
<br/>The stack in nand2tetris part 2 works on the RAM, but on the Hack-Computer itself, jumps can only be made in ROM because the RAM is not connected to the program counter.
<br/>Only the ROM ist connected to the program counter in Hack-PC.
<br/><br/>How can I jump on the RAM in Hack-Computer?
<br/><br/>
tag:nand2tetris-questions-and-answers-forum.52.s1.nabble.com,2006:post-4027912and/neg operations2014-03-13T17:28:50Z2014-03-13T17:28:50Zngdrummer
So I'm working on my VM translator for project 7, and getting through the SimpleAdd was a breeze, but now that I'm trying the stack test, I'm running into an interesting error. I'm getting an error from the CPU Emulator saying "In line 274, Expression Expected", so I did some digging.
<br/><br/>In the StackTest.vm, the following lines occur:
<br/><br/>push constant 57
<br/>push constant 31
<br/>push constant 53
<br/>add
<br/>push constant 112
<br/>sub
<br/>neg
<br/>and
<br/><br/>but doesnt neg just give the negative value of the current constant? or am I misunderstanding what neg really means? I'm confused because and seems like an operation that can only be executed on true or false, as I have it set up to give, however, with non 0 or -1 constants, how does and work?
<br/><br/>Thanks
tag:nand2tetris-questions-and-answers-forum.52.s1.nabble.com,2006:post-4035547A bit confused on the pointer notation2021-01-29T03:44:37Z2021-01-29T03:44:37Zcyclogenesis
Please refer to time stamp 3:05 of Unit 1.4's video.
<br/><br/>Pseudo Assembly Code:
<br/>D = *p
<br/><br/>Statements made in the video:
<br/>1. *p refers to the (value stored at) memory location that p points at.
<br/>2. If we said instead D = p, then presumably we'll get the value 257 because that's what p points to.
<br/>3. p is equivalent to 0.
<br/>4. D = p will leave us the contents of ram[0].
<br/><br/>My thoughts and concerns on the above statements:
<br/>1. I am okay with this. It's just de-referencing a pointer. p is a pointer and if I de-reference it, I am accessing the contents of that address. This is my knowledge from C++. In C++, we can de-reference as many times as we want.
<br/><br/>Ex: int num = **p
<br/><br/>This first retrieves the value(address) stored at address p, and then retrieves the values at that address.
<br/><br/><br/><br/>2,3. Now I am getting confused. If p is an address, say 0, then shouldn't D = p leave D = 0?
<br/> Is there a implicit de-reference occurring here?
<br/>
<br/><br/>4. An implicit de-reference seems to be what is occurring then.
<br/> D = p in C would actually be D = *p
<br/> and
<br/> D = *p in C would actually be D = **p.
<br/><br/><br/><br/>Am I misunderstanding this? Thanks your time.
<br/><br/><br/><nabble_embed>https://youtu.be/Iq9KA6qRqXo?t=181</nabble_embed>
tag:nand2tetris-questions-and-answers-forum.52.s1.nabble.com,2006:post-4036898Alternative Explanation of Examples from Lectures2022-09-25T10:17:21Z2022-09-25T10:17:21Zjnb
I created a series of Youtube videos giving an alternative explanation of examples from the lectures.
<br/><br/><a href="https://www.youtube.com/playlist?list=PLYQdoWGZ1qBRgOEFBgP-y6lqcSaqqc8tz" target="_top" rel="nofollow" link="external">https://www.youtube.com/playlist?list=PLYQdoWGZ1qBRgOEFBgP-y6lqcSaqqc8tz</a><br/><br/>It's still a work in progress, but I thought it might be helpful to share it here for anyone trying to understand the stack machine.
tag:nand2tetris-questions-and-answers-forum.52.s1.nabble.com,2006:post-4033688StackTest2019-09-23T07:01:05Z2019-09-23T07:01:05Zjcb
Hi,
<br/><br/>I ran my .asm file from my VM translator against the test files in the CPU emulator for StackTest. I got the correct values in my registers, but the output file didn't print the second line of registers and values.
<br/><br/>Is there something I am doing in my code that creates this issue?
<br/><br/>Thanks
tag:nand2tetris-questions-and-answers-forum.52.s1.nabble.com,2006:post-4036867Can you be more specific about programming prerequisites for Part Two?2022-07-22T20:23:09Z2022-07-22T20:23:09ZHayekk74
In various places, it has been mentioned:
<br/><br/>"The only prerequisite is knowledge of programming at the level acquired in introduction to computer science courses"
<br/><br/>OR
<br/><br/>"Java or Python"
<br/><br/>I know some JavaScript - is that sufficient? If not, can you recommend specific Coursera courses or specializations, the completion of which would be sufficient to finish Part Two? I am primary interested in structured classes with graded quizzes and programming assignments (as opposed to several books recommended in other parts of this forum). I would be GRATEFUL for any recommendations. I am totally addicted to this amazing course and want to continue the journey.
tag:nand2tetris-questions-and-answers-forum.52.s1.nabble.com,2006:post-4032534StackTest Problem2018-11-09T05:00:21Z2018-11-10T22:40:23Zfirgunner
So all the other tests pass except StackTest.
<br/><br/>I have gone through each RAM location referenced in StackTest.out and it lines up perfectly with the state of my memory upon termination of the StackTest.asm, yet the test fails.
<br/><br/>In addition to that, I have gone through each outputted command and written down the expected result beforehand and found that every command correctly satisfies my expectation of them.
<br/><br/>So I have two main questions:
<br/><br/>How does the test fail comparison when StackTest.out matches my memory state exactly. Does the test script examine more than what is output to StackTest.out?
<br/><br/>Secondly, I have begun to doubt my understanding what the commands should do. So I have the following questions:
<br/><br/>Whenever two operands are involved I assume where it matters say in x - y for the sub-command that x is *(SP-2) and y is *(SP-1) or something like that. Or is it the opposite way around? I assume whatever the convention is stays the same for all commands (where it matters of course). I chose that way since when implementing the high-level language we will be pushing onto the stack left-to-right (generally). Is this the wrong assumption.
<br/><br/>I am beginning to wonder whether <i>and</i>, <i>or</i>, and <i>not</i> are bitwise or logical I implemented them as logical (and according to my thorough examination or StackTest.asm (stepping through each line) they work by representing true as 1 and false as 0. Do I have any misunderstandings here?
<br/><br/>(EDIT)
<br/><br/>So I took a look at StackTest.cmp I wasn't aware that was the correct file. My bad. I didn't pay attention to that one video about testing. Anyway, it looks like <i>not</i> is not logical but bitwise and true should be represented as -1 not 1? Is that correct?
<br/><br/><br/>(EDIT)
<br/><br/>I figured it all out except for one thing. in StackTest.cmp the result of a not operation is -91. How can this be? My result is 0 since the operation in the test acts on 1 as a result of the previous or. I am moving on with the course for now since I feel like this is a small detail that I have missed or something but it is still bothering me so I would appreciate any answers and help.
<br/><br/>Thank you.
tag:nand2tetris-questions-and-answers-forum.52.s1.nabble.com,2006:post-4036510What are the "historical reasons" for push and pop?2021-12-22T07:38:48Z2021-12-22T07:38:48Zouverson
Listening to Shimon lecture "VM Abstraction: the Stack".
<br/><br/>At the beginning of the lecture, Shimon says, "One of them is called push for historical reasons and this operation allows us to put the plate on the top of the stack and..."
<br/><br/>What are the "historical reasons" for push and pop? If someone knows.
<br/><br/>Thank you.
tag:nand2tetris-questions-and-answers-forum.52.s1.nabble.com,2006:post-4036495push constant2021-11-30T16:13:08Z2021-11-30T16:13:08Zbikal
The book in chapter 7 says the <i>index</i> is nonnegative integer. Does this mean that can only push positive integers as constant in the VM?
<br/>
tag:nand2tetris-questions-and-answers-forum.52.s1.nabble.com,2006:post-4036293Confusion about memory segmentation2021-08-29T02:01:32Z2021-08-29T02:01:32Zharshchikorde1234@gmail.com
Here in the textbook, it says the RAM is divided into three major spaces i.e
<br/>RAM (from address 0 - 16383) 16Kb
<br/>SCREEN (from address 16384 - 24575) 8Kb
<br/>KEYBOARD (address 24576) 1 Byte
<br/>Total 24576 Bytes
<br/><br/>but if we consider 15 bits of address then the maximum memory that is addressable is 32767
<br/>So the first question is, why are we not using 32767 - 24576 = 8191 bytes?
<br/><br/>The RAM(16383 bytes) is again compartmentalized into memory segments i.e
<br/><b>RAM address Usage</b><br/>0-15 sixteen virtual registers
<br/>16-255 Static variables
<br/>266-2047 Stack
<br/>
<br/>The second question is from 2048 to 16383, What are we using this space for?
<br/><br/>(Continuing....)
<br/><br/>The sixteen virtual registers are as follows:
<br/>SP RAM[0]
<br/>LCL RAM[1]
<br/>ARG RAM[2]
<br/>THIS RAM[3]
<br/>THAT RAM[4]
<br/>TEMP RAM[5-12]
<br/>R13 RAM[13]
<br/>R14 RAM[14]
<br/>R15 RAM[15]
<br/>SCREEN RAM[16384]
<br/>KBD RAM[24576]
<br/><br/>When writing an assembler I have initialized the predefined symbol Table from RAM[5-20] as R0 to R15
<br/>but first five segments are the same, but for writing Virtual machine code we are again segmenting the same space into TEMP, R13,R14 and R15 why is that?
<br/><br/>Also, the sample assembly programs provided to test our own assembler make use of:
<br/>@R0 and @R1, so the question is if our virtual machine commands make use of TEMP then how would it be mapped to the assembly code, for example, if I use TEMP[6] then the same RAM space in assembly code is @R1 or R14 for @R13 in assembly code.
<br/><br/>Please correct me if I have understood the concept in the wrong manner!
<br/><br/>
tag:nand2tetris-questions-and-answers-forum.52.s1.nabble.com,2006:post-4035652Questions about the virtual machine2021-02-08T14:10:58Z2021-02-08T14:10:58Zcyclogenesis
This chapter has been the most difficult not because of the introduction to the stack or the project itself but because they introduce this idea of the virtual machine. I am unsure about the existence of this virtual machine. Let's start off with some quotes from the book.
<br/><br/><i>The basic idea is as follows: Instead of running on a real platform, the intermedi-
<br/>ate code is designed to run on a Virtual Machine. The VM is an abstract computer
<br/>that does not exist for real, but can rather be realized on other computer platforms.</i><br/><br/><i>The result of this elaborate translation process, known as compilation, will
<br/>be yet another text file, containing machine-level code.
<br/>Of course machine language is also an abstraction—an agreed upon set of binary
<br/>codes.</i><br/><br/>The definition of an abstract machine according to wiki is:
<br/><br/><i>An abstract machine, also called an abstract computer, is a theoretical computer used for defining a model of computation. An abstract machine can also refer to a microprocessor design which has yet to be (or is not intended to be) implemented as hardware. An abstract machine implemented as a software simulation, or for which an interpreter exists, is called a virtual machine. </i><br/><br/>My first concern is that when translating assembly into binary, we never talked about the existence of a virtual machine. If intermediate code is meant to run on some abstract machine, why isn't assembly considered an even lower intermediate code that runs on some VM?
<br/><br/>I know assembly is a one-to-one translation to binary. Perhaps this is why it doesn't make sense to say that assembly runs on some virtual machine. The binary runs on a real machine and ergo, there isn't a virtual machine.
<br/>Let's come back to this.
<br/><br/>The first diagram presented in the book is this(figure 1.1 right before chapter 1):
<br/><img src="http://nand2tetris-questions-and-answers-forum.52.s1.nabble.com/file/n4035652/abstractions.png" border="0"/><br/><br/>This shows a hierarchy of abstractions built upon abstractions.
<br/>Looking at the VM block, I will assume the abstract interface is the VM intermediate code itself.
<br/>The implementation of this VM code is the abstract interface of assembly code. Perhaps this is an incorrect assumption.
<br/><br/>My question is this. The VM code runs on a virtual machine. Are there any other virtual machines <b>or</b> abstract machines in this hierarchy?
<br/><br/>If we had the microprocessor design in front of us(which according to the wiki is an abstract machine),
<br/>can't this be used as the abstract interface of the assembly code/machine code?
<br/><br/>I want to say that assembly/machine code can run on an abstract machine(microprocessor architecture),
<br/>but it is not a virtual machine because it isn't "implemented as a software simulation". It is implemented with real hardware. Please correct me if I am wrong.
<br/><br/>Let's skip to the other end up the abstraction diagram.
<br/>High level code is compiled into VM code.
<br/>If VM code is meant to run on some abstract machine that's implemented with software simulation(VM),
<br/>does high level code run on some virtual machine as well?
<br/><br/>Thanks for your time.
tag:nand2tetris-questions-and-answers-forum.52.s1.nabble.com,2006:post-4035551eq implementation in a different way2021-01-29T11:23:16Z2021-01-29T11:23:16Zajksdf
The following code is what I come up when<b> implementing 'eq'</b> in the <b>StackTest.asm</b>. I doubt that if it is possible coz I cannot get the right answer when I passed it to CPUEmulator. Am I missing sth? Thank you very much in advance.
<br/><br/>```
<br/>@SP
<br/> A=M-1
<br/> A=A-1
<br/> D=M //x value
<br/><br/> A=A+1 // M = y value
<br/> D=D-M //x value - y value, save to D register
<br/>
<br/> @SP
<br/> A=M-1
<br/> A=A-1 // go to the value x address location to prepare for the different condition
<br/><br/> @SET_TRUE
<br/> D; JEQ
<br/><br/> M=0 //if not true, set M=0
<br/><br/> (SET_TRUE)
<br/> M=-1 //if true, set M=-1
<br/><br/> @SP
<br/> M=M-1
<br/>```
tag:nand2tetris-questions-and-answers-forum.52.s1.nabble.com,2006:post-4035545Confused about SimpleAdd implementation concept2021-01-29T00:24:20Z2021-01-29T18:10:29Zajksdf
I have a question while I was doing project 7 SimpleAdd just got very confused. Hope that someone can give me some hints. Thank you very much.
<br/><br/><br/>I come across some project7-related posts, some of them mentioned AM=M-1. I tried to search in the book but in vain. I found a <a href="http://nand2tetris-questions-and-answers-forum.32033.n3.nabble.com/Introduction-to-Hack-Assembly-Language-td4032232.html" target="_top" rel="nofollow" link="external">post </a>by 'cadet1620' which include some examples. Do the same logic apply to AM=M-1?
<br/><br/>eg. AD=A+1 Increment A register and set D register to incremented value.
<br/> //AM=M-1 Decrement M register and set M register to decremented. Nothing to do with the A register
<br/><br/>
tag:nand2tetris-questions-and-answers-forum.52.s1.nabble.com,2006:post-4035479why do we need the Stack2021-01-17T22:29:00Z2021-01-17T22:29:00ZJoeyWoo
<br/>We need a intermediate language which is used as the VM language. I think that any language such as Java C++ can do this(maybe I don't get the point this book talk about), I don't understand why we need the Stack.
<br/><br/>Thanks!
tag:nand2tetris-questions-and-answers-forum.52.s1.nabble.com,2006:post-4035447Confused about the VM2021-01-14T04:28:47Z2021-01-17T22:29:37ZJoeyWoo
<b>CONTENTS DELETED</b>
<div class="weak-color">The author has deleted this message.</div>
tag:nand2tetris-questions-and-answers-forum.52.s1.nabble.com,2006:post-4035259Confused about registers2020-11-21T21:53:40Z2020-11-21T21:53:40ZPnick0509
Hello. I've really only gotten to this point by a lot of trial and error and reading the textbook. Things have been difficult to understand so far but now its seeming impossible. When I asked my professor about this they only gave me "add" as an example but I'm not sure what it even means. I've been trying to figure it out for a few hours now trying to decipher it by trial and error to no avail.
<br/><br/>@SP
<br/>AM=M-1
<br/>D=M
<br/>A=A-1
<br/>M=D+M
<br/><br/>My understanding is as follows:
<br/>>@SP loads the stack pointer into register M. The stack pointer is pointing the the position after the top value.
<br/>>AM=M-1 sets Registers A and M to point to the top value in the stack
<br/>After this point I am really uncertain about anything. I don't understand why we decrement A but then don't do anything with it. There are clearly some intersections I am just not seeing. Any help would be greatly appreciated.
<br/>
tag:nand2tetris-questions-and-answers-forum.52.s1.nabble.com,2006:post-4035160push/pop for unallocated addresses?2020-10-24T02:19:50Z2020-10-24T02:19:50ZRoku7
I tried running the MemoryAccess/BasicTest.vm on the VM emulator and noticed that push and pop only works sometimes.
<br/>E.g:
<br/>push constant 10 (works)
<br/>push local 0 (does not work)(out of segment space)
<br/><br/>and
<br/><br/>pop local 0 (does not work)(out of segment space)
<br/>pop temp 6 (does work)
<br/><br/>From what I understand, this happens when there is no start address(pointer) assigned to the particular segment yet.
<br/><br/>However, why does 'pop local 0' not work while 'pop temp 6' works fine?
<br/><br/>Also, for translating into assembly code, do you need to check for such out of segment errors and skip such VM commands? I also read that the VM code should be assumed error free. If so, then is the code in BasicTest.vm purposefully wrong?
tag:nand2tetris-questions-and-answers-forum.52.s1.nabble.com,2006:post-4035067using different languages for different projects2020-09-04T05:46:54Z2020-09-04T05:46:54Zseagul
I wrote my assembler in C, because I wanted to take the opportunity to learn a new language, which is also quite low level.
<br/><br/>I now feel quite comfortable with it, and want to learn new programming languages.
<br/><br/>Will I be able to write my VM translator, compiler and OS in different languages?.
<br/><br/>If so, which of the following languages would be good to use?:
<br/>Java, JS (node?) ,C++, C#, any other sugestions? (python is not listed because I know it quite well)
<br/><br/>Thanks
tag:nand2tetris-questions-and-answers-forum.52.s1.nabble.com,2006:post-4025277Static Segment naming convention2012-10-15T04:14:49Z2012-10-15T04:14:49Zyoav
<div dir="ltr">I am not sure I understand how to deal with the following spec:<div><br clear="all"><div><i>"Each static variable j in file Xxx.vm is translated into the </i></div><div><i>assembly symbol Xxx.j. In the subsequent assemblyprocess, </i></div>
<div><i>these symbolic variables will be allocated RAM space by the </i></div><div><i>Hack assembler."</i></div><div><br></div><div>For example, in the StaticTest.vm exercise, I used variable '<i>StaticTest.8</i>' for the 'push static 8' vm command. The CPU emulator assigns it to RAM(16) and not RAM(24) as one might naively assumes.</div>
<div><br></div><div>Please clarify the rationale behind this spec. </div><div><br></div><div>Thanks</div><div><br></div><br>
</div></div>
tag:nand2tetris-questions-and-answers-forum.52.s1.nabble.com,2006:post-4026690where can i find chapter 7?2013-04-21T09:14:19Z2013-04-21T09:14:19Zmichalh
Hi,
<br/><br/>Where can I find chapter 7 and the full list of instructions to implement?
<br/>(it's not on the Course homepage where chapters 1-6 are available...)
<br/><br/>Thanks,
<br/>Michal.
tag:nand2tetris-questions-and-answers-forum.52.s1.nabble.com,2006:post-4034649how to implement arithmetic?2020-05-16T05:31:20Z2020-05-16T05:31:20Zkawakami
I'm at a loss when I implement arithmetic operations.
<br/>I think I should do "POP 1 or 2 times, execute process and then PUSH".
<br/>But what segments or symbols in the text do I reserve "POP"ed value(s)?
<br/>Arbitrary selected symbol name is OK?
<br/><br/>My guess is as follows. If I have these pseudo vm code,
<br/><br/> push X
<br/> push Y
<br/> add
<br/><br/>asm code would be
<br/><br/>@whereX
<br/>M=0
<br/>@whereY
<br/>MD=j
<br/>@whereResult
<br/>D=D+M
<br/>@SP
<br/>M=D
<br/>@SP
<br/>M=M+1
<br/><br/>Can I declare whereX, whereY and whereResult?
<br/>Are they nothing to do with segments like LCL, ARG, etc?
<br/><br/>Thanks in advance.
tag:nand2tetris-questions-and-answers-forum.52.s1.nabble.com,2006:post-4033521How to write our VM translator if HACK is the first platform on build.2019-08-22T05:53:46Z2019-08-22T05:53:46ZHenoktes722
Now we are actually writing a VM translator for our HACK platform using some other real platform.
<br/><br/>But what if HACK is the first and the only platform, which are currently building, so how can we build our VM translator?
tag:nand2tetris-questions-and-answers-forum.52.s1.nabble.com,2006:post-4033517Mapping VM to hack assembly.2019-08-21T12:02:34Z2019-08-21T12:02:34ZHenoktes722
Mapping VM to hack assembly.
<br/><br/>push constant 7
<br/>push constant 8
<br/>add
<br/><br/>What will be the compact hack assembly of this program, just to check with the output of my VM translator.
<br/>
tag:nand2tetris-questions-and-answers-forum.52.s1.nabble.com,2006:post-4033509Mapping memory access commands?2019-08-21T03:14:32Z2019-08-21T03:52:32ZHenoktes722
"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. This implementation of the static segment is somewhat tricky, but it works."
<br/><br/>At first, when I read the book, it seems working. But when I try to implement the project VM translator, I have a question.
<br/><br/>push static 3 (get the value of static segment at index 3 and push it into the stack).
<br/><br/>but the recommend way of mapping to hack assembly doesn't make sense.
<br/><br/>@Xxx.3
<br/>D=M
<br/>Then push to the stack
<br/><br/>but the first command doesn't tell the assembler the index, 3 , assembler considers "Xxx.3" as a variable which is at memory 16 not 19.
<br/>So does that mean the index doesn't matter, if yes why not push static 0 instead of push static 3?
<br/><br/>
tag:nand2tetris-questions-and-answers-forum.52.s1.nabble.com,2006:post-4033339Liberal use of temp2019-06-23T04:06:55Z2019-06-23T04:06:55Zkb-math
So far I have - out of convenience - used the temp registers i.e., R5,R6, etc. liberally when implementing the "pop segment i" command to save temporary variables. I can see that I will probably use the same strategy in implementing the gt and lt commands (to overcome issues that have arisen in <a href="http://nand2tetris-questions-and-answers-forum.32033.n3.nabble.com/Implementations-of-gt-lt-and-eq-in-asm-td4032816.html" target="_top" rel="nofollow" link="external">http://nand2tetris-questions-and-answers-forum.32033.n3.nabble.com/Implementations-of-gt-lt-and-eq-in-asm-td4032816.html</a>). This means that a call like "pop argument 9" may edit the values in these temp registers.
<br/><br/>Question: is this allowed? Or does our contract assume that a call to "pop argument 9" does not alter the contents of the temp registers?
<br/><br/>For reference, here is my implementation of pop argument 9... notice the @R5 and @R6 lines which make use of temporary variables.
<br/><br/>// pop argument 9
<br/><br/>@SP
<br/>M=M-1
<br/>A=M
<br/>D=M
<br/>// save it for later in the temp, as we will need to put it in the right location in RAM
<br/>@R5
<br/>M=D
<br/><br/>@2
<br/>D=M
<br/>@9
<br/>D=D+A
<br/>// So D is now the actual index of RAM where we want to place the value popped off the stack
<br/>@R6
<br/>M=D
<br/><br/>// finally place the saved value
<br/>@R5
<br/>D=M
<br/>@R6
<br/>A=M
<br/>M=D
<br/>
tag:nand2tetris-questions-and-answers-forum.52.s1.nabble.com,2006:post-4033313Higher order functions2019-06-18T14:24:54Z2019-06-18T14:24:54Zdrbolle
I want to start a little pet project that creates a new Scheme-like language called "Hackeme" to be run on the Hack platform. I actually would like my compiler to produce Hack VM code but I have some doubts.
<br/>Being a Scheme-like language Hackeme should support functions as arguments. However I don't see a way to support this in the Hack VM as it would require dynamic function calls. So do I have to extend the standard VM or did I miss something which would allow me to use the Hack VM as is?
tag:nand2tetris-questions-and-answers-forum.52.s1.nabble.com,2006:post-4033301Having real trouble getting my Vm Translator to work2019-06-17T03:49:57Z2019-06-17T03:49:57ZAmeeno
Hey guys,
<br/><br/>I've spent about 5 days on this project and for some reason, it is failing.
<br/><br/>I can't figure out why.
<br/><br/>I have checked my logic and I really can't see the bug (I have written in python)
<br/><br/><br/>Could you please help me Debug?
<br/><br/>I will post my code:
<br/><a href="https://pastebin.com/ApuEwbUL" target="_top" rel="nofollow" link="external">https://pastebin.com/ApuEwbUL</a><br/><br/>Can you see any obvious problems with my ASM statements?
<br/>
tag:nand2tetris-questions-and-answers-forum.52.s1.nabble.com,2006:post-4032816Implementations of gt, lt, and eq in asm2019-02-01T11:50:57Z2019-02-01T11:50:57ZTimothyJimothy
I'm having trouble implementing these functions in the stack. My first impulse is to compare the values with a subtraction and use a jump to set the return value, but then I run into the problem of the jump label name being reused throughout the program. My next thought is to create random values in python to use as jump labels, but that's just a hacky workaround. This would be so much easier if I could push the instruction pointer to the stack or if there was a flags register.
<br/><br/>Is it possible to do these calculations and get the correct return values without doing jumps?
<br/><br/>
tag:nand2tetris-questions-and-answers-forum.52.s1.nabble.com,2006:post-4032757A couple of questions about memory segments2019-01-26T16:42:51Z2019-01-26T16:42:51ZElliotW
Is 'static i' equivalent in terms of memory allocation to @16+i?
<br/>The chapter notes seem to imply the static memory segment has a unique implementation to the other memory segments, but so far I've programmed it almost exactly like push temp i (except push temp uses 5+i to access RAM[5..12]).
<br/>
<br/>I'm also unsure about what data the push/pop Pointer segment should get. The notes say it should supply the "base address of THIS or THAT", but are the base addresses RAM[3,4] or the value stored in these registers?
<br/>
<br/>TIA.
tag:nand2tetris-questions-and-answers-forum.52.s1.nabble.com,2006:post-4032747Is -1 part of the Virtual Machine language syntax?2019-01-22T11:45:32Z2019-01-22T11:45:32ZAcsor
I'm on my way to implement the lexer/parser layer of the VM language, and am wondering whether such instructions as
<br/><br/>push constant -1
<br/>push local -1
<br/><br/>that is those involving the -1 constant, are allowed. My prejudiced answer is that they are not, but I couldn't find a paragraph or any affirmative excerpt that says it. Is there such a reference, or way of knowing whether -1 is formally included in the VM language syntax?
tag:nand2tetris-questions-and-answers-forum.52.s1.nabble.com,2006:post-4032654What are the 'this' and 'that' memory segments for?2018-12-25T19:43:40Z2018-12-25T19:43:40ZA_Random_Person
Hello! Just wondering. What are the the 'this' and 'that' memory segments for?