# How do I get a value of a RAM by given address? [closed]

I think I know how RAM works, but I have an exercise where I have to read at the address 0x????.

Furthermore, I am only interested what value get returned after the reading command. For example:

There is a RAM and the whole RAM is filled with (so it's repeating)

 \$22476BFF 273C22FF. . .


Now I read the content at the adress "0x2901": (Here is my code, but actually I only need a theoretical answer)

Loop: LD R17,Y+  // Y =0x2901
JMP Loop


Description: (You may skip)

In this code I read with LD R17, Y+ the content of the Register of the RAM with the address of Y and save this content in the register R17. (I hope you understand me).

Solution:

The content which got read is "0x47", but I am not sure why.

Could it be that if Y is "0x2900" would the content be "0x22"? If so, what would be at the address "0x2908"? (=0x22, because it's repeating?)

I am using Eclipse as a platform. I don't believe it's necessary but I'm using an AVR ATMega162 board.

Or maybe you know an example which is similar to that.

Thanks for the help

• Do you know how many hardware architectures with different assembly instruction sets out there? Jan 19, 2016 at 21:39
• Yeah, but I guess the structur of a RAM should be nearly the same. Jan 19, 2016 at 21:40
• So I guess you didn't get my message. You should mention the platform you are talking about at the very least when asking about assembly code. Jan 19, 2016 at 21:42
• "I dont believe it´s nessesary but" - you're right it's not necessary; it's essential. Reading RAM follows the same method regardless of hardware, yes, but what you type into your computer changes from one system to the next. Jan 19, 2016 at 22:11
• I don't even understand what you are asking. Are you asking anything? You have listed code, you tell us what it does, and it does what you expect. What do you want us to say?
– pipe
Jan 19, 2016 at 22:35

an address is no different than the address on houses in a street or in the world. with the properly formed address you can find an individual house, knock on the door and find what is stored inside.

ram is like that but simpler, the contents of an address are fixed in size, an 8 bit wide ram, the contents are 8 bits. of coarse the confusion can/does come in that the same address MIGHT be able to be accessed as a 16 bit read or a 32 bit read ora 64 bit read. and then endians get involved. big enders and little enders.

yes if you assume that your ram is filled with a repeating pattern of 8 bytes, then in theory if you read a byte at address K then the byte at address K+8 will have the same value, so long as those addresses are in the space that contains the ram. if that address space is for peripherals or a space that has nothing behind it, then you get something else.

so this is an endian thing but if address K has the value 0x47 and K+1 has 0x6B then K-1 should have 0x22. but if K+1 has 0x22 then K-1 should have 0x6B. that is if you are speaking generically, theoretically. your specific avr platform the answer is known. you have not though shown your data in an understandable format though so it is still subject to interpretation.

You need to think of RAM as a giant wall full holes and the holes are numbered with labels, i.e. their address.

When you program your controller, all of your variables get thrown into these cubbies at RANDOM. You don't know what is stored in RAM until you access that memory. Generally, things like strings or arrays, are kept closer together but that's not always the case for every RAM.

So, to assume that byte 0x22 will be in location address 0x2900 is not certain, UNLESS, you put it there yourself.