Linking C with Assembly in Visual Studio

蹲街弑〆低调 提交于 2019-12-11 10:26:31

问题


I'm trying to link main.c program with procedure.asm. I have the following C program and Assembly program.

main.c

#include <Windows.h>
#include <iostream>

using namespace std;
extern "C" {
    void ClearUsingIndex(int[], int);    
}
static int Array[10] ={1, 2, 3, 4, 5, 6, 7, 8, 9, -1};

int main() 
{
    int size = 10;

    ClearUsingIndex( Array, size);

    system("pause");
    return 0;
}

procedure.asm

; Listing generated by Microsoft (R) Optimizing Compiler Version 17.00.50727.1 

    TITLE   c:\Users\GS\documents\visual studio 2012\Projects\ClearIndex\ClearIndex\procedure.cpp
    .686P
    .XMM
    include listing.inc
    .model  flat

INCLUDELIB MSVCRTD
INCLUDELIB OLDNAMES

PUBLIC  ?ClearUsingIndex@@YAXQAHH@Z         ; ClearUsingIndex
EXTRN   __RTC_InitBase:PROC
EXTRN   __RTC_Shutdown:PROC
;   COMDAT rtc$TMZ
rtc$TMZ SEGMENT
__RTC_Shutdown.rtc$TMZ DD FLAT:__RTC_Shutdown
rtc$TMZ ENDS
;   COMDAT rtc$IMZ
rtc$IMZ SEGMENT
__RTC_InitBase.rtc$IMZ DD FLAT:__RTC_InitBase
rtc$IMZ ENDS
; Function compile flags: /Odtp /RTCsu /ZI
;   COMDAT ?ClearUsingIndex@@YAXQAHH@Z
_TEXT   SEGMENT
_i$ = -8                        ; size = 4
_Array$ = 8                     ; size = 4
_size$ = 12                     ; size = 4
?ClearUsingIndex@@YAXQAHH@Z PROC            ; ClearUsingIndex, COMDAT
; File c:\users\gs\documents\visual studio 2012\projects\clearindex\clearindex\procedure.cpp
; Line 2
    push    ebp
    mov ebp, esp
    sub esp, 204                ; 000000ccH
    push    ebx
    push    esi
    push    edi
    lea edi, DWORD PTR [ebp-204]
    mov ecx, 51                 ; 00000033H
    mov eax, -858993460             ; ccccccccH
    rep stosd
; Line 4
    mov DWORD PTR _i$[ebp], 0
    jmp SHORT $LN3@ClearUsing
$LN2@ClearUsing:
    mov eax, DWORD PTR _i$[ebp]
    add eax, 1
    mov DWORD PTR _i$[ebp], eax
$LN3@ClearUsing:
    mov eax, DWORD PTR _i$[ebp]
    cmp eax, DWORD PTR _size$[ebp]
    jge SHORT $LN4@ClearUsing
; Line 5
    mov eax, DWORD PTR _i$[ebp]
    mov ecx, DWORD PTR _Array$[ebp]
    mov DWORD PTR [ecx+eax*4], 0
    jmp SHORT $LN2@ClearUsing
$LN4@ClearUsing:
; Line 6
    pop edi
    pop esi
    pop ebx
    mov esp, ebp
    pop ebp
    ret 0
?ClearUsingIndex@@YAXQAHH@Z ENDP            ; ClearUsingIndex
_TEXT   ENDS
END

I did some research and I found the following source and followed the instructions: Guide to Using Assembly in Visual Studio .NET

But I get the following error when I compile the assembly file.

error A1017: missing source filename

I google the error but all the methods I tried don't seem to work.

来源:https://stackoverflow.com/questions/22739425/linking-c-with-assembly-in-visual-studio

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!