Interacting with C program (8086 + C)

Discussion in 'Programmer's Corner' started by ramesh_manu, Jan 16, 2008.

  1. ramesh_manu

    Thread Starter New Member

    Jun 19, 2007
    1
    0
    i have able to write c program interact with 8086 program. For that, i simply call the assembly language program in C coding. But I am not able to pass the parameter to the assembly langugae programming. I tried with PUBLIC and EXTERN Directives in ALP coding. can any one guide me with sample coding. i used MASM5.0 and TC software.
     
  2. Mark44

    Well-Known Member

    Nov 26, 2007
    626
    1
    Ramesh,
    It sounds to me like you need to write an assembly procedure (PROC) to go with the part of your application written in C. My experience in mixed-language programming was about 15 years ago. Hopefully my example will be helpful.

    The C portion of your app will have a call in it to what the C portion thinks is just another C function. In reality the called function will be an assembly PROC. I'm assuming the call looks like this:

    result = my_function(value);

    and that the prototype of this function is like so:

    short my_function(short);

    The assembly proc looks like this:

    MASM
    .MODEL small
    .CODE
    PUBLIC _my_function
    _my_function PROC NEAR
    ARG Value:WORD
    push bp
    mov bp, sp ; Save BP and copy stack pointer to BP
    push si ; save affected register
    mov si, Value

    ; do what needs to be done
    ; put value to be returned in AX

    pop si ; clean up registers used
    pop bp ; restore BP to its former value
    ret
    _my_function ENDP
    END
     
  3. RiJoRI

    Well-Known Member

    Aug 15, 2007
    536
    26
    Are you using MASM to create an .OBJ file to be linked in your project, or are you shelling out (using some form of exec() ) to have the ASM program (.COM or .EXE) run? And, if you are exec'ing, which OS are you using?

    My favorite 80x86 assembler was A86, which I believe is still available on the 'Net. It does 80x86 assembly without all the overhead of MASM. There are also files explaining how to interface to a C program in either of the two cases above.

    --Rich
     
  4. Mark44

    Well-Known Member

    Nov 26, 2007
    626
    1
    Rich,
    The code I posted came from a book on DOS programming using C and assembler (of which I am a co-author). The work I did was in 1991, and I used Borland's Turbo C toolset. IIRC, I was using Windows 3.1 at the time.

    I would use the compiler to compile the C portion into an .obj file, use the assembler to assemble the .asm code, and use the linker to combine the .obj files.

    The Turbo assembler (TASM) seemed a lot easier to use than MASM, and the Borland debugger seemed to me to be superior to the MS debugger of the time. The debugger's UI was nicely laid out, so I could find out what was going on anywhere in memory, in the registers, and could single-step through the code, watching what was happening.

    I seem to remember having A86, and I might still have it on a 5 1/4 " floppy somewhere, but I don't recall doing much with it.
    Mark
     
  5. RiJoRI

    Well-Known Member

    Aug 15, 2007
    536
    26
    Another idea for Ramesh:
    Turbo C can generate just the assembler output, although you may need to use the command-line version (TCC??). If you compile the following to assembler, you can see what is going on:

    Code ( (Unknown Language)):
    1.  
    2.  
    3. int dummy(int parm);
    4.  
    5. int main (int argc, unsigned char * argv[])
    6. {
    7.   int a;
    8.   unsigned char c;
    9.   int d;
    10.  
    11.     a = argc;
    12.     c = *argv[0];
    13.  
    14.     d = dummy(a);
    15. }
    16.  
    17. int dummy(int parm)
    18. {
    19.     return (parm);
    20. }
    21.  
    Turn off all optimization, so TC does not remove any of your code. After this, you can replace the call to dummy() with an exec{) call to see how that is handled.

    --Rich
     
Loading...