ELEC211 Introduction to the ARM Microprocessor 2022
Hello, dear friend, you can consult us at any time if you have any questions, add WeChat: daixieit
ELEC211
Introduction to the ARM Microprocessor
3. Introduction
The ARM Cortex M0 microprocessor is a modern 32-bit processor designed by a British company, ARM Holdings PLC, based in Cambridge. The major advantage of an ARM processor is its low power consumption. This makes it the ideal choice for battery-powered devices which require digital computation. For example, the great majority of all modern digital mobile phones use an ARM processor. The ARM microprocessor is manufactured by most semiconductor companies under licence; the one used in this experiment is made by Freescale (formerly called Motorola). The purpose ofthis experiment is to become familiar with the ARM Cortex M0 microprocessor, and this will be achieved by examining the operation of simple computer programs that have already been written. This experiment will help you on being more familiar with the assembly language and see practically how the ARM microprocessor works. This will also help you to recall how simple instructions work, arithmetic and logic operations, including negative numbers, branches, flags and conditional executions.
This experiment is based upon the Freescale integrated circuit, KL46Z256, containing the ARM Cortex M0 processor which is mounted on a printed circuit board known as the Freescale Freedom FRDM-KL46Z. This development board is connected to a host computer so that programs can be prepared on the PC and downloaded and executed (or run) on the ARM processor. In this experiment, you will use the Keil uVision environment for writing code and debugging. The Keil uVision software is a professional package used in industry and can be used to link C and C++ programs with assembly language programs. The Keil uVision debugger is a powerful tool for finding bugs in programs and is useful for investigating the characteristics of the ARM Cortex M0 microprocessor.
4. Getting started
During the on-campus lab session, the Freescale Freedom FRDM-KL46Z board will be used. This development board can be connected to a host computer (e.g. MWS PC) so that programs can be prepared on the PC and downloaded and executed (or run) on the ARM processor. The Freedom board can also be connected to other boards, commonly called ‘shields’, through a header that is Arduino compatible. One of these boards is the MBED shield. The Freescale Freedom board connects to a PC as a serial device over the USB connection. In this section you are going to make the board ready to be used for the experiment. Power on an MWS PC and log in into it by using your university credentials. Connect the MWS PC to the Freescale Freedom board using the OpenSDA USB connection as shown in Figure 1. The board should
be mapped by Windows as a new USB drive called “DAPLINK”. Check that the DAPLINK drive is present by using File Explorer.
User Switch SW1
Light sensor LED2 (red)
Arduino I/O header J1 LED1 (green)
Cortex M0+
Arduino I/O header J2
Capacitive touch slider
User Switch SW3
4 digit segment LCD display
Arduino I/O header J4 Arduino I/O header J3 Magnetometer
Accelerometer
KL46 USB
RESET switch
Status LED
OpenSDA USB (CMSIS-DAP USB)
Figure 1: Freescale Freedom development board.
Find the ‘Exp 26 (ARM microprocessor) - Demo code.zip’ file on Canvas for your module (ELEC222, ELEC224 or ELEC273) by using the browser in the MWS PC. Save the zip file to a location of your choice, then open it, extract it and place the program directory at a suitable location. Open the directory and double click on the “uvprojx” file to start Keil uVision. This will launch the ‘Exp 26 (ARM microprocessor) - Demo code’ project.
5. Assembly language program
The ‘Exp 26 (ARM microprocessor) - Demo code’ project has two source files, ‘main.c’ written in the C programming language and ‘exp26_asm.s’ written in assembly language or ‘mnemonics’. Other files under “RTE\Device” are used by the Keil uVision environment to work with the “FRDM-KL46Z” board based on the ARM Cortex M0+ microprocessor. Take a look at the C language program in the Keil uVision environment by double-clicking on “main.c” in the “Project” window. Move the cursor to the line of the main function (line 14)
and insert, if not present, a breakpoint by pressing F9. This can also be done by selecting
‘Insert/Remove Breakpoint’ from the ‘Debug’ drop-down menu or by clicking on the icon
in the toolbar. Take a look at the assembly language program in the Keil uVision environment by double-clicking on “exp26_ams.s” in the “Project” window.
To run the program on the board you need to carefully follow these steps:
1) In the Keil uVision environment, right-click on ‘frdm kl46z’ in the ‘Project’ window and select ‘Options for Target’. Click on the ‘Target’ tab and then select from the drop- down menu ‘ARM Compiler’ on the right the ‘Use default compiler version 6’ compiler version. Click on the ‘Linker’ tab and select the radio button ‘Use Memory Layout from Target Dialog’. Click on the ‘Utilities’ tab on the far right and then click on the ‘Settings’ button. A new window entitled ‘CMSIS-DAP Cortex-M Target Driver Setup’ should appear. Make sure that in the dialog “Programming Algorithm” the ‘MKXX 48Mhz 256kB Prog Flash’ is present, ifnot, click on the ‘Add’ button and from the list select ‘MKXX 48Mhz 256kB Prog Flash’. Click on ‘Add’ to close the window and then ‘OK’ once to close another window. Now, in the ‘Options for Target’ window, click on the ‘Debug’ tab. The radio button next to ‘Use’ should be selected (i.e. not the radio button next to ‘Use Simulator’) and ‘CMSIS-DAP Debugger’ should be showing in the adjoining box. If it is not, then select it from the drop-down list. Finally click on ‘OK’ to close the ‘Options for Target’ window.
2) Then build the project by selecting ‘Build target’ in the ‘Project’ drop-down menu. F7 can also be used. Then you need to download the program to the Freescale Freedom board by selecting ‘Download’ in the ‘Flash’ drop down menu. F8 can also be used.
3) Start debugging the program in the debug window by selecting ‘Start/Stop Debug Session’ in the ‘Debug’ drop-down menu. Control-F5 can also be used.
The two important windows in the debugger view are the ‘Disassembly’ window and the ‘Registers’ window, as shown in Figure 2. In the ‘Disassembly’ window, there are 4 columns which, from left to right, represent (i) the memory address (note that it increments by 2 or occasionally 4), (ii) the machine code – normally 4 hexadecimal digits but occasionally 8 hex digits, (iii) the mnemonic of the instruction and (iv) the operands of the instruction – either registers or immediates or both. In the ‘Registers’ window there should be a list of 17 registers (R0 to R15 and the xPSR, ‘program status register’) and the 4 byte value that is held in each register. Click on the next to the xPSR, and you should see the flags (N, Z, C and V) and their state (1 for set, 0 for clear).
Figure 2: ‘Registers’ and ‘Disassembly’ windows.
6. Initial Address (IA)
You should see the yellow arrow pointing to the same instruction (a PUSH) of the corresponding breakpoint in the C program, ‘main.c’ . This instruction is highlighted in the ‘Disassembly’ window, as shown in Figure 3 (in this example at memory address 0x00000238). Executing instructions by pressing F5 is known as ‘Run’, and it allows you to
continue executing the program until the next active breakpoint is reached. This can also be
executed by selecting ‘Run’ from the ‘Debug’ drop-down menu or by clicking on the icon
in the toolbar.
Figure 3: Example of PUSH instruction at address 0x00000238.
The next instruction to be executed by the microprocessor is shown by a yellow arrow, and this points to the first instruction in the C program, ‘main.c’ . Press F11 (single stepping) once and the yellow arrow moves to the ‘for’ instruction, you have just executed the first few instructions. Before you press F11 again, see if you can predict which registers will change in value and what the new values will be before the “CMP” instruction is executed. Press F11 again, and the instructions on lines 15, 16 and 17 are executed. In the C program, the next instruction to be executed is the ‘for()’ instruction and in the ‘Disassembly’ window, the equivalent mnemonic is ‘CMP r5, #0x00’ (in this example at memory address 0x00000240). In the ‘Registers’
window, the value held by register R5 is 0x0000000F as the block of code is repeatedly executed until the conditional expression is true ‘i<15’ .
Now press F11 twice until the ‘Disassembly’ window jumps to the assembly language program, ‘exp26_asm.s’, highlighting the first instruction ‘ADDS r7, r0, r1’ as shown in Figure 4 (in this example at memory address 0x00000258). This memory address will be called from now on Initial Address (IA) and will be used as a reference memory address. It is important to note that the IA may vary depending on the board used. Therefore, only in this example, the IA is equal to the memory address 0x00000258.
Figure 4: ‘Disassembly’ windows for the ‘exp26_asm.s’ .
Table 1 shows the main addresses used in this example. You need to calculate them depending on your IA. This will help you to quickly find and execute instructions.
Table 1: main addresses used in this example.
Address |
Resulting address (in this example) |
Address |
Resulting address (in this example) |
IA |
0x00000258 |
IA+0x50 |
0x000002A8 |
IA+0x6 |
0x0000025E |
IA+0x54 |
0x000002AC |
IA+0x12 |
0x0000026A |
IA+0x60 |
0x000002B8 |
IA+0x1C |
0x00000274 |
IA+0x62 |
0x000002BA |
IA+0x2C |
0x00000284 |
IA+0x64 |
0x000002BC |
IA+0x30 |
0x00000288 |
IA+0x68 |
0x000002C0 |
IA+0x32 |
0x0000028A |
IA+0x6C |
0x000002C4 |
IA+0x3A |
0x00000292 |
IA+0x7E |
0x000002D6 |
IA+0x44 |
0x0000029C |
IA+0x82 |
0x000002DA |
IA+0x46 |
0x0000029E |
IA+0x84 |
0x000002DC |
The main C program has ‘called’ the assembly language program and has passed two parameters, j and k, using registers r0 and r1 by convention.
Single step the next 3 instructions and notice that registers R2 and R3 hold the values 0x0000000E and 0x00000025 respectively. These values were moved into the registers by executing the first two MOVS instructions of the assembly program. Also, notice that the program counter, R15 or PC, increments by 2 as each instruction is executed. Look at the machine code for the first two MOVS instructions shown in the disassembly window.
Q1. Which part of the machine code identifies the register used? |
Q2. Which part of the machine code gives the number to be moved into that register? |
Write the answers to all questions in your notebook. You will need these answers at the end of the lab to complete the test sheet using the submission template available on Canvas.
7. Arithmetic Operations
Single step the instruction at address 0x0000025E and note the contents of R4.
Q3. What is this equal to? |
Continue single stepping until you reach address IA+0x12 (in this example address 0x0000026A). Note the contents of the registers after each instruction and work out what each instruction does.
Q4. Is the order of the registers in the mnemonics important? Why? |
Note that negative numbers are given in 2's complement format. For example, to find the 2's complement format for - 1,045,387,88310 first convert +1,045,387,88310 to hexadecimal which gives 0x3E4F5A6B. Then convert each digit to its 1's complement equivalent using the following hexadecimal inversion table.
Original digit |
0 |
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
A |
B |
C |
D |
E |
F |
Inverted digit (1's complement) |
F |
E |
D |
C |
B |
A |
9 |
8 |
7 |
6 |
5 |
4 |
3 |
2 |
1 |
0 |
So the 1's complement of - 1,045,387,88310 is 0xC1B0A594. Next, add 1 to find the 2's complement so the 2's complement format for - 1,045,387,88310 is 0xC1B0A595. You can easily check this using the Windows calculator in the “Programmer” view.
Next, we want to run the program again, but with different values in registers R2 and R3. In the ‘Registers’ window, double left click on the contents of R2 - this will allow you to modify the contents of the register - change it to 0x00000064. Similarly, change R3 to 0x0000000A and change the contents of the program counter to IA+0x6 (in this example to 0x0000025E). Now single step the program from address IA+0x6 (in this example address 0x0000025E) to address IA+0x12 (in this example address 0x0000026A). Make a note of the contents ofthe registers.
2022-05-13