What is address of logical operation's result?

88 views Asked by At

I have simple program written in C#:

static void Main(string[] args)
{
    int a = 0;
    for (int i = 0; i < 100; ++i)
        a = a + 1;
    Console.WriteLine(a);
}

I am newbie in such field of programming and my purpose is just to understand assembly code created by JIT. It is piece of asm code:

7:         int a = 0;
0000003c  xor         edx,edx 
0000003e  mov         dword ptr [ebp-40h],edx 
8:         for (int i = 0; i < 100; ++i)
00000041  xor         edx,edx 
00000043  mov         dword ptr [ebp-44h],edx 

I cannot understand code :0000003c xor edx,edx. Where is result of operation stored? I found only such quote from "Intel® 64 and IA-32 Architectures Software Developer’s Manual":

The logical instructions AND, OR, XOR (exclusive or), and NOT perform the standard Boolean operations for which they are named. The AND, OR, and XOR instructions require two operands; the NOT instruction operates on a single operand

EDIT: As I understand this result should be stored at edx (see next code line). But it seems weird for me. I thought that result will be pushed onto stack

2

There are 2 answers

4
Sergey Kalinichenko On BEST ANSWER

Logical operation instructions store results in the first argument - in your case, it's edx.

Note that XOR-ing a value with itself produces 0. Hence, XOR a, a is a common assembly idiom to clear a register.

0
Bathsheba On

xor edx,edx is the idiomatic way of clearing the edx register.

(Note that a XOR a is zero for any value of a.)