Variable declarations in the asm language

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

Variable declarations in the asm language

Albert G
I did not see any place where asm provides the ability to explicitly define memory locations. All that is said is that variables are automatically allocated space from RAM[16] onwards, in the order they appear. So the following sequence:

@a
D=M
...
@b
...
@c

would allocate a in RAM[16], b in RAM[17], c in RAM[18].

However one of the hands-on in the lecture on slide 12 is to implement "arr[7] = 0". That is not really possible since I have no way to specify where "arr" is going to be stored in memory - or rather I have no way to tell the assembler that "arr" occupies, say, 32 words of ram.

Albert
Reply | Threaded
Open this post in threaded view
|

Re: Variable declarations in the asm language

cadet1620
Administrator
Albert G wrote
However one of the hands-on in the lecture on slide 12 is to implement "arr[7] = 0". That is not really possible since I have no way to specify where "arr" is going to be stored in memory - or rather I have no way to tell the assembler that "arr" occupies, say, 32 words of ram.
Assume that arr is an address in RAM, but don't worry about there being no way to allocate a block of storage. Your Hack code will need to set the 7th byte after arr to 0.

(When you get to chapter 7 you'll see that blocks of storage are dynamically allocated and always referenced via pointers.)

--Mark