My 64 bit machine can only store 4 bytes in each memory location

My computer is a 64 bit mac.

How many bytes of information are stored in one of these locations in memory?

When I tried something in gdb

x /2x first
0x7ffff661c020: 0xf661b020      0x00007fff 

      

My code

#define PUT(p, val) (*((size_t *)(p)) = (val))
PUT(first, (size_t)some pointers);

      

I am using gcc -g to compile

It seems that only 4 bytes are stored at 0x7ffff661c020. 0x00007fff

stored at 0x7ffff661c024. Why can't it store 0x00007ffff661b020 at 0x7ffff661c020.

thank

+3


source to share


2 answers


Each memory location can only store eight bits because the memory is addressable. A 64-bit machine doesn't give you 64 bits in every memory location, it just means that it can handle 64 bits at a time.

For example, registers are 64 bits wide (unless you are deliberately manipulating sub-registries like ax

or eax

instead of 64-bit rax

), and you can load that many bits from memory with a single instruction.

You can see that this is a byte addressed by the fact that your two addresses have a difference of four between them:

0x7ffff661c020: 0xf661b020
0x7ffff661c024: 0x00007fff
              \____________/ four-byte
                           \ difference

      

and if you are using byte output, you will see it more "naturally", for example:



(gdb) x/8xb first
0x7ffff661c020: 0x20 0xb0 0x61 0xf6 0xff 0x7f 0x00 0x00

      

So the 64-bit value 0x7ffff661c020

is actually 0x00007ffff661b020

, as expected, you just need to tweak the command gdb

to get it as full 64-bit values, for example:

x/1xg first

      

where 1xg

stands for one value, hexadecimal format, giant word (eight bytes). The details of the command x

can be found here , the important bit for your question is the description of the block size (my bold font):

  • b

    = Bytes.
  • h

    = Halfwords (two bytes).
  • w

    = Words (four bytes). This is the initial default.
  • g

    = Giant words (eight bytes).
+8


source


It seems that only 4 bytes are stored at 0x7ffff661c020

No: you asked GDB to give you 4 bytes stored in the location 0x7ffff661c020

, so that's exactly what it gave you. Try this instead:



(gdb) x/gx 0x7ffff661c020

      

+3


source







All Articles