Mixing C and assembly
Hello,
Here's what most likely will turn out to be an easy answer to this newbie question.
I am trying to get some code running where I am using C and assembly. The just of it is the C program asks the user for an integer, I then pass the integer to the assembly function and try to get it to print the integer to stdout.
The error I am getting when I try to run the program in KDevelop (which uses gcc) is:main.c: undefined reference to `asm_func'
----- C function (main.c) --------
#include <stdio.h>
// prototypes
extern void asm_func (int) __attribute__ ((cdecl));
int main(void)
{
int n;
printf ("Enter an integer 'n': ");
scanf ("%d", &n);
asm_func (n); return (0);
}
------ Assembly function (asm_func.asm) -------
;; Macro file
%include "Io.mac" ;; where the PutInt function comes from
section .stack 0x100 section .model small
section .text
global _asm_func
_asm_func:
enter 4, 0 ;; 4 so that the stack can accomadate the integer 'n'
mov ax, [esp-4] ;; this is where the integer should reside on the stack
PutInt ax ;; prints the value of ax to stdout
leave
ret
Any suggestions/comments would be great.
Dave
Quoted 3 lines
The error I am getting when I try to run the program in KDevelop (which uses gcc) is:
main.c: undefined reference to `asm_func'
That's right. There is no asm_func symbol.
Quoted 5 lines
section .text
global
_asm_func
_asm_func:
The practice of silently appending an underscore to exported C symbols is not done in the Unix world, in general. Export the same symbol you import.
b
I fixed up the assembly code by taking out the underscores before asm_func but I still get a linking error "main.c: undefined reference to asm_func"
Does anybody know why this could be occuring?
Thanks again,
Dave
Quoted 21 lines · Brian Raiter
Quoted 3 lines
The error I am getting when I try to run the program in KDevelop (which uses gcc) is:
main.c: undefined reference to `asm_func'That's right. There is no
asm_funcsymbol.Quoted 5 lines
section .text
global
_asm_func
_asm_func:The practice of silently appending an underscore to exported C symbols is not done in the Unix world, in general. Export the same symbol you import.
b
-
To unsubscribe from this list: send the line "unsubscribe linux-assembly" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html