Do these 2 codes do same thing?

classic Classic list List threaded Threaded
7 messages Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Do these 2 codes do same thing?

inyeop
//RAM[17] = 10
@17
M = 10

or
//RAM[17] = 10
@10
D=A
@17
M=D

Thanks!
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Do these 2 codes do same thing?

ybakos
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...
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Do these 2 codes do same thing?

inyeop


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".
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Do these 2 codes do same thing?

ybakos
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!
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Do these 2 codes do same thing?

inyeop
Ah.. Thanks! I much appreciate it. :)
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Do these 2 codes do same thing?

cadet1620
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
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Do these 2 codes do same thing?

ybakos
Somebody is getting rusty!
Loading...