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

Discussion in 'Embedded Systems and Microcontrollers' started by sandip mule, Dec 24, 2017.

  1. sandip mule

    Thread Starter New Member

    Jul 13, 2017
    2
    0
    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 ?????
     
  2. Sensacell

    Moderator

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

    Active Member

    Aug 17, 2017
    959
    302
    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.
     
  4. WBahn

    Moderator

    Mar 31, 2012
    24,077
    7,474
    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?
     
    sandip mule likes this.
  5. be80be

    AAC Fanatic!

    Jul 5, 2008
    1,768
    347
    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.
     
    sandip mule likes this.
  6. sandip mule

    Thread Starter New Member

    Jul 13, 2017
    2
    0
    Embedded c program for and 8 bit 4 kb flash memory controller
     
  7. spinnaker

    AAC Fanatic!

    Oct 29, 2009
    7,815
    3,663
    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.
     
  8. spinnaker

    AAC Fanatic!

    Oct 29, 2009
    7,815
    3,663

    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.
     
  9. WBahn

    Moderator

    Mar 31, 2012
    24,077
    7,474
    "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).
     
  10. WBahn

    Moderator

    Mar 31, 2012
    24,077
    7,474
    Not all processors have a hardware stack, yet you can still run a stack-oriented virtual machine on them.

    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.
     
Loading...