Question

If I have a call procedure on asm:

push ebp
mov ebp esp
sub ebp, 8

Can I assume right now that both [ebp-4] and [ebp-8] are initialized to zero, or can they have random values?

Was it helpful?

Solution

They will have whatever value was in that memory before, which is unlikely to be 0. This is not 'random' per se - indeed, it's probably somewhat predictable; this usually doesn't do any good, but just don't get any clever ideas about using it for a RNG :)

Remember, all you did in that code was:

  • Save the current value of EBP to [ESP] then subtract 4 from ESP
  • Copy ESP to EBP
  • Subtract 8 from EBP (did you mean ESP?)

The CPU won't read anything into this beyond that, unless you tell it to. That is the essence of assembler. Moreover, when used in normal arithmetic, ESP is not special cased at all - it's just a number.

OTHER TIPS

you should never depend on this as this might be depending on the implementation. to be in a predictable state, always init a register or memory cell with a certain value.

They will definitely have random values unless you explicitly initialize them.

They will have random values.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top