Natan Witkowski
Natan Witkowski

Reputation: 13

What does this instruction do in assembly?

So I don't know what this instruction does as I am starting just assembly.
What does this instruction do?

 cmp byte ptr [edi],00 add [eax],al

Upvotes: 0

Views: 351

Answers (1)

user2355950
user2355950

Reputation:

In fact,Those are two seprate instructions :

cmp byte ptr [edi],00 
add [eax],al

The first one goes to memory address pointed by edi register & fetches the first byte starting from that address , then comparing it to 00=0.


The second instruction throws away the result of the first instruction by overwriting all the flags without depending on them.

It moves the content of al (8-bit register) to memory location pointed by EAX , but since al is the lowest byte of eax, its just like we are copying the lowest byte in the address pointed by eax to memory location pointed by that address (which i think is meaningless).

Before execution: Suppose eax=0x00405060

--------------------
Address    |  Content (1byte)
--------------------
0x00405060 | 00

After Execution: eax=0x00405060 (doesn't change)

--------------------
Address    |  Content (1byte)
--------------------
0x00405060 | 60

If you notice after the instruction execution, we have copied the lowest byte of the address (60) to memory location pointed by that address.

Upvotes: 5

Related Questions