Introduction to ARM Assembly Language and Keil uVision4

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 uVersion4 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


1.      In the lab room CL105, computers are running the operating
        system Windows 7 Enterprise, and ARM Software Microcontroller 
	Development Kit Version 4.71a (Keil uVision4) is installed. 

2.      To install it on your home computer, you can download the following file: 
~ftp/pub/class/301/ftp/mdk470a.exe 3. To know more about Keil, visit http://www.keil.com/ 4. To know more about the ARM Cortex-M family, visit http://www.arm.com/products/processors/cortex-m/index.php 5. To see STM32VLDISCOVERT board, visit STM32VLDISCOVERY Board. 6. To view Keil uVision4 Tutorials, check the following: Tutorial One Tutorial Two http://www.youtube.com/watch?v=zJncQKNDZv8

Create an ARM Assembly Language Program

To create an assembly language program, you need to use a text editor such as NotePad in Microsoft Windows environment. There is a text edit in the Keil uVision4 for you to use. The file name must have a .s at the end. Let's look at the following program called MyFirstArm.s on a PC. The file MyFirstArm.s contains the source code of the program to load registers and demonstrate a few other operations. We will use Keil uVision4 to create a project and execute this program so that you can get a feel of how Keil uVision4 works.


;The semicolon is used to lead an inline documentation
;This is the first ARM Assembly language program you see in the lab
;This program skeleton is from Dave Duguid and Trevor Douglas in summer 2013.
;When you write your program, you could have your info at the top document block
;For Example:  Your Name, Student Number, what the program is for, and what it does etc.

;;; Directives
          PRESERVE8
          THUMB       
 
; Vector Table Mapped to Address 0 at Reset
; Linker requires __Vectors to be exported
 
          AREA    RESET, DATA, READONLY
          EXPORT  __Vectors
 
__Vectors 
	  DCD  0x20001000     ; stack pointer value when stack is empty
          DCD  Reset_Handler  ; reset vector
  
          ALIGN
 
; The program
; Linker requires Reset_Handler
 
          AREA    MYCODE, CODE, READONLY
 
   	  ENTRY
   	  EXPORT Reset_Handler
 
 
Reset_Handler
;;;;;;;;;;User Code Starts from the next line;;;;;;;;;;;;

   	  MOV R0, #12
 
STOP  
	  ADD R0, R0, #4
   	  B  STOP
 
          END	;End of the program

References:
  1. A complete list of DIRECTIVES from ARM Information Center
  2. Cortex-M3 Devices Generic User Guide

Start up Keil uVision4

Before you start up, you are recommended that you create a folder to hold all your project files.
For example: you can have a folder "FirstARM-Project" ready before hand.

You can start up uVision4 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 firt ARM uVision4 project now. To create a project, click on the "Project" menu from the uVision4 screen and select "New uVision Project...".
 

Then, select a folder, give project a name and save.
 

From the "Select Device for Target" window, select "STMicroelectronics" as the vendor.

 

click on "+" beside "STMicroelectronics" and then select "STM32F100RB" and click on "OK".

 

Make sure you click on "NO" for the following pop up window.

 

Create Source File

From the "File" menu, select "New", you will see the "Text1*" 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.

 

Save the program by clicking on the "Save" or "Save As" from the "File" menu and give it a name.

 

Add Source File to the Project

Right click on the "Source Group 1", select "Add Files to Group 'Source Group 1'".

 

Select "Files of type" as "Asm Source file (*.s*;*.src*;*.a*), then select the file "FirstARM.s" for example.
Click on "Add", and then click on "Close".

 

Build your project

Click on the "+" besid the "Source Group 1", you will see the program "FirstARM.s".
Click on the "Build" button or from the "Project" menu, you will see the following screen.

 

Run the program in your project

The assembler is happy with the program. We can now run the program through "Debug" menu.

 
Click on "OK" for the pop up window showing "EVALUATION MODE, Running with Code Size Limit: 32K".

Open your uVision4 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.

 

Click on the "Start/Stop Debug Session" again to stop executing the program.

We will analyze the program and see how it works.
It works with both the simulated target and the real circuit board STM32VLDISCOVERY Board.
I will demonstrate it in the lab for you.

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.

Here is a diagram of the ARM architecture for your reference.

 

    ARM Architecture is an Enhanced RISC Architecture.
    It has large uniform Register file and uses Load Store Architecture.
       i.e. operations operate on registers and not in memory locations.

    ARM Architecture instructions are of uniform and fixed length.
    It is a 32 bit processor. 
    It also has 16 bit variant called THUMB. 
       i.e. it can be used as 32 bit and as 16 bit processor.
Here is the link with more info.

ARM cores are licensed to partners/manufacturers so as to develop and fabricate new microcontrollers around same processor cores. A microcontroller is a small computer on a single integrated circuit containing a processor core, memory, and programmable input/output peripherals. The ARM Cortex-M3 microcontroller will be used in the lab with the STM32VLDISCOVERT board.
For more information, visit STM32VLDISCOVERY Board.

Here is another link to the ARM Archicheture for your reference.

ARM Registers

Here is the Register Organization in ARM State.

 

Here is the Register Organization in THUMB State.

 

Here is the Program Status Register Format:

 


	In ARM State, there are 16 general purpose registers;  
		      one or more status registers are accessible at any one time.

	In  THUMB State, there are 8 general purpose registers; 
			 PC, SP, LR and CPSR are accessible.
 
	Conditonion code flags in CPSR:
	N - Negative or less than flag
	Z - Zero flag
	C - Carry or bowrrow or extendedflag
	V - Overflow flag

The links to Register Organization for your reference: reference one | reference two | reference three.

ARM Instructions

Here are a few sample ARM Instructions for you to test out for this lab:

 
	MOV 	R2, #0x76	
	; Move the 8-bit Hex number 76 to the low portion of R2

	MOV 	R2, #0x7654	
	; Move the 16-bit Hex number 7654 to the low portion of R2

	MOVT 	R2, #0x7654	
	; Move the 16-bit Hex number 7654 to the high portion of R2

	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

	ADD	R1, R2, R3		; R1 = R2 + R3
	
	ADDS 	R1, R2, R3		; R1 = R2 + R3, and FLAGs are updated

	SUB	R1, R2, R3		; R1 = R2 - R3

	SUBS	R1, R2, R3		; R1 = R2 - R3, and FLAGs are updated

	B	LABEL			; Branch to LABEL

ARM Reference Card by Dr. Gerhard

The ARM reference card will be available on exams. Please be sure to make yourself familiar with the layout of the card, and if there is anything missing that you think should be on the card, make sure to let Dr. Gerhard know so it can be included.

Lab Assignment

This page last modified:
Monday, 14-Feb-2022 13:46:36 CST
Accessed     times.

Copyright: Department of Computer Science, University of Regina.