Introduction To ARM Assembly Language and Keil Uvision5
Introduction To ARM Assembly Language and Keil Uvision5
The ARM (Advanced RISC Machine) architecture is introduced in the class (also see http://www.arm.com.) Keil MDK-
ARM is a complete software development toolkit for ARM processor-based microcontrollers. Keil uVision5 will be used
in the lab. The ARM Cortex-M3 processor will be examined with the STM32VLDISCOVERY board. The following is
some important information for you.
Important Information
2. To install it in your home computer, you can download the following files:
~ftp/pub/class/301/ftp/uVision5/MDK521a.EXE
~ftp/pub/class/301/ftp/uVision5/Keil.STM32F1xx_DFP.2.1.0.pack
5. To see The Cortex-M3 Instruction Set, visit Cortex-M3 Devices Generic User Guide.
1
6. To see more references of Cortex-M3, visit the following:
Cortex-M3 Technical Reference Manual - ARM Information Center
Cortex-M3 programming manual
;;; Directives
PRESERVE8
THUMB
__Vectors
DCD 0x20001000 ; stack pointer value when stack is empty
;The processor uses a full descending stack.
;This means the stack pointer holds the address of the last
;stacked item in memory. When the processor pushes a new item
;onto the stack, it decrements the stack pointer and then
;writes the item to the new memory location.
ALIGN
; The program
; Linker requires Reset_Handler
2
AREA MYCODE, CODE, READONLY
ENTRY
EXPORT Reset_Handler
Reset_Handler
;;;;;;;;;;User Code Starts from the next line;;;;;;;;;;;;
STOP
ADD R0, R0, #4
B STOP
References:
3
Here is the Program Status Register Format:
4
STM32F100xB Memory Map
STM32F100xB Memory Map
STM32F100RB Datasheet
5
You can start up uVision5 by clicking on the icon from the desktop or from the
"Start" menu or "All Programs" on a lab PC.
The following screen is what you will see.
Create a project
Let's create our first ARM uVision5 project now. To create a project, click on the "Project" menu from
the uVision5 screen and select "New uVision Project...".
6
Then, select the folder that you prepared for, give project a name and save it.
From the "Select Device for Target" window, select "STMicroelectronics" and then
"STM32F1 Series".
7
click on "+" beside "STM32F100" and then select "STM32F100RB" and click on "OK".
Make sure you click on "OK" for the following pop up window.
8
Create Source File and Add Source File to the Project
Right click on "Source Group 1" and then select "Add New Item to Group 'Source Group
1'...".
You will see the following window and make the suggested selections to proceed.
9
You will see the "FirstARM.s*" text edit window. That is the place you will write your ARM Assembly
language program. For a test, you can copy and paste the example program into this window. You
can click on the "save" buttom to save your project.
10
You can right click on "Target 1" and then select "options for Target 'Target 1'..." the same
as the following screen.
11
Build your project
Click on the "Build" button or from the "Project" menu, you will see the following screen.
12
Click on "OK" for the pop up window showing "EVALUATION MODE, Running with Code Size Limit:
32K".
Open your uVision5 to full screen to have a better and complete view. The left hand side window
shows you the registers and the right side window shows the program code. There are some other
windows open. You may adjust the size of them to see better.
Run the program step by step, you can observe the change of the values in the registers .
13
Click on the "Start/Stop Debug Session" from the "Debug" menu or click on the debug button to stop
executing the program.
14
ARM Architecture
ARM processors are mainly used for low-power and low cost applications such as mobile phones,
communication modems, automotive engine management systems, and hand-held digital systems.
15
The ARM Cortex-M3 microcontroller will be used in the lab with the STM32VLDISCOVERY board.
For more information, visit STM32VLDISCOVERY Board.
ARM Registers
Here is the Register Organization in ARM State.
16
Here is the Program Status Register Format:
MOV32 R2, #0x76543210 ; Move the 32-bit Hex number 76543210 to the R2
LDR R2, = 0x76543210 ; Load R2 with the 32-bit Hex number 76543210
The entire list of the Instructions can be found in the Cortex-M3 Devices Generic User
Guide.
OR see The Cortex-M3 Instruction Set in Cortex-M3 Devices Generic User Guide, in
Chapter 3: The Cortex-M3 Instruction Set.
18
Lab work:
ADD R1,R2,R3 ; R1 = ?
MOV32 R3, #0xFFFFFFFF ; R3 = ?
ADDS R1,R2,R3 ; R1 = ?
; specify Condition Code updates
SUBS R1,R2,R3 ; R1 = ?
; specify Condition Code updates
ADDS R1,R2,R4 ; R1 = ?
; Please specify Condition Code updates
; and now what happened to the flags in the CPSR?
ADDS R1,R2,R3 ; R1 = ?
; Check the flags in the CPSR?
20