Nand2Tetris Questions and Answers Forum
›
Architecture
›
Chapter 4
Search
everywhere
only in this topic
Advanced Search
Do these 2 codes do same thing?
Classic
List
Threaded
♦
♦
Locked
7 messages
inyeop
Reply
|
Threaded
Open this post in threaded view
♦
♦
|
Do these 2 codes do same thing?
//RAM[17] = 10
@17
M = 10
or
//RAM[17] = 10
@10
D=A
@17
M=D
Thanks!
ybakos
Reply
|
Threaded
Open this post in threaded view
♦
♦
|
Re: Do these 2 codes do same thing?
This post was updated on
.
Conceptually, yes, they have the same end result.
(Note that you cannot use a constant in the command
M = 10
.)
Edit
: correction below...
inyeop
Reply
|
Threaded
Open this post in threaded view
♦
♦
|
Re: Do these 2 codes do same thing?
But I see in Branching lecture, I see that
@R1
M=0
or
@R1
M=1
I'm a little confused about when I can use direct assignment vs indirect using "D".
ybakos
Reply
|
Threaded
Open this post in threaded view
♦
♦
|
Re: Do these 2 codes do same thing?
You are correct, and my original response is not accurate. I should have said "We can only use the literal constants 0 and 1."
For all other constants, we must use an A instruction.
Thank you for pointing out my error!
inyeop
Reply
|
Threaded
Open this post in threaded view
♦
♦
|
Re: Do these 2 codes do same thing?
Ah.. Thanks! I much appreciate it. :)
cadet1620
Reply
|
Threaded
Open this post in threaded view
♦
♦
|
Re: Do these 2 codes do same thing?
Administrator
You can also directly set A, D or M to -1.
These are "C-instructions" (4.2.3)
dest
=
comp
;
jump
where the
dest
field is one or more of A, D or M, and the
comp
field is 0, 1 or -1.
--Mark
ybakos
Reply
|
Threaded
Open this post in threaded view
♦
♦
|
Re: Do these 2 codes do same thing?
Somebody is getting rusty!
Free forum by Nabble
Edit this page