I have to write some member functions of a class in Assembly for an exam. I’ve followed every instruction but I still can’t get it to work. Here are the relevant files. The header and the main method are already provided, I just need to write the constructor and the elab1 method.
Class header
#include <iostream>
using namespace std;
struct st { int a; int vv1[4]; double vv2[4]; };
class cl
{ double b; st s;
public:
cl(int *p, double *d);
void elab1(st ss);
void stampa()
{ int i; cout << b << ' ' << s.a << endl;
for (i=0;i<4;i++) cout << s.vv1[i] << ' '; cout << '\t';
for (i=0;i<4;i++) cout << s.vv2[i] << ' '; cout << endl;
cout << endl;
}
};
Main method for testing
// prova1.cpp
#include "cc.h" // class header
int main()
{
st s = {1, 1,2,3,4, 1,2,3,4 };
int v[4] = {10,11,12,13 };
double d[4] = { 2, 3, 4, 5 };
cl cc1(v, d);
cc1.stampa();
cc1.elab1(s);
cc1.stampa();
}
And this is my assembly:
# es1.s
.text
.global __ZN2clC1EPiPe
__ZN2clC1EPiPe:
pushl %ebp
movl %esp, %ebp
subl $4, %esp
pushl %eax
pushl %ebx
pushl %ecx
pushl %edx
pushl %esi
cmpl $0, 12(%ebp)
je fine
cmpl $0, 16(%ebp)
je fine
movl 8(%ebp), %eax
movl 12(%ebp), %ebx
movl 4(%ebx), %ecx
movl %ecx, 12(%eax)
fldz
fstpl (%eax)
movl $0, -4(%ebp)
ciclo:
cmpl $4, -4(%ebp)
je fine
movl -4(%ebp), %esi
movl 12(%ebp), %ebx
movl (%ebx, %esi, 4), %ecx
subl %esi, %ecx
movl %ecx, 16(%eax, %esi, 4)
movl 16(%ebp), %ebx
pushl %eax
movl %esi, %eax
movl $3, %ecx
imull %ecx
movl %eax, %edx
popl %eax
movl 12(%ebp), %ecx
fldl (%ebx, %edx, 4)
fldl (%ecx, %esi, 4)
faddp %st, %st(1)
fstpl 32(%eax, %edx, 4)
fldl (%ebx, %edx, 4)
fldl (%eax)
faddp %st, %st(1)
fstpl (%eax)
incl -4(%ebp)
jmp ciclo
fine:
popl %esi
popl %edx
popl %ecx
popl %ebx
popl %eax
movl 8(%ebp), %eax
leave
ret
.global __ZN2cl5elab1E2st
__ZN2cl5elab1E2st: #TODO
I try to compile and link everything with the command-line statement that has been provided to us:
g++ -o es1 -fno-elide-constructors es1.s prova1.cpp
but it only gives me a bunch of undefined references:
/tmp/ccbwS0uN.o: In function `main':
prova1.cpp:(.text+0xee): undefined reference to `cl::cl(int*, double*)'
prova1.cpp:(.text+0x192): undefined reference to `cl::elab1(st)'
collect2: ld returned 1 exit status
Do you have any idea how can I solve this issue? I thought that probably I might have translated the function names in the wrong way, but I’ve checked them several times.
Apply
c++filtto your name mangling and compare to the signature in the error message.When removing one underscore and filtering with c++filt, I get for your mangled name
cl::cl(int*, long double*)which does not match any in your error message/class declaration.The correctly mangled name should be
_ZN2clC1EPiPdforcl::cl(int*, double*).I suggest that you improve the way (wahtever it is) to get the mangled name.