为什么使用寄存器出于其预期目的而使用寄存器?
众所周知,X86寄存器名称具有目的,并指出了应如何使用寄存器(请参阅此网站例如,或这样的发布)。 寄存器的目的应为:(
* EAX - Accumulator Register
* EBX - Base Register
* ECX - Counter Register
* EDX - Data Register
* ESI - Source Index
* EDI - Destination Index
* EBP - Base Pointer
* ESP - Stack Pointer
请注意,我还没有在英特尔的文档上找到有关此的官方信息)
,ecx
应该是持有我的i
变量的寄存器代码:
int main()
{
register int i = 0;
for(i = 0 ; i <= 10 ; i++){}
return 0;
}
我用gcc loop.c -o loop
编译的代码。 然后我用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
我们清楚地看到ebx
holding i ,而不是ecx
。 有历史原因吗?编译器当时是否使用了理论目的或登记册,还是仅适用于人类?
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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论