Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

C program to find size of the processor

Status
Not open for further replies.
HAI echo47,

All automatic variables are stored in stack segment except the static. The static variables are stored in data segment. I already submitted two methods for finding size of compiler. But cksivaram asked program that is why I did not use any built in command but your answer also correct.

Added after 13 minutes:

hai cksivaram,

Till now What I have given programs all are for finding which compiler it is? not for processor. I am trying for processor. soon I will send you.
 

sureshreddy said:
HAI echo47,

All automatic variables are stored in stack segment except the static. The static variables are stored in data segment. I already submitted two methods for finding size of compiler. But cksivaram asked program that is why I did not use any built in command but your answer also correct.

Added after 13 minutes:

hai cksivaram,

Till now What I have given programs all are for finding which compiler it is? not for processor. I am trying for processor. soon I will send you.

That is not true always. Auto vars can be stored within registers as well. If i am not wrong C standard does not specify exactly storage location for auto's and this is implementation dependent.


ckshivaram wrote :

"For finding the size of the processor you use int, but what is the size of character for a 8 bit controller / processor. By looking at pin diagram of processor how do you find out the size."

Did somebody say that he/she is capable to determine proc size by counting pins?
For better result you can use datasheet when counting pins. Together with pin names you can find size of the proc there as well.


P.S. would we move this thread to General subforum?
 

The C standard says nothing about memory segments.

Some processors don't have segmented memory.

The size of a C int can be different from the processor size. It's implementation dependent. Also, an int must have at least 16 bits, even on an 8-bit processor. (Some compilers provide an 8-bit int option, but that mode doesn't conform to standard C.)
 

That is not true always. Auto vars can be stored within registers as well. If i am not wrong C standard does not specify exactly storage location for auto's and this is implementation dependent.


ckshivaram wrote :

"For finding the size of the processor you use int, but what is the size of character for a 8 bit controller / processor. By looking at pin diagram of processor how do you find out the size."

Did somebody say that he/she is capable to determine proc size by counting pins?
For better result you can use datasheet when counting pins. Together with pin names you can find size of the proc there as well.



Hai Artem,


My point regarding automatic variable always store in stack segment is TRUE exception for static variables. what you said regarding automatic variables is not correct because if you specify register keyword for a variable then only that particular variable will store in registers.


HAI, Ckshivaram,


Yes, sivaram what you said is correct for finding 8 bit 0r 16 bit processor but one point I have to add here is that based on number of data lines which will be available on pin diagram, based on that you can easily find out .

Hai Eco47,

PLZ refer once again and give me reply.
If C standard does not say any thing about memory segments means where the variables are going to store. My point of view it has memory segments like TEXT OR CODESEGMENT, DATASEGMENT, HEAPSEGMENT, and STACK SEGMENT. One more segment called const segment but we are not frequently talking about it.



Another thing is that size of data types not dependant on processor always dependant on COMPILER.
 

The ANSI/ISO C standard defines the language, not how to implement the compiler. It avoids specifying where the compiler should or shouldn't store anything, and leaves those decisions up to the implementation. The standard never mentions stacks or memory segments. Some implementations don't have those mechanisms.

'const' is a type qualifier that restricts how an object can be accessed. It's not a segment.

Here are the 1990 and 1999 editions of the C standard. About 10 megabytes.
**broken link removed**
 

sureshreddy said:
Hai Artem,


My point regarding automatic variable always store in stack segment is TRUE exception for static variables. what you said regarding automatic variables is not correct because if you specify register keyword for a variable then only that particular variable will store in registers.

If you are true in this statement this only can be applied to particular compiler but not to all of them.


Check the IAR compiler for AVR micros :
(ftp://ftp.iar.se/WWWfiles/avr/guides/ocavr.pdf)

Variables that are defined inside a function—not declared static—are named auto
variables by the C standard. A small number of these variables are placed in processor
registers; the rest are placed on the stack
. From a semantic point of view, this isequivalent. The main differences are that accessing registers is faster, and that less
memory is required compared to when variables are located on the stack.
Auto variables live as long as the function executes; when the function returns, the
memory allocated on the stack is released.
 

Hai artem,
The link which u have given is not opening.can u send me once again link.
 

echo47 said:
The ANSI/ISO C standard defines the language, not how to implement the compiler. It avoids specifying where the compiler should or shouldn't store anything, and leaves those decisions up to the implementation. The standard never mentions stacks or memory segments. Some implementations don't have those mechanisms.

'const' is a type qualifier that restricts how an object can be accessed. It's not a segment.

Here are the 1990 and 1999 editions of the C standard. About 10 megabytes.
**broken link removed**

Hai,
I also accept that "The ANSI/ISO C standard defines the language, not how to implement the compiler".But what i given just for our understanding purpose.
 

I don't think there is a perfect solution.

I would likley bet if the following is true, then you do know the data width of the processor. Some people may think the following would never happen, well you are wrong. The TI C compiler for the 320C3x family this is true...all generic C data types are 32-bt wide...period.
if (sizeof(char) == sizeof(int)) && (sizeof(int) == sizeof(long))
printf("Processor Data Width = %u\r\n", sizeof(int) * 8);

(sizeof(int) * 8) is usually the size of the processor in most cases, but not all. I can provide many examples where that is not the case.

(&Var2 - &Var1) most likely will not be of any help because the linker might be aligning data wider than the native data width.

Since C is a high-level language, the compiler can easily hide the true width of the processor. A compiler can make an 8-bit processor handle 16-bit, 32-bit, 64-bit C integer types, and all of your operations could not prove the fact in C.

Some of the types in "stdint.h" could help provide some clues, but likely won't be 100% correct either.

I think one way to determine the very maximum a processor width could be is the sizeof() a pointer. I think all processors that I've ever seen have an address bus greater than or equal to the size of the data bus. Likely there is some processor that doesn't meet this rule, but this could be used for most processors.

I don't think there is a 100% portable way to determine the width of a processor in C. I need to think about this one a little more...
 

Please let me know how to find out the size of the procssor i.e. if it is 8 bit, 16 bit 32 bit or 64bit using a C program


Please tell me the answer if you previously got to know answer for your question.

My idea is to , Declare a register variable.
left shift it 32 times and then add 1 to it and check value less than 0. If TRUE the it must be 32bit else 64bit.

Does this work ?
 
Last edited:
Please tell me the answer if you previously got to know answer for your question.

My idea is to , Declare a register variable.
left shift it 32 times and then add 1 to it and check value less than 0. If TRUE the it must be 32bit else 64bit.

Does this work ?

It surely works. This is common misunderstanding between CPU size and memory alignment.
There are compiler options to set the size of int to 16 bits or 32 bits.
However actual size of CPU is not dependent on address bus as mentioned in the above posts but its actually the size of the ALU.
Its observed most commonly that size of the ALU and address bus is same across most of the architecture but its not always the case.

Thanks Sai Pavan.
 

Status
Not open for further replies.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top