Reputation: 1
I have learned that a memory is just a collection of bytes storage that are numbered with address thus I have reached the conclusion that each memory address can stores just one byte of data.
I am currently learning how to use the gdb debugger to examine memory but I'm confused as to how the x
command of gdb is used. I have also learned that a number can be prepended to the format of x
command to examine multiple units at the target address and also the default size of a single unit is 4 bytes.
How is it possible that a 4-byte data can be stored at a memory address that can hold only one byte? and also how is it possible that x/8xb
also works at a given memory address when the whole data can be displayed using only a word (i.e x/1w
)?
Upvotes: 0
Views: 1406
Reputation: 385955
The minimal addressable memory is often 8 bits, but it's not always the case. For example, I worked on a system with 32,768 addresses of 16-bit values.
How is it possible that a 4-byte data can be stored at a memory address
They're not. The address is the address of the first byte.
0x11223344 at address 0x1000 on a little-endian system which can address 8-bit values:
+--------+
0x1000 | 0x44 |
+--------+
0x1001 | 0x33 |
+--------+
0x1002 | 0x22 |
+--------+
0x1003 | 0x11 |
+--------+
0x11223344 at address 0x1000 on a big-endian system which can address 8-bit values:
+--------+
0x1000 | 0x11 |
+--------+
0x1001 | 0x22 |
+--------+
0x1002 | 0x33 |
+--------+
0x1003 | 0x44 |
+--------+
Upvotes: 2