# 汇编代做 | arm代写 | C代写 – ARM v7-M Assembly Language and C Programming

### assignment1 (Semester 1, AY2018/19) ARM v7-M Assembly Language and C Programming

I. Background Concepts

A function or subroutine can be programmed in assembly language and called from a C program. A well-written assembly language function usually executes faster than its C counterpart.

It is common in many engineering applications such as image processing and computer vision to do classification, which involves determining the class a given pattern comes from, e.g. determine from a photograph whether the person is male or female. In this case, there are 2 classes: male and female.

The performance of a classification method, for example a neural Networkpattern classifier, can be captured in a confusion matrix which indicates how many patterns, whose actual class is known, are correctly and wrongly classified.

In general, if we have classes, the x confusion matrix would look like:

##### 1 MM

where the element indicates the number of instances when patterns whose actual class is class have been classified as class . Hence, the number of instances when patterns from a particular class have been correctly classified are indicated by the diagonal element . The confusion matrix is always a square matrix.

One common performance metric of a classification method is the probability of detection PD for class , which is given by the formula:

PD=
##### M=1

For class m, PD gives the ratio of the number of patterns classified correctly as class m over the total number of patterns which are actually from class m.

Another common performance metric of a classification method is the probability of false alarm PFAm for class , which is given by the formula:

1,
1, 1
M
km
k km
m MM
kj
k k mj

=
==

1,
1, 1
M
km
k km
m MM
kj
k k mj

=
==

#### =

For class m, PFAm gives the ratio of the number of patterns classified as class m (excluding those actually from class m) over the total number of patterns which are not from class m. Note: k m means to skip the k=m case during the summation.

II. Objectives

The first objective of this assignment is to develop an ARMv7-M assembly language function pdm (CM,M,index) (where index=m- 1 ) to compute the probability of detection PD for class using the information in a given x confusion matrix CM. ( You may assume that 10 .)

The second objective of this assignment is to develop a C language function pfa(CM,M,index) (where index=m- 1 ) to compute the probability of false alarm PFAm for class using the information in a given x confusion matrix CM. (You may assume that 10 .)

III. Procedure

(a) Initial Configuration of Programs

The C program main.c in the projectEE2028Asmt1S1AY 2018 19 specifies a CM and the corresponding value. This program calls pdm(CM,M,index) repeatedly for different values of index.

Currently in main.c, = 3 and the CM is initialized with the following values:

##### 27 14 24

The elements of this matrix are stored row by row in consecutive words in memory in the manner shown in Table 1.

CM  0x10007FA8 0x0000003C CM element (1,1)
0x10007FAC 0x00000002 CM element (1,2)
0x10007FB0 0x00000003 CM element (1,3)
0x10007FB4 0x0000000B CM element ( 2 ,1)
0x10007FB8 0x0000002F CM element ( 2 ,2)
0x10007FBC 0x00000007 CM element ( 2 ,3)
0x10007FC0 0x0000001B CM element ( 3 ,1)
0x10007FC4 0x0000000E CM element (3,2)
0x10007FC8 0x00000018 CM element (3,3)
0x10007FCC : :

Table 1. Contents of consecutive memory locations containing elements of the confusion matrix CM for M=3. *Note: The actual memory addresses in your case may be different from those shown here.

Note: In C programs, the elements of each row and column of a square matrix are indexed from 0 to M-1, where M is the number of elements in each row and column. For pdm (CM,M,index), a ll the necessary operations must be done in the assembly language function.

(b) Preparations

After completing labSession 1, you should have the Lib_CMSISv1p30_LPC17xx project and several other projects, in the Project Explorer pane of the LPCXpresso IDE (LXIDE).

The Lib_CMSISv1p30_LPC17xx project contains the Cortex Microcontroller Software Interface Standard (CMSIS) files that will be explained later in lectures.

Import the EE2028Asmt1S1AY 2018 19.zip archive file which contains the EE2028Asmt1S1AY201819 project. Within the src folder of this project, there are 3 files:

