Mail Archives: djgpp/1997/04/17/14:15:41
>
> I was just wondering if there is any way in which I can spawn NASM
> instead of AS for inline-assembly in GCC. Because, frankly AT&T syntax is
Sorry, no help here.
> Oh, and a related question: How do I make procs public in NASM, and how
> do I include it in GCC? (extrn void _procedure(void) ??)
In NASM, labels behave by default as though they had been declared
static in C. To make a symbol exportable in NASM put a
[GLOBAL myFunc]
for it at the top of the assembly file ( for variables and procedures).
Remember to name your
assembly language procedures with an underscore so gcc maps them correctly.
When you do your external function declaration use the same syntax as
your assembly routine expects. If you are returning a value in eax
declare
int myFunct(arg1,arg2,...)
If you are not returning a value then declare void myFunct.
Here is a very simple example
test.c
#include <stdio.h>
extern int mulByTwo(int num1);
int main(void)
{
int i, j;
i = 3;
j = mulByTwo(i);
printf("%d\n",j);
}
routine.s
[BITS 32]
[GLOBAL _mulByTwo]
[SECTION .text]
_mulByTwo :
mov EAX,[ESP+4];
imul 2;
ret;
I can't test this here at work so some of the syntax may not be
exactly correct.
Andrew
- Raw text -