www.digitalmars.com         C & C++   DMDScript  

D - function call from assembly

reply Manfred Hansen <manfred toppoint.de> writes:
Hello

i try to call a function from an assembly program.


##
## http://www.geocities.com/SiliconValley/Ridge/2544/
# Compile Instructions:
## -------------------------------------------------------------
## This  file is  a basic  demonstration of  the  GNU assembler,
## `as'.
## dmd -c print.d
## gcc -s -c d_function.s
## gcc  -nostdlib  c_function.o print.o  -lgcc -o d_function
#######################################################################

        .section .data
        .section .text
        .globl _start

  _start:
        ## Call the function
        call prin
        
        ## terminate program via _exit () system call
        xorl %eax, %eax     # %eax = 0
        incl %eax       # %eax = 1 system call _exit ()
        xorl %ebx, %ebx     # %ebx = 0 normal program return code
        int $0x80       # execute system call _exit ()

The D programm

void prin() {
        /* printf("Hallo"); */
        int i = 3;
}

Compile with:
dmd -c print.c
gcc -s -c d_function.s
gcc  -nostdlib  d_function.o print.o  -lgcc -o d_function
c_function.o(.text+0x1): In function `_start':
: undefined reference to `prin'
collect2: ld returned 1 exit status

Maybe someone have an idea, or a better example.

Manfred
                
Mar 05 2004
parent reply "Ben Hinkle" <bhinkle4 juno.com> writes:
My only suggestion is add "extern (C)"

extern (C)
void prin() {
        /* printf("Hallo"); */
        int i = 3;
}
Mar 05 2004
parent Manfred Hansen <manfred toppoint.de> writes:
Ben Hinkle wrote:

 My only suggestion is add "extern (C)"
 
 extern (C)
 void prin() {
         /* printf("Hallo"); */
         int i = 3;
 }

It looks good. There are no error message anymore. In the evening or tommorow i will try this in my real proramm. Thank you. Manfred
Mar 05 2004