file 1 --------------------------------------

// c file used to test - use a near data mem model

foo_far(char far *t1);
foo_near(char near *t1);

#include <malloc.h>
#include <string.h>

void main(void)
{
   char far *fart1, near *t1;

   t1=malloc(100);
   fart1=farmalloc(100);

   _fstrcpy(fart1, "FAR hi world\r\n$");
   strcpy(t1, "NEAR hi world\r\n$");

   foo_far(fart1);
   foo_near(t1);

   free(t1);
   farfree(fart1);

}

File 2 --------------------------------------------------

// asm file with foo's -------------------------------------------


; Alex Russell 1997, example of passing strings (pointers) from C
; to a ASM module. TASM macros used
; C prototypes:
; foo_far(char far *t1);
; foo_near(char near *t1);

.model medium, C

public foo_far
public foo_near

.code

; far pointer version
foo_far PROC t1:dword

        push ds

        lds   dx, t1   ; ds has t1's segment, dx the offset

        ; display the string using a dos int call
        mov   ah, 09h
        int   21h

        pop ds

        ret

foo_far endp

; near pointer version
foo_near PROC t1:word

        push si

        ; display the string using a dos int call
        mov   dx, t1    ;t1 contains the offset, 
                        ;ds already has the segment
        mov   ah, 09h
        int   21h

        pop si

        ret

foo_near endp

end

