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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T12:51:22+00:00 2026-06-14T12:51:22+00:00

So, first off, this is an assignment for a friend that I’m helping with,

  • 0

So, first off, this is an assignment for a friend that I’m helping with, and while it’s been a while since I’ve done C, that’s not the problem (Or at least I don’t think it is), the problem is the assembly code. The assignment must use a function written in inline assembly to sum two numbers that have been passed to the function after having been input by the user, and return the value, which is then output. On running my code, I get errors either reading or writing to memory locations found in the asm function, specifically the second mov command, and the program will hang while attempting to execute that line of code. Tracing the program, one of the values will be stored correctly (Whatever the second value the user enters, which I believe is normal, because values are read in reverse in assembly?) and the other isn’t read at all, and the program crashes. I’ve spent about four hours trying to figure this out, and am now resorting to outside help. Anyways, enough background, trying to be thorough, here’s the code. I’m sure what I’m doing is probably something basic and is staring me in the face, but any help is appreciated. Oh, and yes, I made sure masm was enabled in visual studio.

#include "stdafx.h"
#include "stdio.h"
#include <conio.h>

int sum( int val1, int val2 );
int main (void)
{
int val1=0, val2=0, val3=0;

printf("Hello, this program will add two whole numbers. Please enter the first    number.\n");
scanf("%d",&val1);

printf("Please enter the second number.\n");
scanf("%d",&val2);

val3 = sum(val1, val2);
printf("The sum of %d and %d is %d", val1, val2, val3);
_getch();

return 0;
 }

 int sum ( int val1, int val2 ){
 int val3;

    __asm{  mov eax, val2        ;
            push eax             ;
            mov ebx, val1        ;
            push ebx             ;
            add eax, ebx         ;
            mov ecx, val3        ;
            pop val3             ;
            pop ebx              ;
            pop eax              ;
            pop ecx              ;
            ret                  ;
    }
    return val3;

}
  • 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-14T12:51:24+00:00Added an answer on June 14, 2026 at 12:51 pm

    I’m not sure what all the push and pops are for, but this works:

    int sum ( int val1, int val2 )
    {
        int val3;
    
        __asm{  mov eax, val2        ;
                mov ebx, val1        ;
                add eax, ebx         ;
                mov val3, eax        ;
             }
        return val3;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

First off, this is NOT a duplicate of: Turn a C string with NULL
First off I would like to say that this is my first post and
First off, I apologize if this has been asked before. I can't seem to
First off, full disclosure: This is going towards a uni assignment, so I don't
I know first off that this is probably the worst looking regex ever but
first off this is a class assignment so i would appreciate help but just
So first off, this is a homework assignment, so please don't write any code
First off I know this is a duplicate question that is asked on here
First off this question has been helpful in my understanding of how to subclass
First off I have seen this: Remote Service as apk And it does not

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.