🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: comp.os.msdos.programmer
Article #3247

Re: Calling assembly routines from C

#3247
From: Eric Hughes
Date: Sat, 01 Dec 1990 20:52
43 lines
2221 bytes
In article <1990Dec1.050322.15678@wpi.WPI.EDU> jhall@wpi.WPI.EDU (John
Clinton Hall) writes:
>I am writing a program to be separately assembled to be linked with a
>C program.

Remember to prepend an underscore to the name as declared in the
assembler code so that the .OBJ names will match.

Also, if you use MS C 6.0, you don't need a separate assembler and
parameter passing is greatly simplified.

>The Microsoft Mixed Language Programming Guide states, "By default, C
>parameters are passed by value, except for arrays, which are passed
>by reference."  ...  What exactly does it mean by "reference?"

The reference is the address (lvalue) of the first element in the array.
A call by reference to a variable is the same as a call by value to the
address of the variable.  (In MS C, at least.)

>Is it a word pointing into the data segment, or a segment address
>with a word pointing into the segment?

It depends on whether it is a near or far pointer.  If you don't
explicitly declare the pointer size, it defaults to that of the memory
model which the compiler is using.  This is a dangerous practice,
since you might change memory models without remembering the implicit
size dependency.

Therefore, make sure your prototype contains the size of the parameter.

>Also, how would I define the function with extern in the C program?
>segment?  Would I use:
>	extern int29( const char * );

The 'const' keyword is superfluous.  I would use
	extern int29( char _far * ) ;

Why a far pointer?  It will work with any memory model, as the
compiler with generate four-byte pointers in small model in presence
of a prototype.

Eric Hughes
hughes@ocf.berkeley.edu
Technical Details
Message-ID: <HUGHES.90Dec1125250@locusts.Berkeley.EDU>
Path: arc1-ca.pugleaf.net!utzoo!utgpu!news-server.csri.toronto.edu!rutgers!uwm.edu!bionet!agate!agate!hughes
References: <1990Dec1.050322.15678@wpi.WPI.EDU>

Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!utzoo!utgpu!news-server.csri.toronto.edu!rutgers!uwm.edu!bionet!agate!agate!hughes
From: hughes@locusts.Berkeley.EDU (Eric Hughes)
Newsgroups: comp.os.msdos.programmer
Subject: Re: Calling assembly routines from C
Message-ID: <HUGHES.90Dec1125250@locusts.Berkeley.EDU>
Date: 1 Dec 90 20:52:50 GMT
References: <1990Dec1.050322.15678@wpi.WPI.EDU>
Sender: usenet@agate.berkeley.edu (USENET Administrator)
Organization: ucb
Lines: 43
In-Reply-To: jhall@wpi.WPI.EDU's message of 1 Dec 90 05:03:22 GMT