www.delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1997/04/17/14:15:41

From: Andrew Crabtree <andrewc AT typhoon DOT rose DOT hp DOT com>
Message-Id: <199704171750.AA094619458@typhoon.rose.hp.com>
Subject: Re: spawning NASM from GCC?
To: FLEGEL AT physnet DOT uni-hamburg DOT de (Michael Flegel)
Date: Thu, 17 Apr 1997 10:50:57 PDT
Cc: djgpp AT delorie DOT com
In-Reply-To: <Pine.VMS.3.91-b11-vms.970417120540.194D-100000@sat111.physnet.uni-hamburg.de>; from "Michael Flegel" at Apr 17, 97 12:10 (noon)

> 
> 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 -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019