ASM explanation

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

ASM explanation

adijo
What does the following code snippet taken from the Hack machine language to sum up 1 to 100 do?

@i
M = 1
@sum
M = 0

From my understanding, @value sets the A register to value. So the A register gets the memory address right? Example: @7 would store 0000000000000111 in the A register, (which is an address in the data memory)

So, what does @i mean? We haven't even specified what i is, how does A store any address?

And when M = 1 is executed, the explanation is i = 1. What exactly happens here? Does the memory location referenced by i in the data memory store the value 1?

I'm really confused! I think that the tutorial should have been more comprehensive



Reply | Threaded
Open this post in threaded view
|

Re: ASM explanation

cadet1620
Administrator
adijo wrote
What does the following code snippet taken from the Hack machine language to sum up 1 to 100 do?

@i
M = 1
@sum
M = 0
When an undefined symbol is first used, a RAM location is automatically assigned to it. The automatic assignments begin at address 16, so this code is equivalent to
    @16
    M = 1    // Stores 1 in RAM[16]
    @17
    M = 0    // Stores 0 in RAM[17]
(This automatic assignment is explained in 4.2.4 which is a forward reference in the text since this example is in 4.2.2.)

--Mark