Lost in addresses

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

Lost in addresses

p.konrad
Hi,

I'm trying to figure out a way to use a number, stored in a symbol ( for example @50, D=A, @addr, M=D ) as the memory address which I want to change next.

Or in other words whatever value "addr" has, I would like to change the memory address, matching this value. If addr = 50 I'd like to set whatever is in the 50th memory location to a new value.

If I just @addr, M= 1, it just changes addr from 50 to 1 doesn't it?

thanks in advance for any help
Reply | Threaded
Open this post in threaded view
|

Re: Lost in addresses

ybakos
That is correct.
Reply | Threaded
Open this post in threaded view
|

Re: Lost in addresses

cadet1620
Administrator
In reply to this post by p.konrad
p.konrad wrote
I'm trying to figure out a way to use a number, stored in a symbol ( for example @50, D=A, @addr, M=D ) as the memory address which I want to change next.

Or in other words whatever value "addr" has, I would like to change the memory address, matching this value. If addr = 50 I'd like to set whatever is in the 50th memory location to a new value.
As you said,
    @50
    D=A
    @addr
    M=D
sets RAM[addr] = 50.

An address stored in a variable is called a pointer. To use the pointer stored in RAM[addr], you need to load that pointer into the A register.
    @addr
    A=M

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

Re: Lost in addresses

p.konrad
alright! Thank you, I think I'm back in the game now. This can get really confusing if you think about it to much ;)
Reply | Threaded
Open this post in threaded view
|

Re: Lost in addresses

16384
In reply to this post by cadet1620
cadet1620 wrote
An address stored in a variable is called a pointer. To use the pointer stored in RAM[addr], you need to load that pointer into the A register.
    @addr
    A=M
But how do you use it to set that address to 1? You need another instruction to set the address to 1, but that would change the A register value.

@addr
A=M
@A
M=1 //doesn't set address of A to 1, it creates another address.
Reply | Threaded
Open this post in threaded view
|

Re: Lost in addresses

cadet1620
Administrator
16384 wrote
cadet1620 wrote
An address stored in a variable is called a pointer. To use the pointer stored in RAM[addr], you need to load that pointer into the A register.
    @addr
    A=M
But how do you use it to set that address to 1? You need another instruction to set the address to 1, but that would change the A register value.

@addr
A=M
@A
M=1 //doesn't set address of A to 1, it creates another address.
"M" uses the address in the A Register to access RAM. Instead of @A, you need to get the value of the pointer variable into A:
    @pointer    // address of variable "pointer"
    A=M         // contents of variable into A
    M=1         // RAM[pointer] = 1

--Mark