The MACRO pseudo-operation marks the beginning of the macro definition, and MEND marks the end of the macro definition.
Use MACRO and MEND to define a section of code, called a macro definition body, so that the code segment can be called multiple times through macro instructions in the program. The
syntax format is
MACRO
{$label} macroname {$parameter {,$parameter}...}
;code
...
;code
MEND
where:
$labelz When the macro instruction is expanded, label can be replaced with a corresponding symbol, usually a label. Use $ before a symbol to indicate that the corresponding value will be used to replace the symbol after $ when the program is assembled.
Macroname is the name of the defined macro, and
$parameter is the parameter of the macro instruction. When the macro instruction is expanded, it will be replaced with the corresponding value, similar to the formal parameter in the function. You can specify the corresponding default value for the parameter when defining the macro.
MACRO
$HandlerLabel HANDLER $HandleLabel
$HandlerLabel
sub sp,sp,#4 ;decrement sp(to store jump address)
stmfd sp!,{r0} ;PUSH the work register to stack(lr does not push because it return to original address)
ldr r0,=$HandleLabel;load the address of HandleXXX to r0
ldr r0,[r0] ;load the contents(service routine start address) of HandleXXX
str r0, [sp,#4] ;store the contents(ISR) of HandleXXX to stack
ldmfd sp!,{r0,pc} ;POP the work register and pc(jump to ISR)
MEND
;;Call HandlerFIQ in the program
HANDLER HandleFIQ
HandlerIRQ HANDLER HandleIRQ
HandlerUndef HANDLER HandleUndef
HandlerSWI HANDLER HandleSWI
HandlerDabort HANDLER HandleDabort
HandlerPabort HANDLER HandlePabort
For example, the first one is used as an example to explain HandlerFIQ HANDLER HandleFIQ
;; After the program is assembled, the result of the macro expansion is
HandlerFIQ
sub sp,sp,#4
stmfd sp!,{r0}
ldr r0,=HandleFIQ
ldr r0,[r0]
str r0,[sp,#4]
ldmfd sp!,{r0,pc}
Let's analyze it sentence by sentence. For the sake of analysis, assume sp = 0x33ff8000, $HandleLabel = 0x33ffff00,
[0x33ffff00] = 0x10000000, r0 = 0x56001234:
$HandlerLabel HANDLER $HandleLabel
The name of the macro is HANDLER and it has two parameters.
$HandlerLabel
defines a label
sub sp,sp,#4
Subtract 4 from the stack pointer to leave a word of space (for saving the jump address value), sp=0x33ff7ffc
stmfd sp!,{r0}
First, subtract 4 from sp (sp=0x33ff7ff8), and then push the r0 register to be used onto the stack. At this time, [0x33ff7ff8]=0x56001234
ldr r0,=$HandleLabel
Assign value to register r0, r0=0x33ffff00
ldr r0,[r0]
Assign value to register r0, r0=0x10000000
str r0,[sp,#4]
;Save register r0 to 0x33ff7ffc (0x33ff7ff8+4), sp is unchanged sp=0x33ff7ff8, if
str r0,[sp,#4]! sp changes
at this time
;[0x33ff7ffc] = 0x10000000
ldmfd sp!,{r0,pc}
Pop the two words at the top of the stack and save them to r0 and pc respectively. At this time, sp=0x33ff8000, r0=0x56001234, pc=0x10000000. By comparison, it is not difficult to find that sp and r0 have not changed before and after execution, and the program jumps to 0x10000000 to execute.
Previous article:TQ2440 uboot---6.start.S in relocate part analysis, adr and ldr difference
Next article:Immediate value problem in ARM data processing instructions
- Popular Resources
- Popular amplifiers
- Learn ARM development(16)
- Learn ARM development(17)
- Learn ARM development(18)
- Embedded system debugging simulation tool
- A small question that has been bothering me recently has finally been solved~~
- Learn ARM development (1)
- Learn ARM development (2)
- Learn ARM development (4)
- Learn ARM development (6)
Professor at Beihang University, dedicated to promoting microcontrollers and embedded systems for over 20 years.
- LED chemical incompatibility test to see which chemicals LEDs can be used with
- Application of ARM9 hardware coprocessor on WinCE embedded motherboard
- What are the key points for selecting rotor flowmeter?
- LM317 high power charger circuit
- A brief analysis of Embest's application and development of embedded medical devices
- Single-phase RC protection circuit
- stm32 PVD programmable voltage monitor
- Introduction and measurement of edge trigger and level trigger of 51 single chip microcomputer
- Improved design of Linux system software shell protection technology
- What to do if the ABB robot protection device stops
- Analysis of the application of several common contact parts in high-voltage connectors of new energy vehicles
- Wiring harness durability test and contact voltage drop test method
- From probes to power supplies, Tektronix is leading the way in comprehensive innovation in power electronics testing
- From probes to power supplies, Tektronix is leading the way in comprehensive innovation in power electronics testing
- Sn-doped CuO nanostructure-based ethanol gas sensor for real-time drunk driving detection in vehicles
- Design considerations for automotive battery wiring harness
- Do you know all the various motors commonly used in automotive electronics?
- What are the functions of the Internet of Vehicles? What are the uses and benefits of the Internet of Vehicles?
- Power Inverter - A critical safety system for electric vehicles
- Analysis of the information security mechanism of AUTOSAR, the automotive embedded software framework
- [Raspberry Pi Pico Review] 3. My first project
- Problems with op amp sampling in oximeters
- EasyARM-RT1052 Review Summary
- Submit your idea, experience MPS products or evaluation boards for free, and win a backpack, Bluetooth wireless headset, and 10,000 yuan in cash!
- Microchip Spring Sale, popular development tools up to 60% off!
- The 3 big benefits of the start of the Year of the Tiger are brought to you by Murata Tmall flagship store
- Power supply obstacles + small mistakes in charging management
- [NXP Rapid IoT Review] + The mobile APP can finally connect to the kit
- A novice asks for advice, how can a switching power supply achieve a regulated output without using a 431?
- MSP430F5438+DTH11 Example Code