SPRU514Z July 2001 – October 2023 SM320F28335-EP
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.
int compute(int val, int *err);
int foo(int val, int *err)
{
static int last_err = 0;
int result = 0
if (last_err == 0)
result = compute(val, &last_err);
*err = last_err;
return result;
}
The resulting assembly that is output by the compiler is as follows.
;***************************************************************
;* FNAME: _foo_FiPi FR SIZE: 4 *
;* *
;* FUNCTION ENVIRONMENT *
;* *
;* FUNCTION PROPERTIES *
;* 0 Parameter, 3 Auto, 0 SOE *
;***************************************************************
_foo_FiPi:
ADDB SP,#4
MOVZ DP,#_last_err$1
MOV *-SP[1],AL
MOV AL,@_last_err$1
MOV *-SP[2],AR4
MOV *-SP[3],#0
BF L1,NEQ
; branch occurs
MOVL XAR4,#_last_err$1
MOV AL,*-SP[1]
LCR #_compute__FiPi
; call occurs [#_compute__FiPi]
MOV *-SP[3],AL
L1:
MOVZ AR6,*-SP[2]
MOV *+XAR6[0],*(0:_last_err$1)
MOV AL,*-SP[3]
SUBB SP,#4
LRETR
; return occurs
Executing the C++ name demangler will demangle all names that it believes to be mangled. Enter:
dem2000 foo.asm
The result after running the C++ name demangler is as follows. The linknames in foo( ) and compute( ) are demangled.
;***************************************************************
;* FNAME: foo(int, int *) FR SIZE: 4 *
;* *
;* FUNCTION ENVIRONMENT *
;* *
;* FUNCTION PROPERTIES *
;* 0 Parameter, 3 Auto, 0 SOE *
;***************************************************************
foo(int, int *):
ADDB SP,#4
MOVZ DP,#_last_err$1
MOV *-SP[1],AL
MOV AL,@_last_err$1
MOV *-SP[2],AR4
MOV *-SP[3],#0
BF L1,NEQ
; branch occurs
MOVL XAR4,#_last_err$1
MOV AL,*-SP[1]
LCR #compute(int, int *)
; call occurs [#compute(int, int *)]
MOV *-SP[3],AL
L1:
MOVZ AR6,*-SP[2]
MOV *+XAR6[0],*(0:_last_err$1)
MOV AL,*-SP[3]
SUBB SP,#4
LRETR
; return occurs