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't 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
This macro defines $HandlerLabel HANDLER$HandleLabel. The first $HandlerLabel is the function name (or label), and the second $HandleLabel (note that it is missing an r compared to the first $HandlerLabel) is a function entry address.
The following code can prove that
^ _ISR_STARTADDRESS ;_ISR_STARTADDRESS=0x33FF_FF00
HandleReset # 4
HandleUndef #4
This code means that a table is created with 0x33FF_FF00 as the first address. The ^ in it is consistent with the MAP instruction. MAP is used to define the first address of a structured memory table. At this time, the location counter {VAR} of the memory table is set
The address value {VAR} is a built-in variable of the assembler. ^ is synonymous with MAP.
The # sign corresponds to FIELD, indicating a data field that occupies 4 bytes.
Therefore, it can be seen that HandleReset is an address, not HandlerReset.
MACRO specific use
Format:
MACRO
[$label] macro name [$parameter1, $parameter2, $parameter3 ··········]
Instruction sequence
MEND
The label and parameter are optional, but the macro name is a required part. The label and parameter will be replaced by user-defined symbols when the macro instruction is expanded. The instruction sequence between MACRO and MEND is called the macro definition body. The first line of the macro definition body should declare the prototype of the macro (including the macro name and required parameters)
Pay attention to the use of labels. If you want to use labels inside a macro body, you must use a label to declare it when declaring the macro, making this label a main label. All other labels in the macro statement segment must be composed of this main label. And in the macro statement segment, add a "$" sign before all labels.
MACRO ; Macro definition
CALL $Function,$dat1,$dat2; macro name is CALL, with 3 parameters
IMPORT $Function ; declare an external subroutine
MOV R0,$dat1 ; Set subroutine parameters, R0=$dat1
MOV R1,$dat2
BL Function ;Call subroutine
MEND ; macro definition ends
…
CALL FADD1,#3,#2 ; macro call
…
After assembly preprocessing, the macro call will be expanded and the program listing is as follows:
…
IMPORT FADD1
MOV R0,#3
MOV R1,#3
BL FADD1
…
Here we should pay attention to a rather confusing issue, that is, when defining a macro, it is not necessary to put the macro name first and then the parameters (of course, it is possible to have no parameters). It can also be like the first example, where the middle HANDLER is the macro name and the other two at the end are parameters.
Specific use of MAP and FIELD
MAP is used to define the first address of a structured memory table. At this time, the location counter {VAR} of the memory table is set to the address value {VAR} is a built-in variable of the assembler. ^ is synonymous with MAP. Pseudo-instruction format:
MAP expr,{base_register}
Where expr is a numeric expression or a label in the program. When there is no base_register in the instruction, expr is the first address of the structured memory table.
base_register A register. When this item is included in the instruction, the first address of the structured memory table is the sum of expr and the base_register register value.
Examples of pseudo-instruction applications are as follows;
MAP 0x00,R9; define the first address of the memory table as R9
Timer FIELD 4; define the data field Timer, the length is 4 bytes
Attrib FIELD 4; define the data field Attrib, the length is 4 bytes
String FIELD 100 ; define the data field String, the length is 100 bytes
…
ADR R9,DataStart; Set the value of R9, that is, set the structured memory table address
LDR R0,Atrrib; equivalent to LDR,R0,[R9,#4]
…
The MAP directive and the FIELD directive are used together to define a structured memory table structure.
FIELD is used to define a data field in a structured memory table. # is synonymous with FIELD.
Pseudo instruction format:
{table} FIELD expr
in
When label is included in the instruction, the value of label is the value of the current memory table location counter {VAR}. After the assembly compiler processes this FIELD pseudo-instruction, the value of the memory table counter will be added to expr.
expr represents the number of bytes occupied by this data field in the memory table.
Previous article:A bare metal program about mini2440 - LED and button interrupt
Next article:S3C2440 IIC read and write AT24C02A
Recommended ReadingLatest update time:2024-11-22 09:14
- Naxin Micro and Xinxian jointly launched the NS800RT series of real-time control MCUs
- How to learn embedded systems based on ARM platform
- Summary of jffs2_scan_eraseblock issues
- Application of SPCOMM Control in Serial Communication of Delphi7.0
- Using TComm component to realize serial communication in Delphi environment
- Bar chart code for embedded development practices
- Embedded Development Learning (10)
- Embedded Development Learning (8)
- Embedded Development Learning (6)
Professor at Beihang University, dedicated to promoting microcontrollers and embedded systems for over 20 years.
- Intel promotes AI with multi-dimensional efforts in technology, application, and ecology
- ChinaJoy Qualcomm Snapdragon Theme Pavilion takes you to experience the new changes in digital entertainment in the 5G era
- Infineon's latest generation IGBT technology platform enables precise control of speed and position
- Two test methods for LED lighting life
- Don't Let Lightning Induced Surges Scare You
- Application of brushless motor controller ML4425/4426
- Easy identification of LED power supply quality
- World's first integrated photovoltaic solar system completed in Israel
- Sliding window mean filter for avr microcontroller AD conversion
- What does call mean in the detailed explanation of ABB robot programming instructions?
- Europe's three largest chip giants re-examine their supply chains
- Breaking through the intelligent competition, Changan Automobile opens the "God's perspective"
- The world's first fully digital chassis, looking forward to the debut of the U7 PHEV and EV versions
- Design of automotive LIN communication simulator based on Renesas MCU
- When will solid-state batteries become popular?
- Adding solid-state batteries, CATL wants to continue to be the "King of Ning"
- The agency predicts that my country's public electric vehicle charging piles will reach 3.6 million this year, accounting for nearly 70% of the world
- U.S. senators urge NHTSA to issue new vehicle safety rules
- Giants step up investment, accelerating the application of solid-state batteries
- Guangzhou Auto Show: End-to-end competition accelerates, autonomous driving fully impacts luxury...
- EEWORLD University Hall----Design of DC power supply system for battery testing equipment
- Topic: High-performance dimming electronic ballast solution, a product jointly developed by IXYS and Atmel
- Should the PCB trace angle not be 90°? — PCB Layout Tips
- Problems with serial programming of STC89C51RC microcontroller
- Design of multi-visual sensor measurement and control system based on CAN bus
- Three-phase power-energy integrated circuit with SPI interface
- PIC16F15324 microcontroller serial port interrupt cannot enter
- A case of SPI communication malfunction
- EEWORLD University Hall----On-time Atom LWIP Video Tutorial
- Breakthrough TI BAW technology advances big data amidst the flood of information