The Use of Macros and the Establishment of Structured Memory Tables in AMR

Publisher:脑电风暴Latest update time:2017-11-27 Source: eefocusKeywords:AMR Reading articles on mobile phones Scan QR code
Read articles on your mobile phone anytime, anywhere
  1. MACRO  

  2. $HandlerLabel HANDLER $HandleLabel  

  3.   

  4. $HandlerLabel  

  5.     sub sp,sp,#4 ;decrement sp(to store jump address)  

  6.     stmfd sp!,{r0} ;PUSH the work register to stack(lr does't push because it return to original address)  

  7.     ldr r0,=$HandleLabel;load the address of HandleXXX to r0  

  8.     ldr r0,[r0] ;load the contents(service routine start address) of HandleXXX  

  9.     str r0,[sp,#4] ;store the contents(ISR) of HandleXXX to stack  

  10.     ldmfd sp!,{r0,pc} ;POP the work register and pc(jump to ISR)  

  11.     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.


  1. MACRO ; Macro definition   

  2. CALL $Function,$dat1,$dat2; macro name is CALL, with 3 parameters  

  3. IMPORT $Function ; declare an external subroutine   

  4. MOV R0,$dat1 ; Set subroutine parameters, R0=$dat1  

  5. MOV R1,$dat2          

  6. BL Function ;Call subroutine   

  7. 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.


Keywords:AMR Reference address:The Use of Macros and the Establishment of Structured Memory Tables in AMR

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

Top 10 AMR modules realize full-scenario automation of production line logistics
In recent years, achieving intelligent transformation through automation technology has become a necessary path for the manufacturing industry to achieve higher efficiency, production capacity and competitiveness. In addition to the technological upgrade of the production method itself, more and more companies have
[robot]
AMR Industrial Mobile Robots: The Future "Smart Manufacturing Main Force" Behind New Energy Lithium Battery Manufacturing
Driven by market trends and policy support with intelligence and electrification as the core, China's new energy vehicle market is developing at an astonishing speed and entering a new stage of explosive growth. 1%, 5%, 13.4%, 28.5 % - these four data are for the market penetration rate
[robot]
MiR eBook: The FMCG market is poised for recovery, and AMRs empower the three major operating processes in the FMCG industry
MiR eBook: The FMCG market is poised for recovery, and AMRs empower the three major operating processes in the FMCG industry March 29, 2023, Shanghai – The development theme of China’s consumer goods market in 2023 is undoubtedly “expanding domestic demand”. Driven by policies and a huge market base o
[robot]
MiR eBook: The FMCG market is poised for recovery, and AMRs empower the three major operating processes in the FMCG industry
Latest Microcontroller Articles
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号