$24
6.1 Assignment
For this lab, you will implement some C++ functions for a queue ADC using an array. The main difficulty in linking assembly language with C++ is that C++ compilers “mangle” the names of class member functions. In order to write them in assembly, we must discover what name the C++ compiler creates. The second issue is that the C++ compiler always passes a pointer to the object, as the first parameter. So a C++ class member function has a “hidden” parameter, which is a pointer to the object being modified.
For example, given the following C++ class,
1
2
3
4
5
6
7
8
9
10
11
12
13
14
class example_class{
private:
.
.
.
public:
.
.
.
int do_something(int x, int j);
.
.
.
}
the do_something member function would be mangled so that its C prototype looks like this:
int _ZN13example_class12do_somethingEii(example_class *this, int x, int j);
Additionally, a C++ objects are stored in memory in the same way as C structs. The only real difference is that C++ objects can have virtual functions. Virtual functions are stored in the “struct” as pointers to the actual functions.
6.2 Instructions
1. Download queue.tgz from the site provided by your instructor and extract the files:
1 lpyeatt@rp01 $ tar xfz queue.tgz
Go into the queue directory and run make.
Use objdump to get a list of all of the symbols in the ADT.
1 lpyeatt@rp01 $ objdump --syms queue.o
Find the “mangled” names for the enque, deque, isfull, and isempty member functions.
Create a file named queue_asm.S and write the enque and deque functions in assembly, using the mangled names.
Comment out the enqueue function in the queue.cc file.
Modify the makefile to assemble and link queue_asm.S along with the C++ source files.