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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T10:46:00+00:00 2026-06-08T10:46:00+00:00

I wrote two simple programs that store the same integer value to two different

  • 0

I wrote two simple programs that store the same integer value to two different variables, and I’m wondering why the disassembly is slightly different between both programs.

First program:

int y;
int x = (y = 2);

Disassembly:

0000003a  mov         dword ptr [ebp-40h],2 
00000041  mov         eax,dword ptr [ebp-40h] 
00000044  mov         dword ptr [ebp-44h],eax

Second program:

int x = 2, y = 2;

Disassembly:

0000003a  mov         dword ptr [ebp-40h],2 
00000041  mov         dword ptr [ebp-44h],2 

The second line in the first program, which is clearly the only change, simply copies the value pointed to by [ebp-40h] into the eax registry, right? Maybe it’s a dumb question, but why are these slightly different? I’m not very familiar with assembly, to say the least, so I take it that you have to move a value into a registry before pointing to it? (or whatever the third line does. I think it’s pointing…)

For the sake of readability, I plan to never instantiate variables in serious code like I did in the first program.

Edit

Per the discussion in the comments, I compiled Release builds of these two snippets instead of the Debug builds I had been using before. The results are virtually identical:

First program:

00000000  push        ebp 
00000001  mov         ebp,esp 
00000003  push        eax 
00000004  mov         dword ptr [ebp-4],ecx 
00000007  cmp         dword ptr ds:[005E14B4h],0 
0000000e  je          00000015 
00000010  call        6C37403F 
00000015  nop 
00000016  mov         esp,ebp 
00000018  pop         ebp 
00000019  ret 

Second program:

00000000  push        ebp 
00000001  mov         ebp,esp 
00000003  push        eax 
00000004  mov         dword ptr [ebp-4],ecx 
00000007  cmp         dword ptr ds:[005514B4h],0 
0000000e  je          00000015 
00000010  call        6C42403F 
00000015  nop 
00000016  mov         esp,ebp 
00000018  pop         ebp 
00000019  ret 

It looks like the differences are only in memory addresses (i.e. not really a difference). I think that’s the correct interpretation, at any rate.

  • 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-08T10:46:02+00:00Added an answer on June 8, 2026 at 10:46 am

    Your first example is rewritten to:

    y = 2;
    x = y;
    

    because

    (y = 2)
    

    “evaluates” to

    y
    

    after assigning y.

    And that matches the disassembly 1:1.

    Sidenote: You can see the same effect with properties:

    Button b;
    b.Width = b.Height = 100; //inefficient!
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have two simple programs that use named pipes, here is the first: int
I wrote two simple programs server and a client using sockets in C++ (Linux).
I wrote a simple program that adds two edit fields to the field manager:
I'm trying to write a simple server in c that plays a two player
I wrote two code both are same Using NSURLConnection and Using AFNetworking. My NSURLConnection
I wrote two small java programs: a TCP client which sends many lines of
I wrote the same program two ways. One using a Surfaceview, and the other
I have a simple program (in C) that create two child process, wait on
I had a task to write simple game simulating two players picking up 1-3
I had a task to write simple game simulating two players picking up 1-3

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.