It seem to be well known that x86 registers names have a purpose and indicate on how the register should be use (see this website for example, or this SO post). Registers purpose should be :
* EAX - Accumulator Register
* EBX - Base Register
* ECX - Counter Register
* EDX - Data Register
* ESI - Source Index
* EDI - Destination Index
* EBP - Base Pointer
* ESP - Stack Pointer
(Please note that I did not found official information about this on INTEL's documentation yet)
According to this, ecx should be the register holding my i variable on the code bellow :
int main()
{
register int i = 0;
for(i = 0 ; i <= 10 ; i++){}
return 0;
}
Which I compile with gcc loop.c -o loop
And I disassemble it with objdump -D -M intel ./loop:
0000000000001138 <main>:
1138: f3 0f 1e fa endbr64
113c: 55 push rbp
113d: 48 89 e5 mov rbp,rsp
1140: 53 push rbx
1141: bb 00 00 00 00 mov ebx,0x0
1146: f3 0f 1e fa endbr64
114a: bb 00 00 00 00 mov ebx,0x0
114f: eb 03 jmp 1154 <main+0x1c>
1151: 83 c3 01 add ebx,0x1
1154: 83 fb 0a cmp ebx,0xa
1157: 7e f8 jle 1151 <main+0x19>
1159: b8 00 00 00 00 mov eax,0x0
115e: 5b pop rbx
115f: 5d pop rbp
1160: c3 ret
We clearly see that ebx is holding i, not ecx.
Is there an historical reason to this? Did compiler used theoretical purpose or registers back then or was it just for humans?