Thread: interfacing assembler with c++

  1. #1

    interfacing assembler with c++

    Can anyone clear up the proper syntax for calling assembler code from within a c or c++ program? I am using masm 6.00 and VC ver 1 (both 16 bit and both using the medium memory model) I want to expand on this basic example, but I can't seem to get it to work. Both the c program and the assembler program compile to obj files without errors. Link builds the exe from both obj files without any reported errors; however, when run, the program goes into lala land. TIA



    PUBLIC set_mode
    set_mode PROC FAR C vmode:WORD

    mov ah,0
    mov al, BYTE PTR vmode
    int 10h
    set_mode ENDP

    c source

    #include <stdio.h>
    #define MODE13 0x13

    extern set_mode(int);

    void main()
    blah blah
    blah blah

  2. #2
    Registered User
    Join Date
    Sep 2001
    You compile it as a DOS app right?
    // Gliptic

  3. #3
    Join Date
    Aug 2001
    You should do something like this, but I don't know have masm

    and vc++.

    First write the .h file. Fill in the prototypes to all the functions

    your going to write in assembly. Look up some documentation

    on vc++ calling order and name mangling, or you could write c++ stubs then compile into assembly. The calling convention is most likely to push the arguments from right to left. Then the return adress (eip+1) is pushed by the call instruction.

    For linux on intel, I end up with code which looks similar to


    ; linux c calling convention is that edi, esi, ebp, esp must be

    ; kept intact

    push ebp

    mov ebp, esp

    sub esp, 4 ; create a local variable

    ; ints are four bytes

    mov ebx, [ebp+8] ; first argument

    mov ebx, [ebp+12] ; second argument

    mov dword [ebp-4], 4h ; assign 4h to local variable

    ; leave does this

    ; mov esp, ebp

    ; pop ebp



    for this function

    void f(int a, int b);

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Problem building Quake source
    By Silvercord in forum Game Programming
    Replies: 16
    Last Post: 07-11-2010, 09:13 AM
  2. Which assembler is best?
    By MathFan in forum Tech Board
    Replies: 6
    Last Post: 06-16-2005, 09:25 AM
  3. Inline Assembler Macros?
    By Aidman in forum C++ Programming
    Replies: 14
    Last Post: 07-15-2003, 05:10 AM
  4. Assembler
    By GaPe in forum A Brief History of
    Replies: 8
    Last Post: 02-03-2003, 01:01 PM
  5. MAINFRAME Assembler.
    By sean in forum A Brief History of
    Replies: 3
    Last Post: 12-05-2001, 05:32 PM