masm within VisualC++ question (accessing external global variables)

  • Follow


Hi!

I've following masm-code and within that I want to access the global 
(declared externally in a c++-file) variables BitsLeft and N. According 
to masm help, declaring them extern or externdef should suffice.

However I do get unresolved symbol errors (for BitsLeft and N). I tried 
them with and without leading underscores.

----------------------------------------------
..686
..model flat, stdcall
option casemap :none

Extern _BitsLeft:dword
Extern _N:dword

..code

shiftCplusplus proc dwValue:DWORD

	mov		edx, -32
	mov		ebx, BitsLeft
	mov		ecx, ebx
	neg		ecx
	sub		ecx, edx
	mov		edi, N
	neg		edi
	sub		edi, edx
	bsr		esi, eax
	.if esi<ebx
	sub		edi, ecx
	xor		ecx, ecx
	.endif
	shl		eax, cl
	mov		ecx, edi
	shr		eax, cl
    ret
shiftCplusplus endp
end
----------------------------------------------

I don't understand why there's so little info about such fundamental 
issues on the net.

Would be great, if somebody can tell me what to do (or where to look)!

Any help greatly appreciated! Cheers Hannes

PS: this isn't the final code above (breaking dependencies...) ;-))

0
Reply Hannes 7/14/2005 7:26:22 PM

Hannes Allmaier wrote:
> Hi!
>
> I've following masm-code and within that I want to access the global 
> (declared externally in a c++-file) variables BitsLeft and N. According to 
> masm help, declaring them extern or externdef should suffice.
>
> However I do get unresolved symbol errors (for BitsLeft and N). I tried 
> them with and without leading underscores.
>

Have you declared the global variables as ' extern "C" ' in your C++ source 
code?

J.

0
Reply Jacek 7/15/2005 12:22:14 AM



Hannes Allmaier wrote:
> Hi!
>
> I've following masm-code and within that I want to access the global
> (declared externally in a c++-file) variables BitsLeft and N. According
> to masm help, declaring them extern or externdef should suffice.
>
> However I do get unresolved symbol errors (for BitsLeft and N). I tried
> them with and without leading underscores.
>
> (...)
>
> I don't understand why there's so little info about such fundamental
> issues on the net.
>
> Would be great, if somebody can tell me what to do (or where to look)!
>
> Any help greatly appreciated! Cheers Hannes
>
> PS: this isn't the final code above (breaking dependencies...) ;-))


Link the program with /map, and you'll be able to see exactly how the
C++ compiler decorated the name.  If BitsLeft is an int, you're
probably getting something like "?BitsLeft@@3HA".

Alternatively, you might want to put extern "C" {...} around the
definition of BitsLeft, and you should get something like "_BitsLeft".

0
Reply robertwessel2 7/15/2005 4:00:22 AM

Thanks a lot for helping me out!

extern "C" did its job very well (in this case the leading underscore is 
not necessary).

Great! One step further in assembly learning!

Thanks a lot! Hannes

PS: sorry for the double post BTW

0
Reply Hannes 7/15/2005 7:18:19 AM

3 Replies
268 Views

(page loaded in 0.038 seconds)

Similiar Articles:









7/29/2012 4:05:16 AM


Reply: