I need to run masm assembly code in a C program for a project, as a test I'm trying to make a simple function that adds two numbers together and use it in a C program. I created a new project in Visual Studio for C++, renamed the file to .c, pasted the assembly code in notepad (saved as add.asm) and compiled using ml /c add.asm; I linked the .obj file it generated to the Visual Studio project (right clicked the solution explorer, add existing...) and made sure the path to it appeared on the linker config. However when I try to build the solution it gives me the same error:
Severity Code Description Project File Line Suppression State
Error LNK1107 invalid or corrupt file: cannot read at 0x92 projectName C:\Users\myName\source\repos\projectName\assembly snippets\add.obj 1
I've recompiled the assembly code multiple times and yet it still shows as corrupted.
Anyone have an idea on what it could be?
I've been at it for hours and its hard to find anything related online
The assembly code for said function is as follows
.386
.model flat, C
.stack 4096
.data
; Define any data variables here (if needed)
.code
PUBLIC _add_numbers
_add_numbers PROC
push ebp ; Save the previous base pointer
mov ebp, esp ; Set the new base pointer
mov eax, [ebp+8] ; Get the first parameter
mov edx, [ebp+12] ; Get the second parameter
add eax, edx ; Add the two numbers
pop ebp ; Restore the previous base pointer
ret ; Return from the function
_add_numbers ENDP
END
The code for the C program is
#include <windows.h>
#include <stdio.h>
extern int add_numbers(int a, int b);
int main(void)
{
int result = add_numbers(3, 5);
printf("Result: %d\n", result);
return 0;
}