FibonacciElement

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

Re: FibonacciElement

Eytan Lifshitz
They mean indirect addressing - using some address as a pointer for another address.
Meaning RET doesn't get assigned with FRAME-5 but RET = RAM[FRAME-5]
Also, we don't change the value of ARG, we change the value of RAM[ARG]

‫בתאריך יום ו׳, 7 באוג׳ 2020 ב-4:09 מאת ‪kingofbuffs [via Nand2Tetris Questions and Answers Forum]‬‏ <‪[hidden email]‬‏>:‬
This maybe a silly question, but what are asterisks meant to convey?

This one:

RET = *(FRAME-5)

or this one:

*ARG = pop()

Maybe I am missing something here?



If you reply to this email, your message will be added to the discussion below:
http://nand2tetris-questions-and-answers-forum.32033.n3.nabble.com/FibonacciElement-tp4034926p4034962.html
To unsubscribe from FibonacciElement, click here.
NAML
Reply | Threaded
Open this post in threaded view
|

Re: FibonacciElement

WBahn
Administrator
In reply to this post by kingofbuffs
kingofbuffs wrote
This maybe a silly question, but what are asterisks meant to convey?

This one:

RET = *(FRAME-5)

or this one:

*ARG = pop()

Maybe I am missing something here?
It's what is known as a pointer dereference notation and is used in C and several other languages.

You can think of it as meaning "The value stored at the memory location whose address is..."

So *42 would mean the value stored at the memory location whose address is 42.

*ARG would then mean the value stored at the memory location whose address is the value stored in ARG.

It is tightly coupled to array index notation, so you can generally think of

*ARG as being the same as RAM[ARG] in the case of Hack assembly.
 
Reply | Threaded
Open this post in threaded view
|

Re: FibonacciElement

Stormtrooper2001
This post was updated on .
In reply to this post by kingofbuffs
please check the following screenshot this label in your code is generated twice so your code loops to the wrong place..!!! Please correct this and let me know if your code works..!!
In fact, there are two instances created for most of your labels. Check other labels like (RIP$$0) also.

Reply | Threaded
Open this post in threaded view
|

Re: FibonacciElement

Stormtrooper2001
In reply to this post by WBahn
I checked this part of his code might not be a really good implementation but it happens to do the work....!!
Reply | Threaded
Open this post in threaded view
|

Re: FibonacciElement

kingofbuffs
This post was updated on .
In reply to this post by Stormtrooper2001
Thank you so much for this, and others for giving insightful answers.

I was messing up two things.

1) Bad coding. I created the the variable that was supposed to increment every time inside the function, so, everytime the function was called, it would initialize the variable to 0, thus creating duplicates.

2) I was not setting the RET correctly. I was setting the RET to FRAME-5, instead of the value of FRAME-5. This was also causing the program to jump to incorrect points. (I was not aware of that asterisk notation, I don't know if it's explained in the book, if it is, I must have missed it.)




Reply | Threaded
Open this post in threaded view
|

Re: FibonacciElement

kingofbuffs
I was able to finish the chapter after working on nested calls for a few hours. After that, statics test passed the test without any additional work. I guess I should be happy but this seems highly suspicious.

Has this also been the case for other people in here?
Reply | Threaded
Open this post in threaded view
|

Re: FibonacciElement

Stormtrooper2001
Glad I could help. Statics test finished fast for mee too. I spent most of my time doing the FibonacciElement only. Good luck with week 3.
12