• cr_startup_lpc17.c, which is part of the CMSIS and does not need to be modified;
• pdm.s, which presently does nothing and returns to the calling C program immediately – this is where you will write the assembly language instructions that implement the pdm() function; and
• main.c, which is a C program that calls the pdm() function with the appropriate parameters, scales down the returned results and prints out the results on the console pane. You will need to modify this file to implement the pfa() function and/or to modify the value of M and the confusion matrix.

Note: Parameter passing between C program and assembly language function:

In general, parameters can be passed between a C program and an assembly language
function through the ARM Cortex-M3 registers. In the following example:
extern int asm_fn(arg1, arg2, ...);
arg1 will be passed to the assembly language function asm_fn in the R0 register, arg2 will be
passed in the R1 register, and so on. The return value of the assembly language function can
be passed back to the C program through the R0 register.

(c) Procedure

Compile the EE2028Asmt1S1AY201819 project and execute the program. Explain the console window output that you see.

What is the address of the memory location containing element (1,1) of the CM matrix? How do you determine this?

Write the code for the assembly language function pdm() after reading the following sub-section (d) carefully. If you have implemented the function correctly, the console output should be:

Write the code for the C language function pfa(). If you have implemented the function correctly, the console output should be:

Note: the assembly language and C functions that you write should work for any value of M (set using #define in main.c) where 10. During the assessment for Assignment 1, the Graduate Assistant (GA) will modify the main.c program and specify a different value of M and another CM accordingly.

Note: You will describe you and your partners contributions towards the outcomes of this assignment through IVLE. More details will be provided later.

Show the assembly language and C language programs and actual console output to the Graduate Assistant (GA) during the assessment session (in Week 6). See Section IV below.

(d) Assembly Language function

You are required to write the assembly language code for the function pdm() that computes the probability of detection PDm for class m whose formula is shown in Section I.

The assembly language program only needs to deal with integers. Note that the value returned by the pdm() is scaled down by a factor of 10,000 in main.c to arrive at the final PDm value before it is printed out.

Write the ARM v7-M assembly language instructions that first determine the address of the memory location containing the requested data value before loading the data value from that memory location to a designated register.

For execution efficiency, do not use any subroutine in the assembly language function.

What else can be done to enhance the computation and/or storage efficiency of your programs?

There are several aspects that you need to pay attention to:

• It is a good practice to push the contents in the affected general purpose registers onto the stack upon entry into the assembly language function, and to pop those values at the end of the assembly language function, just before returning to the calling main program.
• If a set of actions are conditional, you may use the ARM assembly language IF-THEN (IT) block feature.
• In a RISC processor such as the ARM, arithmetic and logical operations only operate on values in registers. However, there are only a limited number of general purpose registers, and programs, e.g. complex mathematical functions, may have many variables. Try to use and reuse the registers in a systematic way.
• The printf() function enables output from the C program running on the LPC1769 to appear on the console window within the LXIDE. However, note that the operation of printf() and data transfer speed to the console window of the LXIDE are slow compared the general execution speed of other C and assembly language instructions.

IV. Assessment (Week 6)

For each group of 2 students:

Write a short report of about 3 pages long to answer the questions raised in Section III (c) above and explain how your assembly language and C programs work.

Write your names and matriculation numbers, and the name of Graduate Assistant (GA) supervising or assessing your group, clearly on the top left corner of the first page of your report.

Bring a hardcopy of your report when you attend the assessment session and hand it up to the GA assessing your group. Show the execution of your programs and the console output from the programs and explain how your programs work.

Note: your programs will be copied onto the lab PC at the start of your assessment session. It will be compiled and tested on the lab PC.

The GA will modify your program slightly, e.g. specify a different value of M and initialize another CM accordingly, to assess whether the correct PDm and PFAm values in that case can be obtained.

The assessing GA(s) will ask each student some questions in turn during the assessment. Both students need to be familiar with all aspects of the assignment and your solution as the GA can choose any one of you to explain any part of the assignment. The GA will also ask you additional questions to test your understanding.

You will also need to fill up a statement of contributions on the IVLE, clearly stating the contributions of each group member towards the assignment. Instructions on how to do this will be sent to you by e- mail in due course.