What is the meaning of "ptr" in assembly?

148 views Asked by At

Since [si] in brackets is like the value at the address si like the *si in C

and since offset si is like &si

what about ptr in

mov dword ptr [si], ax 

?

1

There are 1 answers

3
Jabberwocky On

Here's a concrete example:

Assuming this memory situation (all numbers in hexadecimal), each box represents one byte:

Address   Memory content
          +---------+
00000000  |   11    |
          +---------+
00000001  |   22    |
          +---------+
00000002  |   33    | <--- si (= 00000002) points here
          +---------+
00000003  |   44    |
          +---------+
00000004  |   55    |
          +---------+
00000005  |   66    |
          +---------+
00000006  |   77    |
          +---------+
  • After the instruction: mov eax, dword ptr [si], eax contains 66554433.
  • After the instruction: mov eax, word ptr [si], ax (16 low bits of eax) contains 4433.
  • After the instruction: mov eax, byte ptr [si], al (8 low bits of eax) contains 33.

  • dword ptr [x] means: we want to read/write a double word (4 bytes) from/to the memory address contained in x.
  • word ptr [x] means: we want to read/write a word (2 bytes) from/to the memory address contained in xmemory adddre.
  • byte ptr [x] means: we want to read/write a single byte from/to the memory address contained in x.

Now you may ask why we need to put dword ptr and not just dword. It's just a convention.