How to interface Assembly8086 with C ?

Hi

I want to interface my assembly 8086 code with C. The assembly code and the relevant C code is been shown below. But when i run the C code I get a linker error.
Can anyone tell me why is this happening ?


THE ASSEMBLY CODE---------------------------------

PUBLIC CUROFF
.MODEL small, C
.CODE

CUROFF PROC

MOV AH, 3
XOR BX, BX
INT 10H
OR CH, 20H
MOV AH, 01
INT 10H
RET

CUROFF ENDP

END

NOW THE REQUIRED C CODE-----------------


#include

void curoff(void);

void main()
{
printf("
The cursor is now turning off");
curoff();
}




Ruchika

Comments

  • : Hi
    :
    : I want to interface my assembly 8086 code with C. The assembly code and the relevant C code is been shown below. But when i run the C code I get a linker error.
    : Can anyone tell me why is this happening ?
    :
    :
    : THE ASSEMBLY CODE---------------------------------
    :
    [code]
    : PUBLIC [red]_[/red]CUROFF
    : .MODEL small, C
    : .CODE
    :
    : [red]_[/red]CUROFF PROC
    :
    : MOV AH, 3
    : XOR BX, BX
    : INT 10H
    : OR CH, 20H
    : MOV AH, 01
    : INT 10H
    : RET
    :
    : [red]_[/red]CUROFF ENDP
    :
    : END
    [/code]
    :
    : NOW THE REQUIRED C CODE-----------------
    :
    [code]
    : #include
    :
    : void main()
    : {
    : printf("
    The cursor is now turning off");
    : curoff();
    : }
    [/code]
    :
    :
    : Ruchika
    :

    [blue]It took some time, but I got it working.

    OK, first of all it seems to be the C way to use underscores in front of external function names, I`ve coloured them red.

    You may also have missed something in the compilation process, so I`ll take you through it:

    1) [b]tasm curoff.asm[/b]
    where curoff.asm is the name of the assembly file
    this will output a file called curoff.obj

    2) [b]tcc -c main.c[/b]
    Im assuming you are using the Turbo C compiler.
    main.c is the name of the C file
    -c tells the compiler to only compile, not link the program
    this will output a file called main.obj

    3) [b]tlink D:TCLibc0s.obj main.obj curoff.obj, program.exe,, cs.lib[/b]
    You should have the c0s.obj and cs.lib files in your compiler folder somewhere, TCLib for Turbo C. Replace "D:TCLib" with the name of the folder where the files are in your computer.
    These files provide some sort of a startup interface for the program. As Im not very experienced with C, I can`t give you any extensive information about this.

    This gave me a lot of experience, thank you for this!
    I hope it`ll work for you too.
Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

In this Discussion