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 7969947
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T07:19:10+00:00 2026-06-04T07:19:10+00:00

I am learning assembly language in my spare time. Can anyone explain why .maxstack

  • 0

I am learning assembly language in my spare time. Can anyone explain why .maxstack appears to be optional in this program. I have tried to find the answer online and in my book with no such luck i.e. the program will compile and run with .Maxstack commented out:

//Add.il
//Add Two Numbers

.assembly extern mscorlib {}

.assembly Add
{
    .ver 1:0:1:0
}
.module add.exe

.method static void main() cil managed
{
    //.maxstack 2
    .entrypoint

    ldstr "The sum of 50 and 30 is = "
    call void [mscorlib]System.Console::Write (string)

    ldc.i4.s 50
    ldc.i4 30    
    add
    call void [mscorlib]System.Console::Write (int32)
    ret
}

I am compiling the program at the command line using the ILASM tool and then running the generated executeable.

  • 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-04T07:19:11+00:00Added an answer on June 4, 2026 at 7:19 am

    I think your confusion stems from a misunderstanding of what .maxstack actually does. It’s an easy mistake to make, because it seems like it would cause an error when executing. Surprisingly, that particular directive actually has nothing do with the with stack size at runtime, instead, it is specifically used during code verification.

    From Partition III – Section 1.7.4

    Note: Maxstack is related to analysis of the program, not to the size of the stack at runtime. It does not specify the maximum size in bytes of a stack frame, but rather the number of items that must be tracked by an analysis tool.

    The code becomes unverifiable. That same section, notes that any conforming implementation need not support a method with an invalid max stack value. However, it doesn’t say that it must not, and quite clearly, the runtime is executing the code. So if it seems to have no effect, why even bother having it?

    Believe it or not, by default, the .NET framework runs unverifiable code. It was actually difficult for me to figure out how to enable verification in .NET 4.0, but if you do turn on CAS, your program (with .maxstack 1) will stop running with

    Unhandled Exception: System.InvalidProgramException: Common Language Runtime detected an invalid program.
    at main()

    Keeping this in mind, unverifiable the code cannot run in any environment that doesn’t have full trust (generally assemblies from the internet). If that’s not important to you, you can let it be an invalid value, and it really won’t make a difference. If the code itself is still correct, it will run fine; of course if there is an actually an issue with the IL stack, it will throw an InvalidProgramException.

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

Sidebar

Related Questions

I am learning assembly language in my spare time to become a better developer.
does anyone have any resources for learning assembly language on x86? I'm trying to
Hi I just started learning assembly in IA32. Can anyone tell me what these
I am learning assembly and I have this function that contains some lines I
I am currently learning Assembly language on Linux. I have been using the book
I am learning High Level Assembly language at the moment and have been going
So I'm learning to program in an assembly language for an abstract machine wich
So I have been learning assembly and came to the topic of stack, storing
I'm learning assembly and I have a very basic loop here segment .data msg:
I am thinking about learning assembly language in order to gain expertise in reverse

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.