I am trying to run procedure from asm file in cpp file but i get such errors:
Error 1 error LNK2019: unresolved external symbol _calka referenced in function _main D:\Addem\main.obj Project
Error 2 error LNK1120: 1 unresolved externals D:\Addem\Debug\Project.exe 1 1 Project
Here is my main.cpp:
#include <iostream>
using namespace std;
extern "C" void calka();
int main()
{
calka();
system("Pause");
return 0;
}
And my calka.asm
; The calka Subroutine (calka.asm)
public _calka
INCLUDELIB kernel32.lib
INCLUDELIB user32.lib
INCLUDELIB Irvine32.lib
INCLUDE Irvine32.inc
INCLUDE macros.inc
.data
BUFFER_SIZE = 50
buffer BYTE BUFFER_SIZE DUP(?)
filename BYTE 80 DUP(0)
fileHandle HANDLE ?
Rozmiar dw ?
Znak db ?
Suma dw ?
Minus db 0
wynik dw ?
temp dd ?
.code
_calka proc near
; Let user input a filename.
mWrite "Podaj nazwe pliku (z rozszerzeniem): "
mov edx,OFFSET filename
mov ecx,SIZEOF filename
call ReadString
; Open the file for input.
mov edx,OFFSET filename
call OpenInputFile
mov fileHandle,eax
; Check for errors.
cmp eax,INVALID_HANDLE_VALUE ; error opening file?
jne file_ok ; no: skip
mWrite <"Cannot open file",0dh,0ah>
jmp quit ; and quit
file_ok:
; Read the file into a buffer.
mov edx,OFFSET buffer
mov ecx,BUFFER_SIZE
call ReadFromFile
jnc check_buffer_size ; error reading?
mWrite "Error reading file. " ; yes: show error message
call WriteWindowsMsg
jmp close_file
check_buffer_size:
cmp eax,BUFFER_SIZE ; buffer large enough?
jb buf_size_ok ; yes
mWrite <"Error: Buffer too small for the file",0dh,0ah>
jmp quit ; and quit
buf_size_ok:
mov buffer[eax],0 ; insert null terminator
;mWrite "File size: "
;call WriteDec ; display file size
;call Crlf
; Display the buffer.
; Pytanie o wielkosc przedzialu
mWrite "Podaj wielkosc przedzialu h na osi x: "
mov edx,OFFSET Rozmiar
mov ecx,SIZEOF Rozmiar
call ReadDec
mov Rozmiar, ax
;mWrite <"Buffer:",0dh,0ah,0dh,0ah>
;mov edx,OFFSET buffer ; display the buffer
;call WriteString
;call Crlf
mov ecx, 15
mov ebx, OFFSET buffer
mov si, 0
jmp odczyt1
odczyt:
mov ebx, temp
inc ebx
odczyt1:
mov cl, byte ptr [ebx]
mov Znak, cl
mov temp, ebx
cmp Znak, '$' ;koniec pliku
je koniec
cmp Znak, 3bh ;srednik - nastepna liczba
je nastepna
cmp Znak, 20h ;spacja - ponowne wczytanie
je odczyt
cmp Znak, '-'
je Zmien_znak
mov al, Znak
sub al, 30h
mov bl, al
mov bh, 0
mov ax, 10
mul si
add ax, bx
mov si, ax
jmp odczyt
Zmien_znak:
mov Minus, 1
jmp odczyt
nastepna:
cmp Minus, 0
je dodaj
jne odejm
dodaj:
add Suma, si
mov si, 0
jmp odczyt
odejm:
sub Suma, si
mov Minus, 0
mov si, 0
jmp odczyt
koniec:
cmp Minus, 0
je dod
jne minu
dod:
add Suma, si
mov si, 0
jmp kon
minu:
sub Suma, si
mov Minus, 0
mov si, 0
kon:
mov ax, Suma
mul Rozmiar
mWrite "Wynik calkowania: "
cmp ax,0
;mov ebx, eax
jg plus
mWrite "-"
mov bx, 0
sub bx, ax
mov ax, bx
plus:
call WriteDec
close_file:
mov eax,fileHandle
call CloseFile
; Zeby aplikacja sie nie zamknela, heheszki :D
mov edx,OFFSET Rozmiar
mov ecx,SIZEOF Rozmiar
call ReadString
quit:
exit
_calka ENDP
END
I have tried everything what I can focus on - adding obj files to linker and so on. I only want to type the name of file, read date from it and calculate it. Calka.asm works well unless I try to get it work in my cpp file.
What am I doing wrong?