ARM Architecture and Programming Notes

Publisher:dandan666Latest update time:2021-12-02 Source: eefocusKeywords:ARM Reading articles on mobile phones Scan QR code
Read articles on your mobile phone anytime, anywhere


1. Sorting


  1. AREA TEXT,CODE,READWRITE    

  2.     ENTRY    

  3.     MOV R0,#100 ;Number of loops    

  4.     MOV R1,#0 ; Initialize data    

  5. LOOP    

  6.     ADD R1,R1,R0; add the data to get the final data    

  7.     SUBS R0,R0,#1; loop data R0 minus 1    

  8.     CMP R0,#0 ; Compare R0 with 0 to see if the loop is finished    

  9.     BNE LOOP ; Determine whether the loop is finished, if accepted, proceed to the following steps      

  10.     LDR R2,=RESULT    

  11.     STR R1,[R2]    

  12. RESULT    

  13.     DCD 0    

  14. STOP    

  15.     B STOP   

  16.     ; Arrangement algorithm: first compare all the data with the first one, and finally take out the smallest data and put it in the first memory unit    

  17.     ;Then start comparing from the second memory unit and put the second smallest data into the second memory unit.    

  18.     ; By this inference, the ten data can be arranged.    

  19.     AREA TEXT,CODE,READWRITE    

  20.     ENTRY    

  21.     LDR R0,=DATA; Get the starting address of DATA data    

  22.     MOV R1,R0        

  23.     MOV R5,#9; The number of loops at the beginning is 10, so it should start from 9    

  24.     MOV R6,R5    

  25. COMPARE    

  26.     ADD R0,R0,#4; The address stored in R0 + 4 is represented as the address of the next number to be compared      

  27.     SUB R6,R6,#1 ; Loop once and subtract 1    

  28.     LDR R2,[R1]; Take the data in the register and compare the size    

  29.     LDR R3,[R0]    

  30.     CMP R3,R2    

  31.     MOVCC R7,R2; If the value of the following address is smaller than the previous one, swap their data    

  32.     MOVCC R2,R3    

  33.     MOVCC R3,R7    

  34.     STR R2,[R1] ; store data in the corresponding memory unit    

  35.     STR R3,[R0]    

  36.     CMP R6,#0 ; Check if each cycle ends    

  37.     BNE COMPARE    

  38.     ADD R1,R1,#4; After each loop, the initial memory address is moved back one unit.    

  39.     MOV R0,R1 ; Reinitialize the address stored in the register in the previous loop    

  40.     SUB R5,R5,#1; After each loop, the number of times in the following loops will be reduced by 1    

  41.     MOV R6,R5    

  42.     CMP R5,#0 ; Check if all loops are finished    

  43.     BNE COMPARE    

  44. DATA    

  45.     DCD 9,4,6,7,8,1,3,2,0,5    

  46. STOP    

  47.     B STOP   


C language code:


  1. #include     

  2. extern void strcopy(char *d, const char *s);    

  3. int main()    

  4. {    

  5.     const char *srcstr="abcdefghi";    

  6.     char dststr[]="ighfedcba";      

  7.     strcopy(dststr,srcstr);    

  8.     return 0;    

  9. }     


ARM assembly code:


  1. STACK_TOPEQU 0x40002000    

  2.     PRESERVE8    

  3.     AREA SCopy, CODE, READONLY    

  4.     EXPORT START    

  5.     EXPORT strcopy    

  6.     import main    

  7.     ENTRY    

  8. START    

  9.     LDR R13,=STACK_TOP    

  10.     B main    

  11. strcopy                    

  12.     LDRB r2, [r1], #1    

  13.     STRB r2, [r0], #1    

  14.     CMP r2, #0            

  15.     BNE strcopy            

  16.     MOV pc,lr          

  17.     END   


  1. stack_top equ0x40002000  

  2. PRESERVE8  

  3. export copy  

  4. AREA copy,CODE,READONLY  

  5. import copystr  

  6. export start  

  7. ENTRY  

  8. start  

  9. ldr r13,=stack_top  

  10. ldr r0,=src  

  11. ldr r1,=dst  

  12. BL copystr  

  13. src      

  14. dcb "abcdefghij"  

  15. dst  

  16. dcb "helloworld"  

  17. end  


  1. //C program  

  2. #include   

  3. void copystr(char *d,char *s)  

  4. {  

  5. while((*d++=*s++)!='');  

  6. }  


