PDA

View Full Version : Special registers



Doomulation
February 26th, 2006, 21:16
Messing around with assembly, I seem to be confused about ebp and esp. What are these two registers function? I know they are general purpose, but typically vc++ uses them for its own purpose.
I thought ebp was the stack pointer, but when I push something onto the stack, I see esp changes! Am I wrong?

It also seems it is much faster to read/write to memory rather than the stack. At least due to my tests. Is it supposed to be like that?

Garstyciuks
February 26th, 2006, 21:56
I have always thought that esp is the stack pointer...

zilmar
February 26th, 2006, 23:18
ESP is stack register
EPB is used for a stack frame .. basicly stores the stack location at the start of the function that way it can always know where a variable is stored in the stack cause it will be in a set position from its starting point.

in function a .. var bcd would be at something like ebp - 4 .. so no matter where the stack pos is .. that variable is always constant

Doomulation
February 26th, 2006, 23:41
Well, that's a bother. That means there are only 6 general purpose registers to use...
Unless I use shifting and bit manipulating to fully use each bit of the 32-bit registers.

zilmar
February 27th, 2006, 03:17
You are free to use ESP and EBP .. I once played with it with pj64 recompiler, but VC had a spack if ESP was not pointing to valid memory.

You can use EBP, but if it is inlined asm, then it needs to be saved and restored

synch
February 27th, 2006, 11:56
Well, you can use EBP freely in a routine, without pushing/poping, if you don't mix C and asm (pure inline asm) in that routine. I haven't profiled the speed results, as I always used it for size optimizations. When using ebp VisualC will generate a warning that you can safely ignore. About ESP, if you're using the stack for something in that routine, it's better to use it only to index the stack.

Doomulation
February 27th, 2006, 16:16
You can check omit framepointers in the config to make vc ignore the ebp register unless necessary. But you had better not touch esp unless you know what you're doing.