can anybody here gave an example on how to mix assembly and C, or send it to me ?


the main prog is written with Tasm, and the second prog with
borland c (wich contain calls to i/o functions, e.g printf, scanf...)


thanks,

My email is BlackHorus@caramail.com
Posted on 2001-08-19 20:04:50 by Sabeel
You use inline c. Sure, if such a thing existed. Does TAsm have a linker. If so you do some exporting/importing.
Posted on 2001-08-20 01:22:24 by eet_1024
simplest solution would be to let the C part be the main program, so that the c runtime will initialize. So code a simple main/WinMain() which just calls your ASM main/Winmain (which you will need to rename, i'm afraid).

japheth
Posted on 2001-08-20 02:26:32 by japheth
Sabeel,

I gather with the mix you are after, you want to run a C prog with some assembler in it. I am pretty sure you can convert tasm assembler modules into libraries and link them in directly. You will need to write the prototypes for it in C.

You should be able to do it in reverse as well, write a TASM program and link a C module into it. Same aplies, you will have to write the TASM prototypes yourself for the C modules.

Perhaps you should have a look at the compiler literature for the syntax but there sghould be a way to declare a module as an EXTERN or similar notation.

Regards,

hutch@pbq.com.au
Posted on 2001-08-20 09:15:09 by hutch--
Sabeel, here is a sample:


; ------------------ test_asm.asm ----------------------

.386
.model flat

; --------------------------------------------
; advise to compiler about external functions
; --------------------------------------------
extern ExitProcess:proc
extern _showit:proc ; <- you must prefixe the external
; functions name with '_'

; -------------------------------------
; The entry point in C libs is 'main'
; -------------------------------------
_start equ <main>

.code

_start:
xor edi, edi
mov ebx, 3
@01: inc edi
push edi
call _showit ; 'external function name '_' prefixed
or eax, eax
je error
dec ebx
jne @01
error:
push ebx
call ExitProcess
end _start

; --------------------------------------------------------------

// ---------- test_c.c ----------------------

#include <stdio.h>

// These defines are only in windows.h, in C
// standard libs does not exist BOOL data types

#define FALSE 0
#define TRUE 1

// Prototype: without '_' prefixe
int showit(int count);

int showit(int count)
{
if( !(printf("number %d\n", count)) )
return FALSE;
else
getch();
return TRUE;
}

// -------------------------------------------


I use this bat file to build the exe:


SET BIN=C:\BC\BIN
SET INCLUDE=C:\BC\INCLUDE
SET LIB=C:\BC\LIB
SET TA=C:\TASM\BIN
SET PATH=PATH

PATH %BIN%;%INCLUDE%;%LIB%;%TA%;%PATH%

if exist *.obj del *.obj
if exist *.exe del *.exe
cls

BCC32 /tWC /c /I%INCLUDE% test_c.c
if errorlevel 1 goto out
cls
TASM32 /ml test_asm.asm
if errorlevel 1 goto out
cls
TLINK32 /Tpe /c /ap /V4.0 /L%LIB% test_c test_asm,test,,import32.lib cw32mti.lib
if errorlevel 1 goto out
if exist *.obj del *.obj
if exist *.bak del *.bak
cls
start test
exit
:out
pause
if exist *.obj del *.obj
if exist *.bak del *.bak
cls
Posted on 2001-08-21 14:56:30 by n u M I T_o r