Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8039959
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T03:44:28+00:00 2026-06-05T03:44:28+00:00

I wonder, how to set a local variable in ASM’s procedure ? thanks!!

  • 0

I wonder, how to set a local variable in ASM’s procedure ?

thanks!!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-05T03:44:29+00:00Added an answer on June 5, 2026 at 3:44 am

    If you want to store a variable on the stack, you need to reserve space for it, this is generally done with the SUB ESP,xxx sequence, where xxx is the size of the “variable” you want to make space for, aligned to the stack alignment (generally 4 bytes, can also be 8 or 16). The only exception to this rule is when the variable is in a register, in which case you can perform a PUSH on that register.

    This space needs to be cleaned up on function exit, so if you PUSHed a register, you should POP it or, ADD ESP,xxx where xxx was the size you originally SUB‘ed/the size of the register you PUSHed aligned to the stack size.

    Reading and writing are done using MOV, but this is where it gets a little tricky, as we have two cases, with stack frames, and without stack frames.

    without stack frames requires more math, as you need to compensate for the function arguments on the stack, so if our function takes 2 args, and we allocate space for an integer on the stack, we can write to it via MOV [ESP + 0xC],value, reading is the same MOV EAX,[ESP + 0xC].

    with a stack frame, your arguments take a positive index to EBP and your allocated memory is negatively indexed from EBP, so with the same example above, you’d do MOV EAX,[EBP-4].

    As you can see this gets a little tricky, so a better way is to create C or C++ code that represents what you want, compile it with -O0 (we compile with no optimization to prevent elision of stack vars to registers) then dissassemble it, and see how the compiler does it.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I wonder if matlab has set restriction on variable's name. fixnb21=0; for fix=1:200 if
I wonder if there is a chance to set a final Overlay in Google
I wonder if it is possible to set up an SVN subversion system (btw,
I wonder how to set next month with showing only mondays active: i tried
I wonder why this code does not work as expected: @ECHO off SET S1=HELLO
I want to sort a set of data using C implementation. I wonder which
I am using popular jquery Cookie plugin https://github.com/carhartl/jquery-cookie Wonder how to set and read
As ActionController::Base#default_url_options is deprecated, I wonder how to set default url options in rails3.
I wonder if it's possible to create a stored procedure in MySQL5 via ColdFusion's
I wonder if there is a way to set the value of #define in

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.