Lessons on byte alignment in learning about ARM undefined instruction exceptions

Publisher:HarmoniousCharmLatest update time:2021-09-28 Source: eefocusKeywords:ARM Reading articles on mobile phones Scan QR code
Read articles on your mobile phone anytime, anywhere

Today, I learned the course of undefined instruction exception of jz2440 development board. After following teacher Wei Dongshan to write code, compile and burn, the program teacher could not run normally. After careful investigation, it was found that the byte was not aligned to 4 bytes. The start.S file in the previous program started as follows:


_start:

/* Disable watchdog */

ldr r0, =0x53000000

ldr r1, =0

  str r1, [r0]


The instructions are aligned to 4 bytes from the beginning, so there is no problem running the program. But when the undefined instruction exception handling statement is added after the _start label, the code is as follows:


_start:

     b reset

     b do_and

 

 do_and:

     ldr sp, =0x34000000

 

     stmdb sp!, {r0-r12, lr}

     mrs r0, cpsr

     ldr r1, =and_string

     bl printException

  

     ldmia sp!, {r0-r12, pc}^

 

  and_string:

     .string "underdefined instruction exception"

     

 .align 4                                                                     

 reset:

     /* Disable watchdog */

     ldr r0, =0x53000000

     ldr r1, =0

     str r1, [r0]


If you do not add the .align 4 statement before the reset label, the address of the compiled reset segment code will be 0x300000043, which is not 4-byte aligned, so the program cannot jump and execute normally after startup.

Keywords:ARM Reference address:Lessons on byte alignment in learning about ARM undefined instruction exceptions

Previous article:Exception handling in Arm64
Next article:Analysis of ARM's exception handling process (exception vector/working mode)

Recommended ReadingLatest update time:2024-11-23 08:34

Design of Tax Control Cash Register System Based on ARM Controller LPC2214
introduction Tax control cash register refers to an electronic cash register with specific tax control functions. It is an embedded system integrating hardware and software. The hardware design considers high cost performance and high reliability, and the software design considers the stability and relia
[Microcontroller]
Design of Tax Control Cash Register System Based on ARM Controller LPC2214
Understanding of ADR instructions
When I was reading the assembly code of ARM before, I came across the adr instruction. I checked the instruction manual of ARM, and it only said that the instruction uses a relative address, but there was no specific explanation on how to understand this relative address. After that, I searched the Internet with the ad
[Microcontroller]
Illustrated explanation of the basic usage of Keil uvison 4 for ARM
I remember that I spent a lot of time to build a Keil project a long time ago. Here I will write down the basic Keil project creation method to prevent myself from forgetting it in the future: New Construction Save the project Select Device Create a new folder here, and then add the program code
[Microcontroller]
Illustrated explanation of the basic usage of Keil uvison 4 for ARM
ARM assembly instructions detailed explanation 1
RealView Developer Suite (RVDS) is a new generation of ARM integrated development tools (the previous generation is ADS) launched by ARM. It supports all ARM series cores and cooperates with many third-party real-time operating systems and tool vendors to simplify the development process. It includes the following comp
[Microcontroller]
ARM assembly instructions detailed explanation 1
ARM Learning Memory Management Unit (MMU)
I learned a lot of knowledge today while studying MMU. I have summarized it as follows, firstly to deepen my impression and secondly to write it down in the hope that I can exchange and learn with you. 1. What is MMU?  Answer: MMU is a memory management unit. If MMU is turned on, it will convert the virtual address se
[Microcontroller]
ARM LPC2132 Flowing Light LCD1602
1. Assembler GPADIR             EQU            0xE0028008 GPASET            EQU            0xE0028004 GPACLR            EQU            0xE002800C                         EXPORT xmain                         AREA    Init,CODE,READONLY                         ENTRY xmain                         ldr r0,=GPADIR  
[Microcontroller]
ARM LPC2132 Flowing Light LCD1602
Install ARM cross-compilation tools under Ubuntu
1. Add a source to our /etc/apt/sources.list so that we can sudo apt-get install gcc-armxxx; Source address: deb http://www.emdebian.org/debian/ stable main Add the above address to our /etc/apt/sources.list; Manually add deb http://www.emdebian.org/debian/ stable main to /etc/apt/sources.list. The permissions of
[Microcontroller]
Understanding of ARM load and run-time addresses
Just understanding it this way makes sense for some processes, and it is consistent with what is said in some materials. The download address and runtime address in the scatter file are used in the compilation and linking stages. For example, there is the following scatter file, taking the jump from assembly to c f
[Microcontroller]
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号