سؤال

When tackling to translate the following segment of code, can someone tell me the purpose of ptr being there?

cmp byte ptr [eax], 0

ptr is a label, it has the value:

(++>

My understanding with cmp is that it compares the value on the left, with the value on the right.

With the third parameter involved (ptr), what does this mean? Is it comparing ptr AND the memory address value in eax with 0?

If someone could translate it into English for me, that would be great. Thanks.

هل كانت مفيدة؟

المحلول

In Intel assembler syntax, there is no explicit mention of the operand size. When you say mov eax, 0, it's clear that a 32-bit operand is needed (since eax is 32 bit wide), and mov al, 0 implies 8 bits.

But when you dereference a memory location, there is no way to infer the operand size, so you have to specify it explicitly by saying byte ptr, word ptr, dword ptr or quad ptr, for 8, 16, 32 and 64 bit operands, respectively.

So your instruction is comparing one byte (8 bits) at the memory addressed by the value of eax with 0.

نصائح أخرى

eax contains a pointer to some address. The instruction cmopares the byte value eax is pointint to with 0.

Similar to:

char *p = addr;
if(*p == 0)
   ...

PTR is not an instruction operand, but rather an option of the first operand.

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top