c++ - 程序运行前寄存器的值是怎么来的?
PHPz
PHPz 2017-04-17 11:23:28
0
4
552

当OD停在入口点,程序一行代码都尚未执行,此时寄存器中的值是如何确定的?eip指向当前地址,esp指向堆栈,那么eax,ebx,ecx中的值是如何来的?

PHPz
PHPz

学习是最好的投资!

reply all(4)
黄舟

As far as x86 is concerned, there are not many general-purpose registers that can be controlled by the user program. The most important ones are eip and esp, which correspond to the first instruction of the user program and the stack address of the user program respectively. These two The os of the register will be set according to the format of the elf file when loading the user program. When the user program is running, the use of other general-purpose registers such as eax, ebx, ecx, and edx is managed by the compiler. Before the user program uses a register, the compiler will also load the required value into in the register. Segment registers such as cs, ds, es, and fs are also set by the operating system. As for the registers like cr3 that control the virtual memory to physical memory mapping table, they are also set by the OS and the user program does not have the authority to change them.

Peter_Zhu

eax, ebx, ecx are general-purpose registers, and will have a default value (should be 0) when the CPU starts.

阿神

The way the operating system runs a program (for example, compiled in C language) is: first create a new process, then run the program loader, set up the stack and copy the program from disk to memory, and then finally It transfers control to the main() function (actually main() is not the first function called in the program, but I say this here for simplicity), and then the program runs happily. After executing so much code before, I have to manipulate the registers...

PHPzhong

How hard does the OS work to load and execute a program? The OS needs to create page tables, read files, cut LDTs, and set registers. Otherwise, you won’t be able to see hello world. Did you create it?
CPU, who has done all the hard work in the background, is crying silently...

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template