AK_
AK_

Reputation: 2079

Assembly - modifying stack contents

How do I modify stack memory chunk in assembly?

I thought of one way, which is:

POP EAX
ADD EAX, 5
PUSH EAX

Is there a shorter more efficient way of doing this?

Upvotes: 0

Views: 1221

Answers (1)

Matteo Italia
Matteo Italia

Reputation: 126957

You can address the value on the stack directly with a memory operand, as in

add dword [esp], 5

or

add qword [rsp], 5

if you are targeting 64 bit; in 16 bit mode, instead, sp-based addressing is not available.

Upvotes: 5

Related Questions