tags:

views:

81

answers:

4

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?

+2  A: 

They will have random values.

Vinay Sajip
Eh? Why the downvote? It answers the question and is not wrong.
Vinay Sajip
+5  A: 

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.

Atmocreations
+2  A: 

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

Marco M.
Critical reason: all you're doing is moving a pointer around. Nothing you do would cause them to be zeroed.
Michael E
+7  A: 

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.

bdonlan
Thanks for spoting that sub ebp, 8. I really thought it was with ebp :S . I am right now reading Barlet's Introduction to 80x86 Assembly Language and Computer Architecture Procedure and stack chapter so I can finally understand how the stack works.
devoured elysium