This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

#DEFINE and EXTRN NUMBER are incompatible ???

Dear friends,

Plz help me in solving this bad problem:

PROBLEM DESCRIPTION:

I have a number defined in C and I DONT want to alocate memory in 8051 for this number :

#define myNumber 0x1234

All is well, when i work with myNumber in C for example:

HiByte=myNumber/256;

will translate as expected:
MOV HiByte,#012H ;
No memory alocated for myNumber and stil, C compiler is capable to make calculus based on it.

Happy with that, now i try tu use myNumber (remember defined in C) in ASM.
And that is the problem: I'm unnable to found a method to see myNumberin ASM.

Shortly:
Seems to me that A51 compiler is unable to see a numerical constant declared in C51 with #define directive (but mybe i missing something out, and that's why I ask for your expertize, Dear friends)

An example follows:

//---------file main.c----------------

//I wish to see this number both in C and ASM
//PLZ NOTE: I dont want to reserve memory for myNumber
//i only wish to use it's High Byte in a data memory location

#define myNumber 0x1234

//function defined in ASM which use myNumber
extern  unsigned char GetHiByte(void);

//reserve memory location
unsigned char HiByte;

void main (void)
{
	HiByte=myNumber/256;//all is well in C
	HiByte=GetHiByte();//dont work in ASM, myNumber is not seen
			   //and is initialized to zero
}

;-------file func.a51-----------------

?PR?GetHiByte?FUNC? segment code

	EXTRN NUMBER (myNumber)

	public GetHiByte

rseg ?PR?GetHiByte?FUNC?

	using 0
GetHiByte:

	mov r7,#HIGH(myNumber)
	ret

end

Linker errors:
*** WARNING L1: UNRESOLVED EXTERNAL SYMBOL
SYMBOL: MYNUMBER
MODULE: func.obj (FUNC)
*** WARNING L2: REFERENCE MADE TO UNRESOLVED EXTERNAL
SYMBOL: MYNUMBER
MODULE: func.obj (FUNC)
ADDRESS: 0016H

Parents
  • "the C51 manual ... Chapter 4 lacks in information on haw preprocessor works."

    That's because it's a Compiler Manual - not a 'C' textbook!

    It is not the job of a Compiler Manual to tech you how to write programs in 'C' - that is the job of a textbook and, preferably, a 'C' programming class.

    See the Preface in the front of the printed C51 Manual (same as the PDF version):

    "This manual describes how to use the Cx51 Optimizing C Compilers to compile C programs for your target 8051 environment ... This manual assumes that you are familiar with the Windows operating system, know how to program 8051 processors, and have a working knowledge of the C programming language." (my emphasis)

    Also:

    "If you have questions about programming in C, or if you would like more
    information about the C programming language, refer to "Books About the C Language" on page 16."

Reply
  • "the C51 manual ... Chapter 4 lacks in information on haw preprocessor works."

    That's because it's a Compiler Manual - not a 'C' textbook!

    It is not the job of a Compiler Manual to tech you how to write programs in 'C' - that is the job of a textbook and, preferably, a 'C' programming class.

    See the Preface in the front of the printed C51 Manual (same as the PDF version):

    "This manual describes how to use the Cx51 Optimizing C Compilers to compile C programs for your target 8051 environment ... This manual assumes that you are familiar with the Windows operating system, know how to program 8051 processors, and have a working knowledge of the C programming language." (my emphasis)

    Also:

    "If you have questions about programming in C, or if you would like more
    information about the C programming language, refer to "Books About the C Language" on page 16."

Children