0

I've got an assignment in one of my lectures and here I'm stuck right at the beginning.

My ASM file:

.intel_syntax noprefix

.text
.global stuff
stuff:
    mov eax, 1

My C file:

#include <stdio.h>

extern int stuff();

int main()
{
  int result = stuff();
  printf("%d\n", result);

  return 0;
}

and I compile with:

gcc -m32 -o runme main.c a.S

Edit:

./runme

prints 0 instead of expected 1. Why is that and how should I fix it?

kazimazi
  • 1
  • 1
  • 1
    What is the problem with the code you show? Please take some time to read [the help pages](http://stackoverflow.com/help), take the SO [tour], read [ask], as well as [this question checklist](https://codeblog.jonskeet.uk/2012/11/24/stack-overflow-question-checklist/). Then [edit] your question to improve it. – Some programmer dude Mar 15 '20 at 06:58
  • It compiles well, but when I run it my printed value will be 0 instead of expected 1. I would like to know why and how I should fix it. – kazimazi Mar 15 '20 at 07:11
  • Hint: When and where do your function `stuff` actually ***ret**urn*? – Some programmer dude Mar 15 '20 at 07:20
  • 2
    I see a **ret** is missing at the end, now it works thx – kazimazi Mar 15 '20 at 07:25
  • @kazimazi Please post this as an answer to your own question so others see that it has been resolved. – fuz Mar 15 '20 at 09:43
  • 1
    @fuz: the [x86 tag wiki](https://stackoverflow.com/tags/x86/info) has some links to existing Q&As about missing `ret` and fall through into whatever code is next. I linked a couple that seem relevant. – Peter Cordes Mar 15 '20 at 19:36
  • @PeterCordes I wanted to give OP a chance to learn how Stack Overflow works, but I guess this too is a valid way to resolve this question. – fuz Mar 15 '20 at 20:21

0 Answers0