Chapter 3: Navigating through Memory
Memory memory memory. Also known as RAM. A CPU's instructions will reside in Memory. Also, any data that the CPU needs to read/write to will also reside in Memory. Memory is usually broken up into segments/regions depending on certain intended purpose(s). The region of Memory where a CPU's instructions reside at is usually called Static or Main memory. It's named Static because every time a specific program is executed by the CPU, the CPU instructions are usually placed at the same locations within Static Memory every single time.
The region of Memory where Data is kept at is usually called Dynamic or Heap memory. It's called Dynamic because every time a specific program is executed/launched by the CPU, the Data may not be at the same location it was present at the time before. There are of course exceptions to how Static & Dynamic Memory operate. I am speaking in general terms.
Locations in Memory are called Memory Addresses. Memory Addresses are usually a fixed length when referenced or used by a CPU. The determined fixed length is dependent on the CPU itself and some special properties of the CPU that are determined/written by a program shortly after said CPU has booted or been reset.
Example 32-bit Memory Address:
0x80516074
Understanding values located in Memory:
Data residing within Memory (using some sort of Memory Viewer debugging tool/device) is usually broken up into groups of bytes. There are usually 16 bytes per row.
The above is a random pic of Memory of a random Program. (Side Note: This picture is from a PowerPC program, not ARM. However we can still use it for teaching you how to navigate thru Memory as the concept of navigation is the same for any CPU)
Most Memory Viewers within Debugging Tools will always display the data in Hex form. Since Hex is a Base-16 number system, this is the reason as to why each row is 16 bytes. Memory Viewers are very helpful and give you a good visual input of what the CPU is 'looking' at. One of the toughest aspects for Beginners is being able to "Visualize" Code. If you can "visualize" it, you can write code for it.
An ability that every Assembler Programmer must possess is being able to navigate thru Memory. Let's go over the example Memory Address of 0x80516074. To navigate to this Address, you first want to look at the Address values on the left hand side of the picture below. You will see the Address for each row increments by 0x10 (16). You will first go down to Address 0x80516070. Now you simply go over to the right by 4 to end up at 0x80516074.
As you can see, the blue boxed address shows how to navigate to the example address using the numbered address rows. The green boxed number represents the column to navigate to which is number 4. A simple equation of the address row value + the column number will navigate to the desired memory address. (0x80516070 + 0x4 = 0x80516074).
The hex number outlined in red shows the first 4 bytes (word) that is located starting at Memory Address 0x80516074. Thus, you can state that the word at Address 0x80516074 is 0x38A00000.
Reiterating the point here, you HAVE to understand how to navigate thru Memory. Let's go over some more examples. Using the picture of Memory that has already been shown, go to Memory Address 0x805160BC. The Word at this address is 0x4BAF3AC5. The picture below shows the Word outlined in red.
The halfword at that same memory Address is 0x4BAF. Picture below has the halfword outlined in blue.
The byte at that same Memory Address is simply 0x4B. Picture below has the byte outlined in green.
Final tests:
If I was to say.. what is the halfword at 0x80516086? The correct answer is 0x1B78.
If I was to say.. what is the byte at 0x8051600E? The correct answer is 0xFF.