# Can someone help me with this code? (ASM/C)

**URL:** <https://boards.straightdope.com/t/can-someone-help-me-with-this-code-asm-c/675211>\
**Category:** Miscellaneous and Personal Stuff I Must Share\
**Created:** [December 1, 2013, 4:20pm UTC](https://boards.straightdope.com/t/can-someone-help-me-with-this-code-asm-c/675211 "2013-12-01T16:20:37Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Budget\_Player\_Cadet](https://sea3.discourse-cdn.com/straightdope/user_avatar/boards.straightdope.com/budget_player_cadet/32/205_2.png) [@Budget\_Player\_Cadet](https://boards.straightdope.com/u/Budget_Player_Cadet)\
**Post date:** [December 1, 2013, 4:20pm UTC](https://boards.straightdope.com/t/can-someone-help-me-with-this-code-asm-c/675211/1 "2013-12-01T16:20:37Z")

</div>

On an ARM linux distribution. Couldn’t tell you which.

worker.S:

```auto

.globl _asm_task

.code 32

_asm_task:
MOV r11, r13	;
SUB r11, r11 , #4 ;
SUB r13, r6, #20;
MOV r1, r0	;
STR r1, [r11, #4];
ADD r11, r11, #4 ;
MOV r13, r11	;
B r14	;

```

All this one really does is run a basic program which allocates a variable, saves it in a stack pointer, and returns. This is not quite as important; the problems are here:

main.c

```auto

#include <stdio.h>
extern void _asm_task(int a);

int main(int argc, char **argv) {

_asm_task(stoi(argv[1]));

return 0;

} 

```

The compiler tells me that it doesn’t recognize \_asm\_task and that it doesn’t know stoi(). Both of these confuse me to no end - \_asm\_task is explicitly stated as external and exists in the same directory. As far as I am aware, this distribution has a built-in makefile. I’m building with gcc -o main main.c. It _should_ recognize stoi(), right? Or am I missing an include somewhere?

---

<div class="post-metadata">

**Author:** ![krunen](https://avatars.discourse-cdn.com/v4/letter/k/c37758/32.png) [@krunen](https://boards.straightdope.com/u/krunen)\
**Post date:** [December 1, 2013, 5:08pm UTC](https://boards.straightdope.com/t/can-someone-help-me-with-this-code-asm-c/675211/2 "2013-12-01T17:08:36Z")

</div>

You should probably use atio, not stoi. atoi is in the standard c library, stoi i C++. And it’s usually in stdlib.h.

And when you compile and link at the same time, you need to add the .o file from compiling your asm file to the command line.

---

<div class="post-metadata">

**Author:** ![Budget\_Player\_Cadet](https://sea3.discourse-cdn.com/straightdope/user_avatar/boards.straightdope.com/budget_player_cadet/32/205_2.png) [@Budget\_Player\_Cadet](https://boards.straightdope.com/u/Budget_Player_Cadet)\
**Post date:** [December 1, 2013, 6:50pm UTC](https://boards.straightdope.com/t/can-someone-help-me-with-this-code-asm-c/675211/3 "2013-12-01T18:50:19Z")

</div>

Yeah, a friend of mine informed me that stoi was false. I have no idea what a -o file is; we didn’t deal with that in the tutor lesson whatsoever. It doesn’t really matter at this point; it’s due in about two hours and I don’t even know if it’s graded or not. I just couldn’t figure out the error. It might just be that it’s not finding \_asm\_work because I didn’t configure my VPN right - given the sheer bloody-minded ridiculous number of fucking moving parts involved in just getting the damn thing to run anything at all, this would not surprise me.

---

<div class="post-metadata">

**Author:** ![beowulff](https://sea3.discourse-cdn.com/straightdope/user_avatar/boards.straightdope.com/beowulff/32/542_2.png) [@beowulff](https://boards.straightdope.com/u/beowulff)\
**Post date:** [December 1, 2013, 7:23pm UTC](https://boards.straightdope.com/t/can-someone-help-me-with-this-code-asm-c/675211/4 "2013-12-01T19:23:08Z")

</div>

Did you #include the file with your \_asm\_task routine in it?  
Or, specify it to the linker?  
If not, the linker is not going to be able to find it, no matter how obvious it is to you….

(I often yell at my development system\*\* “IT’S RIGHT THERE!”\*\* you damn so-and-so, when I have these sort of issues).
