an help with IA32 assembly?

This is a discussion on an help with IA32 assembly? within the Linux Programming forums, part of the Platform Specific Boards category; Originally Posted by brewbuck
When programming x86, it helps to be aware of the special functions of certain registers. Had ...

When programming x86, it helps to be aware of the special functions of certain registers. Had you known of this special property of ECX (the fact that it can be used as the count argument of a rotate or shift instruction), you might have avoided using it for some other purpose in the first place.

There is actual method to this madness.

The "A" in EAX means "accumulator," because that's what it is.
The "B" in EBX means "base."
The "C" in ECX means "count."
The "D" in EDX means "data."
The "SI" in ESI means "source index."
The "DI" in EDI means "destination index."
The "BP" in EBP means "base pointer."

This is not a coincidence! The register pair EAX:EDX serves as data for the long multiplication and division instructions. BX, historically, used to be the only general register which could be used to index memory (although SI and DI could also be used), or to do indirect calls/jumps, although that restriction has now been relaxed. CX holds the counters for various kinds of operations, including multi-bit rotation. SI and DI are implicit operands of the string instructions. And BP has the special property that it accesses the stack segment, not the data segment, when dereferenced.

You have to constantly keep these things in mind as you choose which registers to use for which variables, because if you plan poorly, you'll continually be swapping/pushing/saving/restoring them.