1 year ago
#254667
Welt
Error LNK2019: unresolved external symbol C++ and ASM
I ran into this error when trying to run this program that compares the sorting speed of the same array in C++ using both C++ and ASM.
Error Message:
error LNK2019: unresolved external symbol _AsmSelectionSort referenced in function _main Hint on symbols that are defined and could potentially match: AsmSelectionSort
A section of the C++ Code where it is declared is as follows:
#include <iostream>
#include <iomanip>
#include <chrono>
using namespace std;
// Function prototypes for the selection sort and swap functions.
void selectionSort(int array[], int size);
void swap(int &a, int &b);
// Function prototype for the boolean isAscending function.
bool isAscending(int numbers[], int size);
// Function Prototype for the assembly language version of selection sort.
extern "C" {
void AsmSelectionSort(int array[], int count);
}
And this is where the asm is called:
cout << " Using the Assembly Language Selection Sort Algorithm." << endl;
start = chrono::high_resolution_clock::now();
for (int n = 0; n < REPETITIONS; n++)
{
// Copy the randomly generated array.
for (int i = 0; i < SIZE; i++)
{
numbers[i] = element[i];
}
// Use the ASM version of the Selection Sort algorithm.
AsmSelectionSort(numbers, SIZE);
}
end = chrono::high_resolution_clock::now();
auto asmDiff = end - start;
My ASM:
.486
.model small
.code
AsmSelectionSort PROC
PUSH AX ; push AX onto the STACK
PUSH BX ; push BX onto the STACK
PUSH CX ; push CX onto the STACK
PUSH DX ; push DX onto the STACK
PUSH DI ; push DI onto the STACK
CMP BX, 1 ; compare BX with 1
JLE @Skip_Sorting ; jump to label @Skip_Sorting if BX<=1
DEC BX ; set BX=BX-1
MOV CX, BX ; set CX=BX
MOV AX, SI ; set AX=SI
@Outer_Loop: ; loop label
MOV BX, CX ; set BX=CX
MOV SI, AX ; set SI=AX
MOV DI, AX ; set DI=AX
MOV DL, [DI] ; set DL=[DI]
@Inner_Loop: ; loop label
INC SI ; set SI=SI+1
CMP [SI], DL ; compare [SI] with DL
JNG @Skip ; jump to label @Skip if [SI]<=DL
MOV DI, SI ; set DI=SI
MOV DL, [DI] ; set DL=[DI]
@Skip: ; jump label
DEC BX ; set BX=BX-1
JNZ @Inner_Loop ; jump to label @Inner_Loop if BX!=0
MOV DL, [SI] ; set DL=[SI]
XCHG DL, [DI] ; set DL=[DI] , [DI]=DL
MOV [SI], DL ; set [SI]=DL
LOOP @Outer_Loop ; jump to label @Outer_Loop while CX!=0
@Skip_Sorting: ; jump label
POP DI ; pop a value from STACK into DI
POP DX ; pop a value from STACK into DX
POP CX ; pop a value from STACK into CX
POP BX ; pop a value from STACK into BX
POP AX ; pop a value from STACK into AX
RET ; return control to the calling procedure
AsmSelectionSort ENDP
end
What did I do wrong?
c++
arrays
sorting
assembly
extern
0 Answers
Your Answer