What I'm trying to do is interface some assembly routines to C (not C++).
here is a sample asm file I have tried to link with a c file..
test.asm
--------
.model small,c
public clear_screen
.code
clear_screen proc
;whatever I put here has NO bearing on the result
clear_screen endp
end
test.c
------
main() { clear_screen(); }
Now when I compile/assemble and link, it ALWAYS locks up. I used td
and traced through it, and it worked up until the closing } of test.c.
Please help.
--
--
quare
Hi,
you'd better put a RET or it will hang
> clear_screen endp
> end
>
> test.c
> ------
> main() { clear_screen(); }
>
> Now when I compile/assemble and link, it ALWAYS locks up. I used td
> and traced through it, and it worked up until the closing } of test.c.
>
> Please help.
Also, make sure your compiler is compiling for the SMALL model since
that is what your assembler is doing. I think turbo C defaults to small
model so if you don't override it you are probably ok, but you just might
want to check. If you don't compile for the small model then the kind
of return the assembler generates will not be the kind of return the C
program expects to get... and it will hang. Oh you don't have docs;
in BC3.0 the model selection is one of the things somewhere under
the options menu. I imagine it's similar in TC3.0. There are several
models, it will probably say something like 'Memory Model' and then give you
a choice between 'tiny,small,medium,large,huge'. Make sure it's set
to small.
Also, Borland changed the format of object files between BC3.0 and BC4.0;
I imagine TASM V4.0 has the new style. i'm unclear whether this will
affect you with TASM output or not, but I know Borland recommended that
anyone with 3.0 libraries or executables written in C rebuild them
when they switched to 4.0. So if everything else fails you can always
blame it on your compiler and TASM being incompatible!
David
>
> --
> --
> quare
>
here is a sample asm file I have tried to link with a c file..
test.asm
--------
.model small,c
public clear_screen
.code
_clear_screen proc <- pretty simple fix I think!
;whatever I put here has NO bearing on the result
clear_screen endp
end
test.c
------
main() extern clear_screen(); <-I assume you did this or the function
wouldn't be called.
{ clear_screen(); }
>Now when I compile/assemble and link, it ALWAYS locks up. I used td
>and traced through it, and it worked up until the closing } of test.c.
Try just adding the underscore which is necessary with your compiler.
If I missed something I hope to stand corrected!?!?
>Also, Borland changed the format of object files between BC3.0 and BC4.0;
>I imagine TASM V4.0 has the new style. i'm unclear whether this will
>affect you with TASM output or not, but I know Borland recommended that
>anyone with 3.0 libraries or executables written in C rebuild them
>when they switched to 4.0. So if everything else fails you can always
>blame it on your compiler and TASM being incompatible!
well here is a question for ya...I have tc++ v3.0 for dos and I have tasm v4.0
tasm has tlink of it's own that Turbo Debugger only will understand the symbols from
but if i use tasm's tlink i get a dpmi stack error and it dumps out forcing me to use
the tlink that came with tc++ v3. Is there any way that I can use tasm's tlink to do
what I want? (this only happens in a makefile or from a tcc command line)
--Dave
>public clear_screen
>..code
>_clear_screen proc <- pretty simple fix I think!
> ;whatever I put here has NO bearing on the result
>clear_screen endp
> end
>test.c
>------
>main() extern clear_screen(); <-I assume you did this or the function
> wouldn't be called.
> { clear_screen(); }
>>Now when I compile/assemble and link, it ALWAYS locks up. I used td
>>and traced through it, and it worked up until the closing } of test.c.
>
>Try just adding the underscore which is necessary with your compiler.
>If I missed something I hope to stand corrected!?!?
No, no, no, no, no!!! Look at the .MODEL statement. It has the C language
modifier which automatically adds the underscore. He has declared things
correctly in the .ASM file.
Sorry to get so upset about this, but I can't believe how many times I've
seen this same thing said in error, day after day.
The directive:
.MODEL <size>,C
automatically adds an underscore to all public symbols, and correctly
interperets the order of function parameters on the stack. Anyone linking
assembly language modules with a C language program, SHOULD use the
language modifier with the .MODEL directive. This makes the assembly
language programming a lot easier and catches a number of potential bugs
before they happen.
The following is an example of an assembly language file and a C language
file that will compile and link properly, and will run without error.
---------------------------------- testasm.asm
--------------------------------
.model small,c
public testfunc
.code
testfunc proc
ret
testfunc endp
end
--------------------------------------- test.c
---------------------------------
extern void testfunc(void);
int main(void)
{
testfunc();
return(0);
}
----------------------------------------------------------------------------
----
You can compile and link the two files with the following command:
bcc -ms -v test.c testasm.asm
The -ms switch compiles to small model, and the -v switch includes
debugging information.
NOTE: There are NO UNDERSCORES used in the function name in the assembly
language file.
Christopher Hill
Aiea, Hawai`i (O`ahu)
: Try just adding the underscore which is necessary with your compiler.
: If I missed something I hope to stand corrected!?!?
I fixed that problem.. it was because I was not linking in the init
code and the standard library.
I'm still having trouble with the two products. I wish Borland would
consider older users a little more. For example, I can't get td to
execute the startup code now.. leaving me to search for main() manually.
oh well.. i guess if you don't have big bucks to spend you can't really
complain.
--
--
quare