PIC Hardware Stack vs. Software Stack

Publisher:GoldenSerenityLatest update time:2016-08-26 Source: eefocusKeywords:PIC Reading articles on mobile phones Scan QR code
Read articles on your mobile phone anytime, anywhere
Hardware stack: It may also be called system stack, which is located in the RAM area of ​​the chip. Some people say that as long as the microcontroller can use PUSH and POP instructions, it can be said to have a hardware stack. I personally think that this statement is not very comprehensive. Pushing and popping operations through instructions are just one type of operation in the system stack. The system stack can also be called implicitly. For example, when calling a subroutine, the system will actively push the breakpoint into the stack without the user having to operate through instructions. The system stack can be used to save data or pass data between task subroutines. Usually, the bottom of the stack is set at the high end of the memory, that is, the highest section of the memory is designated as the stack area. These are downward growing stacks. The stack pointer may be a dedicated register or may borrow a general register. There are also microcontrollers that set a stack area in the data area, which may grow upward or downward.

The software stack is implemented by you through coding. You allocate a block in memory as the stack area and use a variable as the stack pointer.

    Software stack: It can also be called user stack. It can be defined in internal or external RAM. It is a dedicated data stack created by the user for a task, which is separated from the data area of ​​the system stack. It can save any registers and status words that the user wants to save.

    The software stack of MPLAB C18 is an upward-growing stack data structure. The compiler puts function parameters and local variables of the auto storage class into the software stack. The software stack is different from the hardware stack used by PICmicro MCUs to save function call return addresses.

    The stack pointer (FSR1) always points to the next available stack address. MPLAB C18 uses FSR2 as a frame pointer, which allows fast access to local variables and parameters. When a function is called, its stack-based parameters are pushed onto the stack in right-to-left order before the function is called. On entry to a function, the leftmost function parameter is at the top of the software stack.

    The frame pointer points to the address on the stack that separates stack-based parameters from stack-based local variables. Stack-based parameters are located below the frame pointer, while stack-based local variables are located above the frame pointer. When a C function is first entered, the called function pushes the value of FSR2 onto the stack and copies the value of FSR1 to FSR2, thereby saving the calling function's scene and initializing the current function's frame pointer. The total length of the function's stack-based local variables is then added to the stack pointer, and stack space is allocated for these variables. Stack-based local variables and stack-based parameters are referenced based on their offset relative to the frame pointer.

Keywords:PIC Reference address:PIC Hardware Stack vs. Software Stack

Previous article:PIC Basics
Next article:16F876 controlled electric bicycle drive system source code

Recommended ReadingLatest update time:2024-11-16 08:38

PIC32 Getting Started - Environment Construction
     To learn PIC32, you must first build a compilation environment, otherwise it will be difficult to proceed to the next step of learning.      The first step is to download two software packages: the integrated environment MPLABX-v2.26-windows-installer.exe and the compiler xc32-v1.31-windows-installer.exe, downl
[Microcontroller]
Latest Microcontroller Articles
  • Download from the Internet--ARM Getting Started Notes
    A brief introduction: From today on, the ARM notebook of the rookie is open, and it can be regarded as a place to store these notes. Why publish it? Maybe you are interested in it. In fact, the reason for these notes is ...
  • Learn ARM development(22)
    Turning off and on interrupts Interrupts are an efficient dialogue mechanism, but sometimes you don't want to interrupt the program while it is running. For example, when you are printing something, the program suddenly interrupts and another ...
  • Learn ARM development(21)
    First, declare the task pointer, because it will be used later. Task pointer volatile TASK_TCB* volatile g_pCurrentTask = NULL;volatile TASK_TCB* vol ...
  • Learn ARM development(20)
    With the previous Tick interrupt, the basic task switching conditions are ready. However, this "easterly" is also difficult to understand. Only through continuous practice can we understand it. ...
  • Learn ARM development(19)
    After many days of hard work, I finally got the interrupt working. But in order to allow RTOS to use timer interrupts, what kind of interrupts can be implemented in S3C44B0? There are two methods in S3C44B0. ...
  • Learn ARM development(14)
  • Learn ARM development(15)
  • Learn ARM development(16)
  • Learn ARM development(17)
Change More Related Popular Components

EEWorld
subscription
account

EEWorld
service
account

Automotive
development
circle

About Us Customer Service Contact Information Datasheet Sitemap LatestNews


Room 1530, 15th Floor, Building B, No.18 Zhongguancun Street, Haidian District, Beijing, Postal Code: 100190 China Telephone: 008610 8235 0740

Copyright © 2005-2024 EEWORLD.com.cn, Inc. All rights reserved 京ICP证060456号 京ICP备10001474号-1 电信业务审批[2006]字第258号函 京公网安备 11010802033920号