1. Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.
    Dismiss Notice

How to create stack overflow/underflow exception ?

Discussion in 'Microcontrollers' started by jani12, Jun 21, 2017.

  1. jani12

    jani12 Member

    Joined:
    Oct 16, 2014
    Messages:
    54
    Likes:
    0
    I'm programming Infineon TC29x Aurix Tricore Microcontroller based embedded system in 'C' language.

    Consider stack starting address 0x5000 0000. The stack size is 0x2000.

    If I take current stack pointer minus 0x2000, will that create stack exception? If yes, what might be 'C' or assembly language code that will achieve this?

    My thought is if I subtract negative 0x2000 from current stack pointer or add 0x2000 to current stack pointer, I'll be outside stack and stack exception will occur ?

    I need to set program counter to illegal address, i.e. 0x00FF FFFC. Can this be done with assembly language instructions?
    If yes, please instrument assembly language instruction that would set program counter to 0x00FF FFFC while code is running.
     
  2. Ian Rogers

    Ian Rogers Super Moderator Most Helpful Member

    Joined:
    Mar 28, 2011
    Messages:
    9,163
    Likes:
    909
    Location:
    Rochdale UK
    Easy... Set the stack to 128 and create a local 128 byte array... That'll do it!
     
    • Agree Agree x 1
  3. jani12

    jani12 Member

    Joined:
    Oct 16, 2014
    Messages:
    54
    Likes:
    0
    Please disregard following text from my original post:

    "I need to set program counter to illegal address, i.e. 0x00FF FFFC. Can this be done with assembly language instructions?
    If yes, please instrument assembly language instruction that would set program counter to 0x00FF FFFC while code is running."
     
  4. dave

    Dave New Member

    Joined:
    Jan 12, 1997
    Messages:
    -
    Likes:
    0


     
  5. Ian Rogers

    Ian Rogers Super Moderator Most Helpful Member

    Joined:
    Mar 28, 2011
    Messages:
    9,163
    Likes:
    909
    Location:
    Rochdale UK

    Nothing will happen! There is no illegal address that the PC can get to... If you specify above the PC's count ability, the address will just roll over!

    Illegal addresses and instructions are normally associated with kernels and operating systems.. You determine which one is disallowed... You are the only one who knows where not to write!!
     
  6. Wade Hassler

    Wade Hassler Member

    Joined:
    Jun 4, 2009
    Messages:
    152
    Likes:
    11
    You could insert an assembly-language line into your code, something that loads data from an illegal address:
    LD.W D[15], bad_address
    ... you'll need to find what the unimplemented/ unused/forbidden addresses are for yourself
     
    • Agree Agree x 1

Share This Page