When the CPU executes an undefined instruction, an undefined instruction exception is triggered.
Through the exception vector table, we can find that the entry of the undefined instruction exception is at 0x0000,0004. That is, when the CPU executes the undefined instruction exception, the CPU on the hardware will jump to 0x0000,0004 to execute the code.
We trigger the exception by deliberately adding an undefined instruction 0x0300,00000 in the code. The figure below is the structure of a normal instruction. The original figure has the bit marks reversed, and the left to right should be 31-0.
The following table is a description table of interrupt exit and entry. It can be seen from the table that under ARM instructions, before entering the undefined instruction exception, the address of PC+4 will be stored in R14_x, which is lr_und, so when exiting, you only need to pass R14_und to PC.
When handling an undefined instruction exception, we first store the values of the r0-r12 registers on the stack, and then store the value of the lr_exception on the stack. Because these values may be modified, they must be saved first.
The functional definition of the registers is as follows.
After saving the scene, we perform exception handling. In the exception handling function, we print out the cpsr and output an additional string to indicate that an undefined instruction exception has occurred.
The .string directive is used to define the string here. The difference between it and the .ascii directive is that the string defined by the .ascii directive will not automatically add an end character at the end, while the string defined by the .string directive will automatically add an end character.
The following figure is a schematic diagram of the sequence of handling undefined instruction exceptions. After power-on, the CPU starts executing from address 0, then relocates and copies the entire code to SDRAM and jumps to SDRAM for execution. When an undefined instruction is detected, an exception is triggered and jumps back to 0x4, and then jumps to SDRAM at 0x4 to handle the undefined instruction exception.
Previous article:1.5.2 Exceptions and Interrupts_CPU Mode_State and Registers
Next article:Bidirectional traffic light based on LPC2138 control (green light flashes in the last 3 seconds)
Recommended ReadingLatest update time:2024-11-16 11:36
- Popular Resources
- Popular amplifiers
- Siemens PLC Programming Technology and Application Cases (Edited by Liu Zhenquan, Wang Hanzhi, Yang Kun, etc.)
- Siemens PLC from Beginner to Mastery with Color Illustrations (Yang Rui)
- Experience and skills in using Siemens S7-200PLC (Shang Baoxing)
- Siemens S7-1200-PLC Programming and Application Tutorial (3rd Edition) (Edited by Shi Shouyong)
Professor at Beihang University, dedicated to promoting microcontrollers and embedded systems for over 20 years.
- Innolux's intelligent steer-by-wire solution makes cars smarter and safer
- 8051 MCU - Parity Check
- How to efficiently balance the sensitivity of tactile sensing interfaces
- What should I do if the servo motor shakes? What causes the servo motor to shake quickly?
- 【Brushless Motor】Analysis of three-phase BLDC motor and sharing of two popular development boards
- Midea Industrial Technology's subsidiaries Clou Electronics and Hekang New Energy jointly appeared at the Munich Battery Energy Storage Exhibition and Solar Energy Exhibition
- Guoxin Sichen | Application of ferroelectric memory PB85RS2MC in power battery management, with a capacity of 2M
- Analysis of common faults of frequency converter
- In a head-on competition with Qualcomm, what kind of cockpit products has Intel come up with?
- Dalian Rongke's all-vanadium liquid flow battery energy storage equipment industrialization project has entered the sprint stage before production
- Allegro MicroSystems Introduces Advanced Magnetic and Inductive Position Sensing Solutions at Electronica 2024
- Car key in the left hand, liveness detection radar in the right hand, UWB is imperative for cars!
- After a decade of rapid development, domestic CIS has entered the market
- Aegis Dagger Battery + Thor EM-i Super Hybrid, Geely New Energy has thrown out two "king bombs"
- A brief discussion on functional safety - fault, error, and failure
- In the smart car 2.0 cycle, these core industry chains are facing major opportunities!
- The United States and Japan are developing new batteries. CATL faces challenges? How should China's new energy battery industry respond?
- Murata launches high-precision 6-axis inertial sensor for automobiles
- Ford patents pre-charge alarm to help save costs and respond to emergencies
- New real-time microcontroller system from Texas Instruments enables smarter processing in automotive and industrial applications
- 【GD32L233C-START Review】0.96inch oled screen driver
- Week 1: Learn about the hardware information of the development board
- imx6ull transplant alsa
- Central media report: Beixing is becoming a potential unicorn company
- "Playing with the board" + Zhou Hangci's book Chapter 8, Example 4
- Experts who are familiar with 7135 are welcome to explain and discuss if interested.
- Recommend a fast source code style conversion tool AStyle
- Is there something wrong with the advanced search?
- Wireless Communication RED Directive ETSI EN 301489-1 V2.2.3 (2019-11) Standard Update
- When designing PCB, please package the ground properly and don’t be so stingy, okay?