Step-by-Step learning for compiling the ARM7 program using ads

Source: Internet
Author: User

First, create a project and start ads-> codewarrior
File-> New-> Project-> arm executable image select the project directory to create the *. MCP project file
Next, create a file like VC. Here the file. S (ASM Assembly file). C (Standard C). cpp (C ++ file)
Note that different files call different compilers, so pay attention to the file suffix.
Create an init. s entry. all calls to the initial file will be taken from this file entry.
File-> New-> file-> textfile select the directory to create the file init. s
Below is the code (I have simplified it)

Import main // note that the command line cannot be the top level. Otherwise, the compilation does not recognize the operation code and the import function is similar to the include concept.
Area init, code, readonly // This is the macro assembly syntax that indicates the code segment name and attribute readonly
Entry // ENTRY macro

LDR R13, = 0x8000 // define sp

B Main // jump to main to start operations under the official c file

End // end macro


Create a testlib. s library to test lib and write a strcpy function.

Export strcpy // The function name in the exported Lib is similar to the extern or public function.
 
Area testlib, code, readonly // same as above


Strcpy // The number definition must be the top
Ldrb R2, [R1, #0] // The strcpy process is implemented below
CMP R2, #0
Beq cpy_end
Add R1, R1, #1
Strb R2, [R0], #1
B strcpy

Cpy_end
MoV r0, #1
MoV PC, R14 // implementation ends

End

Similarly, create the main c file of Main. C.
Write code
Int main () // do you see the main? different from standard C, you can customize the entry.
{
Char Buf [10] = {0}; // same as writing in Standard C, but all database functions must be implemented by themselves, not strcpy.
// For hardware such as printf and serial port
Char x pstr = "123456789 ";
Strcpy (BUF, pstr); // call

Return 1;
 
}

The entire process is complete. You can compile and run it. Use axd to enter the debugging stage.

Introduction to ACPs
APCs and arm procedure call standard (arm procedure call standard) provide a compact mechanism for compiling routines. defined routines can be intertwined with other routines. The most significant difference is that there is no clear limit on where these routines come from. They can be compiled from C, Pascal, or in assembly language.
APCs defines:

Limits on the use of registers.
Stack conventions.
Pass/return parameters between function calls.
Stack-based structure format that can be traced back to provide a list of functions (and parameters) from the failure point to the program entry.
APCs Standard
In general, there are multiple versions of APCs (actually 16 ). We only care about what we may encounter on the risc OS.
APCS-A
That is, APCs-Arthur, defined by the early Arthur. It has been deprecated because it has different register definitions (it is a kind of heterogeneous for skilled Proteus OS programmers ). It is used to run Arthur applications in USR mode. It should not be used.

SL = R13, FP = R10, IP = R11, SP = R12, LR = R14, Pc = R15.
PRM (p4-411) said "the use of R12 as SP, rather than the more natural R13 in the system, is historic and prior to Arthur and the risc OS ."
Stack is segmented and scalable as needed.
26-bit program counter.
Do not pass floating-point arguments in the FP register.
Reentrant is not allowed. The flag must be restored.
APCS-R
Is the APCS-RISC OS. It is used for operations by a proteus OS application in USR mode or a module/handler in SVC mode.

SL = R10, FP = R11, IP = R12, SP = R13, LR = R14, Pc = R15.
It is the only and most common APCs version. Because all compiled C programs use APCs-R.
Explicit stack restriction check.
26-bit program counter.
Do not pass floating-point arguments in the FP register.
Reentrant is not allowed. The flag must be restored.
APCS-U
Is APCs-Unix, which is used by riscix of acorn. It is used for riscix applications (USR mode) or kernels (SVC mode ).

SL = R10, FP = R11, IP = R12, SP = R13, LR = R14, Pc = R15.
Implicit stack restriction check (using SL ).
26-bit program counter.
Do not pass floating-point arguments in the FP register.
Reentrant is not allowed. The flag must be restored.
APCS-32
It is an extension of the APCS-2 (-R and-u) that allows 32-bit program counters and exits from a function executed in USR mode, the flag is not restored. Other things are the same as APCs-R.
Acorn C version 5 supports 32-bit code generation. Among the 32-bit tools used for wide-area debugging, it is the most complete development release. A simple test requires your compiler to export the Assembly source code (instead of making the target code ). You should not find:
Movs PC, R14
Or
Ldmfd R13 !, {RX-X, PC}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.