I need to write a function funcName (int a, int b, int c)
on C, which calculates the value using the formula a * b-c
and returns it. Then I need to write a function on masm, which calls this function with arguments that are specified in the data segment and returns the value that the first function returns after its call. A function written in masm must be called in main and output the resulting value. I wrote a program, but when I run it, a window pops up in which it is written Unhandled exception at 0x0014000a in labvpd.exe: 0xC0000005: Access violation writing location 0x8d4e00eb.
What am I doing wrong?
C code:
#include <stdio.h>
#include <stdlib.h>
extern "C"
int __cdecl funcName(int a, int b, int c);
extern "C"
int FUN();
int main()
{
printf("%s", "Result: ");
printf("%d", FUN());
scanf("%d");
return 0;
}
extern "C"
int __cdecl funcName(int a, int b, int c){
int result = a*b-c;
return result;
}
MASM code:
.686
.MODEL C, FLAT
.STACK
.DATA
a dw 10
b dw 20
d dw 30
.CODE
EXTRN funcName : proc
FUN PROC
push d
push b
push a
call funcName
ret
FUN ENDP
END
User contributions licensed under CC BY-SA 3.0