[1] [2]
Keywords:ARM Reference address:ARM Architecture and Programming Notes

Previous article:Programmers' Model of ARM Processor
Next article:Build and compile the Android 4.4.4 environment for the 4412 development board

Recommended ReadingLatest update time:2024-11-16 16:42

ARM's FIQ (Fast Interrupt) IRQ (Interrupt)
IRQ, FIQ definition: This is a normal interrupt. When our program defines this interrupt and an IRQ interrupt occurs when the program is running, the chip will run like this: the interrupt handler uses the IRQ request line to high-speed ARM, and ARM knows that an IRQ interrupt has come, and then ARM switches to IRQ mo
[Microcontroller]
Discussion on ARM JTAG Emulator Circuit
Introduction: The following is some of my experience in practice. I found this because I encountered problems when trying to use the programming board circuit suitable for SAMSUNG S3C44B0 JTAG to program another ARM9 core MPU S3C2440 of SAMSUNG. After consulting some information, I finally solved it. I hope this will
[Microcontroller]
Discussion on ARM JTAG Emulator Circuit
ARM hardware and software handling of exceptions
For IA32 (X86), when an exception is found, the CPU hardware does a lot of things, such as switching SP, CR3, CS, etc. (reading TSS), while for ARM, the processing flow is as follows CPU Hardware: 1 : Save the next instruction where the exception occurs to LR_xxx 2 : Back up the current CPSR to the SP
[Microcontroller]
ARM·System clock (MPLL, UPLL)
【programming】 The clock_int function is used to set the input clock frequency Fin of MPLL and 2440A to 12Mhz, and set FCLK, HCLK, and PCLK to 200MHz, 100MHz, and 50MHz respectively. Idea: Frequency division is 2 steps 1): Set MPLL (multiply 12MHz) 2): Set CLKDIVN (divide the MPLL frequency)        
[Microcontroller]
ARM boot process (Cortex-M3 NXP LPC1768 as an example)
1. Basic concepts (CMSIS): Cortex Micro-controller Software Interface Standard, microcontroller software interface standard.   2. CMSIS standard file structure: a) core_cm.c (stdint.h) b) system_.c (core_cm, system_) c) startup_.s   Among them, core_cm.c and core_cm are the kernel access layer, which defin
[Microcontroller]
Using Qt ARM cross-compilation prompts "This Qt version has an unknown tool chain"
In Tools- Options- Qt4 (the higher version of Qt is "Tools- Options- Compile and Run- Qt4"), when adding the ARM version of qmake, it prompts "This Qt version has an unknown tool chain" I encountered two situations where this was prompted. The first one is because QtCreator does not have permission to access the mks
[Microcontroller]
Design of fire information transmission gateway based on ARM
0 Preface Fire is a major form of urban disasters. It has increasingly become an important disaster that affects social and economic development and people's lives. At present, the main method used by cities to prevent fires is to install automatic fire alarm systems and their linkage fire-fighting devices in buildi
[Microcontroller]
Design of fire information transmission gateway based on ARM
Application of ARM processor LPC2210 in brain blood oxygen monitor
Oxygen is an important substance for human metabolism. Brain tissue has a high metabolic rate and consumes about 20% of the total oxygen in the body. In the clinical rescue and treatment of patients with cardiovascular and cerebrovascular diseases and brain trauma, if there is a lack of monitoring means for the oxyg
[Microcontroller]
Application of ARM processor LPC2210 in brain blood oxygen monitor
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号