Problems in Arm assembly
Arm assembler is similar to x86 assembler. Use ";" to comment. Such as start and loop. ENTRY indicates the start of the program, and END indicates the END. Of course, these two must be written in alignment.
The following describes the first arm assembler I wrote. It deserves to be a difficult problem.
I think this code can be viewed as a new handwriting. The Line "Stop B Stop". However, even such a line of code is hard to produce.
In the first arm assembly code, I did not add this line. After running the program directly, the following error occurs: Processor ARM7TDMI raised an exception. cause: Undefined instruction. When you run the command in a single step, the result is obtained. However, an error box will pop up at the end, and all the last columns in the box are Undefined. this problem is hard to understand. But now I understand.
Why is there such a problem?
In a multi-task operating system, a program is actually a task, which is scheduled by the system. Every task is actually executed cyclically. In embedded products, the program always performs one or more cycles, and the user stops running only when the power supply is disabled. In Windows, the program you designed does not require Loops because the development tool provides you with a default loop program instead of running it cyclically.
The program counter stores the address of your next instruction. The cpu constantly reads the instruction and decodes and executes the instruction. Then, the value is adjusted to the next instruction address of the executed instruction. If there is no loop, after the program ends, it will still read the next instruction. However, your program has been running and no commands have been defined for the program counter to read. In this way, a non-definition error occurs.
After knowing the cause, I thought of the simplest method. Since arm does not stop assembling it. Undefined will be reported if there is no next command, so I will let it loop. So we have the above Code. That is, results are not affected. No error is reported. However, after the actual operation, the program will not stop, like a crash. This makes me feel a little lacking.
I have read many examples in the installation files. Most of the final sections are found to be:
Stop mov r0, #0x18; angel_swireason_reportexception
LDR R1, = 0x20026; adp_stopped_applicationexit
SWI 0x123456
Since it is stop, I guess this should be the code that stops the program. The three lines are indeed stopping the program with interruptions. But the meaning of the specific Code cannot be said. Continue to find information. I finally asked the specific meaning in an arm technology group.
The stop segment is used to exit the program. The first statement "mov r0, #0x18" assigns R0 to 0x18, which corresponds to the macro angel_swireason_reportexception. Indicates the execution status stored in R1. Statement "LDR R1, = 0x20026" sets the value of R1 to adp_stopped_applicationexit. This macro indicates that the program Exits normally. Then run the SWI statement "SWI 0x123456" to end the program and return the CPU control to the debugger.
So far, an arm assembler is born.