simple assignment in Hack

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

simple assignment in Hack

linuxford
I created a two-line .asm file that has these two lines:

@a
M=16

with the idea placing the binary value of 16 into the a memory location. The Assembler says "In line 1. Expression expected." If I change the code to this

@a
M=1

it will work. I am not clear as to why as I am still trying to wrap my head around Chapter 4.

Thanks for any insights and hints.
Reply | Threaded
Open this post in threaded view
|

Re: simple assignment in Hack

Shimon Schocken
Administrator
There is no such command M=16 in the Hack language. The only way to enter a constant c into the machine is to do @c followed by D=A.  For example, consider the following:

// Puts the constant 16 in RAM[10]:
@16  // A = 16
D=A  
@10  // makes M stand for RAM[10]
M=D

If you don't fully understand this, read Chapter 4 in the TECS book.

-- Shimon
Reply | Threaded
Open this post in threaded view
|

Re: simple assignment in Hack

linuxford
This post was updated on .
Thank you sir . I think I am understanding. Your response

Shimon Schocken wrote
There is no such command M=16 in the Hack language.
got me thinking. So I went back to the book again.

The D=A is a "C-instruction", 0110000. I decoded the "comp" bits and found the ALU computation ends up outputting A (figure 4.3), which is 16.
The Destination bits are 010, which says that the ALU output will be fed into the D register (Figure 4.4).

[update]
Thanks again. I got the my Mult.asm successfully working.