Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP
Path: utzoo!mnetor!uunet!seismo!rutgers!labrea!decwrl!sun!imagen!atari!portal!cup.portal.com!Rick_R_Kitts
From: Rick_R_Kitts@cup.portal.com
Newsgroups: comp.lang.c
Subject: Re: Assembly langauge subroutines for use with C
Message-ID: <537@cup.portal.com>
Date: Wed, 22-Jul-87 21:38:04 EDT
Article-I.D.: cup.537
Posted: Wed Jul 22 21:38:04 1987
Date-Received: Sat, 25-Jul-87 05:42:23 EDT
References: <3647@watdcsu.waterloo.edu>
Distribution: world
Organization: The Portal System (TM)
Lines: 90
XPortal-User-Id: 1.1001.1582



In article <3647@watdcsu.waterloo.edu>  ryders@watdcsu.UUCP writes:

>How does one go about writing an assembly function that can be linked
>and used by a C program? I have tried several times to get my modules
>to link properly but with the end result of "Unresolved external".
>I have prefaced the function name with an underscore and I still can't
>manage to get my C code to realize that yes, there is an assembly function
>by that name in one of the linked modules. HELP!
>I'm using MSC 4.0 on an IBM-PC AT.
>
>--
>Steve Ryder, Independent Studies, University of Waterloo
>             Waterloo, Ontario, CANADA, N2L 3G1. (519) 885-1211 Ext. 2352
>allegra,decvax,inhp4,utzoo}!watmath!watdcsu!ryders          RYDERS@WATDCSU.UUC
>"Diligence is the mother of good fortune, and idleness, its opposite, never
>brought a man to the goal of any of his best wishes." -CERVANTES, Don Quixote


Finally _I_ get to help someone out :-)

Chances are that you neglected to include the PUBLIC decleration required
to access assembler functions form MSC. All functions in MSC are PUBLIC.
Below is a bit of code that should help:

**********************************************************************

PUBLIC  _handler, _setivec, _ptr, _getivec

DGROUP  GROUP   _DATA
ASSUME CS:_TEXT, DS:DGROUP, SS:DGROUP,ES:DGROUP

_DATA   SEGMENT WORD PUBLIC 'DATA'

; If you have any variables that you would like access to in
; C, put them here. If they are declared in C preceed them with
; EXTRN

int12   label   DWORD
        off12   DW      0               ; I do not need these in the C
        seg12   DW      0               ; function, hence no underscores
_DATA   ENDS

_TEXT   SEGMENT WORD PUBLIC 'CODE'

; setivec(i_handler, int_number);
; use in Small model

_setivec PROC NEAR
        push    bp                              ; Use these 2 lines for
        mov     bp, sp                          ; ALL assembly functions
        mov     al, [bp + 4]                    ;Get the int_number
        mov     ah, 25h                         ; from the stack
	push 	ds
        lds     dx, DWORD PTR [bp + 6]          ; Get the address of
        int     21h                             ; int_handler from stack
        pop     ds
        pop     bp                              ; This is also mandatory
        ret
_setivec ENDP

; getivec();
; Get interupt vector
;

_getivec PROC NEAR
        push    bp                              ; See?
        mov     bp,sp
        mov     ah, 35h
        mov     al, 0Ch                         ; Hard wired for INT 12
        int     21h
        mov     off12, bx			; Store offset and segment
        mov     seg12, es
        pop     bp
        ret
_getivec ENDP
_TEXT ENDS
END


**********************************************************************

sun!cup.portal.com!Rick_R_Kitts






; If you have any variables that