SLAU132Y September 2004 – June 2021
The examples in this section illustrate the demangling process.
This example shows a sample C++ program. In this example, the linknames of all the functions are mangled; that is, their signature information is encoded into their names.
class banana {
public:
int calories(void);
banana();
~banana();
};
int calories_in_a_banana(void)
{
banana x;
return x.calories();
}
The resulting assembly that is output by the compiler is as follows.
PUSH.W r10
SUB.W #2,SP
MOV.W SP,r12
CALL #_ZN6bananaC1Ev
MOV.W SP,r12
CALL #_ZN6banana8caloriesEv
MOV.W r12,r10
MOV.W SP,r12
CALL #_ZN6bananaD1Ev
MOV.W r10,r12
ADD.W #2,SP
POP r10
RET
Executing the C++ name demangler will demangle all names that it believes to be mangled. Enter:
dem430 calories_in_a_banana.asm
The result after running the C++ name demangler is as follows. The linknames in _ZN6bananaC1Ev, _ZN6banana8caloriesEv, and _ZN6bananaD1Ev are demangled.
calories_in_a_banana():
;* ----------------------------------------------------------------------------*
PUSH.W r10
SUB.W #2,SP
MOV.W SP,r12
CALL #banana::banana()
MOV.W SP,r12
CALL #banana::calories()
MOV.W r12,r10
MOV.W SP,r12
CALL #banana::~banana()
MOV.W r10,r12
ADD.W #2,SP
POP r10
RET