It is an Interview Question asked me in an interview !!!!

Thread Starter

sandip mule

Joined Jul 13, 2017
2
It is an embedded system related question !!!
How many cascading loop we can written in 8 bit microcontroller using embedded c ?
nesting loop
loop inside a loop ?
So anybody have any idea about this ?????
 

Sensacell

Joined Jun 19, 2012
2,634
If by "cascading loop" they mean subroutine calls, then it's limited to the size of the hardware stack, holding the return address.
 

philba

Joined Aug 17, 2017
960
I suspect they wanted to see how you take problems apart. On the surface, it's a silly question. But it's actually kind of clever because it forces to you figure out the limitations and what resources a loop uses. And then answer as a function of available resources. I'd guess they gave bonus points for asking questions to understand the question correctly.
 

be80be

Joined Jul 5, 2008
2,049
The C standard doesn't care about embedded, but vendors of embedded systems usually provide standalone implementations with whatever amount of libraries they're willing to provide. C is a widely used general purpose high level programming language mainly intended for system programming.
 

spinnaker

Joined Oct 29, 2009
7,835
If by "cascading loop" they mean subroutine calls, then it's limited to the size of the hardware stack, holding the return address.
If this is a correct assessment of the question then a better way to ask the question would be. How many recursive calls can be made. and yes it would be limited to the size of the stack. Which might also come into play would be the number of bits of the memory addresses.
 

spinnaker

Joined Oct 29, 2009
7,835
Why does the stack have to be in hardware?

@sandip mule : Are you asking about a C program that is for an embedded application, or about "Embedded C"?

How did you answer?

Where else is it going to be? Even if it is a virtual stack it still sits in memory and therefore has a limitation. If there are limitations set on the compiler then that will come into play too.

So maybe a better answer to the question would be it is limited to the amount of memory available for stack.
 

WBahn

Joined Mar 31, 2012
26,319
The C standard doesn't care about embedded, but vendors of embedded systems usually provide standalone implementations with whatever amount of libraries they're willing to provide. C is a widely used general purpose high level programming language mainly intended for system programming.
"Embedded C" is an official extension of the C language standard adopted in 2008 by the language standard committee specifically to address commonality issues that had arisen due to all of the different vendor-specific implementations. So the distinction between using a version of C for embedded systems and Embedded C is essentially the same as the distinction between using some vendor's version of C and using C99. If you are using a vendor-specific version, then the various limitations and capabilities dictated by that vendor, but if you are using Embedded C or C99 or another standard version, then a lot more is fixed (although there is still a lot of room for the implementation to dictate the specific limitations).
 

WBahn

Joined Mar 31, 2012
26,319
Where else is it going to be?
Not all processors have a hardware stack, yet you can still run a stack-oriented virtual machine on them.

So maybe a better answer to the question would be it is limited to the amount of memory available for stack.
I would agree.

Although I don't think the original question even needs to consider a stack at all. It appears to be about nested loops. The language standard set minimum nesting depths for blocks of code. In C99 it 127. In C89 it was 15 and in C11 I think it is 255. It's not so much a memory issue, as each loop may not need any additional memory beyond that used by the code to test the loop. It's certainly possible to write a bunch of nested loops that all use the same loop variable. The issue is that the compiler has to keep track of all of the blocks as it parses the code.

The minimum block depths are almost always exceeded by a large margin by a particular compiler, so an actual answer has to be couched in terms of what determines the limits and not what the limits actually are.
 
Top