2 Replies - 3204 Views - Last Post: 11 January 2013 - 10:35 AM Rate Topic: -----

#1 wiqi546  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 2
  • Joined: 11-January 13

Assembly procedure calling from C (INTEL 8086)

Posted 11 January 2013 - 06:07 AM

Let me thank you for replying first. Alright, so here is goes. I need to prepare a procedure in Assembly for Intel 8086 able to be called from a C (pass a string and return an integer value(16bit)). My assembly procedure works perfectly fine "stand-alone". I need help with connecting them together.

Program is supposed to run on Intel 8086. I need to use MASM or emu8086 as assembler/simulator. Kindly recommend a C compiler and also a way to make the simple C program that is able to call the assembly procedure and get the returned value.

How can i connect the ASM file and the C file? (How will the compiler know where is the definition/code for this procedure?)
How can i receive the string sent from C in Assembly language, also how to return the integer to C from Assembly?

Any help is sincerely appreciated. Thank you.

Some people have suggest me something like this:
#include <stdio.h>

extern int assem();

int main()
    int i = assem("abc");
    printf("%d\n", i);
    return 0;

Is This A Good Question/Topic? 0
  • +

Replies To: Assembly procedure calling from C (INTEL 8086)

#2 Skydiver  Icon User is offline

  • Code herder
  • member icon

Reputation: 6114
  • View blog
  • Posts: 21,049
  • Joined: 05-May 12

Re: Assembly procedure calling from C (INTEL 8086)

Posted 11 January 2013 - 06:44 AM

Your assembler will output a .obj file. You compile your C program to also generate a .obj. When you call your linker, you pass both .obj files and voila! Your C code calls the ASM code.

To return a value from your assembly code to your C code, you have to follow the conventions used by your C compiler for parameter passing. Typically, for Microsoft compilers, return values are returned in AX.

I think your major challenge will be getting our hands on a 16-bit environment, a 16-bit compiler, and a 16-bit assembler.

This post has been edited by Skydiver: 11 January 2013 - 11:07 AM

Was This Post Helpful? 1
  • +
  • -

#3 snoopy11  Icon User is offline

  • Engineering ● Software
  • member icon

Reputation: 1458
  • View blog
  • Posts: 4,716
  • Joined: 20-March 10

Re: Assembly procedure calling from C (INTEL 8086)

Posted 11 January 2013 - 10:35 AM

Digital Mars
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1