0% found this document useful (0 votes)
28 views

Lab1 v1

The document provides instructions on creating a Keil uVision project for an ARM microcontroller. It discusses assembly language syntax, directives like AREA, THUMB, and ALIGN used to define sections and instructions. Data definition directives like DCB, DCD, DCW are described along with how to declare global symbols using EXPORT/IMPORT.

Uploaded by

Waqas Ahmed
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
28 views

Lab1 v1

The document provides instructions on creating a Keil uVision project for an ARM microcontroller. It discusses assembly language syntax, directives like AREA, THUMB, and ALIGN used to define sections and instructions. Data definition directives like DCB, DCD, DCW are described along with how to declare global symbols using EXPORT/IMPORT.

Uploaded by

Waqas Ahmed
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 8

Lab-I

Pre-requisite
Copy the files Demo.s and startup.s in a folder on your hard drive.
Creating a Keil Project
Launch the Keil µVision.
Go to Project Menu and click New µVision Project.

Browse to the folder where you want to save the project. Name the project and Save.
Select the device ARMCM3 for target and click ok.
Manage Run-Time Environment by selecting software component CMSIS CORE

In Project Window right click on Source Group 1, and click on Add Existing Files to Group Source
Group 1 and add Demo.s and startup.s files.
In Project Window right click on Target and click on Options for Target. In the popup window in
Device tab check the option Use MicroLib.

In the same Options for Target window click the Debug tab and opt the radio button Use
Simulator.

Click Ok.
From Project menu build the target. In case of successful build, go to debug menu and click start
debug session.
Observe the values of Registers and memory location(s). Note down the initial and updated values
of the registers and memory location(s).
Structure of Assembly Language Modules
Syntax of source lines in assembly language
The assembler parses and assembles assembly language to produce object code.
Syntax
Each line of assembly language source code has this general form:
{symbol} {instruction |directive |pseudo-instruction} {; comment}
All three sections of the source line are optional.
1. symbol is usually a label.
 In instructions and pseudo-instructions, it is always a label.
 In some directives it is a symbol for a variable or a constant. The description of the
directive makes this clear in each case.
symbol must begin in the first column. It cannot contain any white space character such as
a space or a tab unless it is enclosed by bars (|).
Labels are symbolic representations of addresses. You can use labels to mark specific
addresses that you want to refer to from other parts of the code. Numeric local labels are a
subclass of labels that begin with a number in the range 0-99. Unlike other labels, a numeric
local label can be defined many times. This makes them useful when generating labels with
a macro.
2. Directives provide important information to the assembler that either affects the assembly
process or affects the final output image.
3. Instructions and pseudo-instructions make up the code a processor uses to perform tasks.
Note:
Instructions, pseudo-instructions, and directives must be preceded by white space, such
as a space or a tab, irrespective of whether there is a preceding label or not.
Some directives do not allow the use of a label.
4. A comment is the final part of a source line. The first semicolon on a line marks the
5. beginning of a comment except where the semicolon appears inside a string literal. The
end of the line is the end of the comment. A comment alone is a valid line. The assembler
ignores all comments. You can use blank lines to make your code more readable.

About ARM and Thumb Mode


ARM and Thumb are two different instruction sets supported by ARM cores with a “T” in their
name. For instance, ARM7 TDMI supports Thumb mode. ARM instructions are 32 bits wide, and
Thumb instructions are 16 bits wide. Thumb mode allows for code to be smaller, and can
potentially be faster if the target has slow memory
THUMB Directive
The THUMB directive instructs the assembler to interpret subsequent instructions as T32
instructions, using the Unified Assembly Language (UAL) syntax.
In files that contain code using different instruction sets, the THUMB directive must precede T32
code written in UAL syntax.
If necessary, this directive also inserts one byte of padding to align to the next halfword boundary.
This directive does not assemble to any instructions. It also does not change the state. It only
instructs armasm to assemble T32 instructions as appropriate, and inserts padding if
necessary.
Unified Assembly Language (UAL)
Unified Assembler Language (UAL) is a common syntax for A32 and T32 instructions.
T32 instructions:
Most ARMv7-A (and earlier) implementations support two instruction sets, the 32-bit ARM
instruction and 32/16-bit Thumb instruction set.
ARMv8-A AArch32 continues to support these two instruction sets, but they are renamed as A32
and T32 respectively.
ARM architecture versions v4T and above define a 16-bit instruction set called the Thumb
instruction set. The functionality of the Thumb instruction set is a subset of the functionality of the
32-bit ARM instruction set.
A processor that is executing Thumb instructions is operating in Thumb state. A processor that
is executing ARM instructions is operating in ARM state.
A processor in ARM state cannot execute Thumb instructions, and a processor in Thumb
state cannot execute ARM instructions. You must ensure that the processor never receives
instructions of the wrong instruction set for the current state.
Each instruction set includes instructions to change processor state.

AREA Directive
Object files produced by the assembler are divided into sections. In assembly source code, you use
the AREA directive to mark the start of a section. It allows the programmer to specify the memory
location to store code and data.
Use the AREA directive to name the section and set its attributes. The attributes are placed after
the name, separated by commas.
You can choose any name for your sections. However, names starting with any non-alphabetic
character must be enclosed in bars, otherwise an AREA name missing error is generated. For
example, |1_DataArea|.
Example1:
AREA Mydata, DATA, READWRITE
Example2:
AREA |.text|, CODE, READONLY, ALIGN=2

Attributes of the AREA Directive

EXPORT and IMPORT Directives


A project may contain multiple source files. You may need to use a symbol in a source file that is
defined in another source file. In order for a symbol to be found by a different program file, we
need to declare that symbol name as a global variable. The EXPORT directive declares a symbol
that can be used in different program files. GLOBAL is a synonym for EXPORT. The IMPORT
directive provides the assembler with a name that is not defined in the current assembly.
ALIGN Directive
Use of ALIGN ensures that your code is correctly aligned. By default, the ALIGN directive aligns
the current location within the code to a word (4-byte) boundary. ALIGN 2 can also be used to
align on a halfword (2-byte) boundary in Thumb code. As a general rule it is safer to use ALIGN
frequently through your code.
Data Reservation Directives (DCB, DCD, DCW)
ARM assembler supports different data definition directives to insert constants in assembly code.
This directive allows the programmer to enter fixed data into the program memory and treats that
data as a permanent part of the program. Different variants of these directives are:
1. DCB (Define Constant Byte) to define constants of byte size.
2. DCW (Define Constant Word) allocates one or more halfwords of memory, aligned on
two-byte boundaries.
3. DCD (Define Constant Data) allocates one or more words of memory, aligned on four-byte
boundaries.
SPACE Directive
The SPACE directive reserves a zeroed block of memory. ALIGN directive must be used to align
any code following a SPACE directive.
Example

----------------------
Assignment
1. Write down step by step procedure of creating and debugging a Keil µVision project
including pre-requisites into your notebook. What project settings that are necessary in Keil
IDE to run a project using assembly language. (MicroLib and Use Simulator)
2. Write down the assembly code given in Demo.s into your note book and label the different
segments and mark different directives used in the code.
3. Draw a table which describes
a. the initial and updated values of Registers used in Demo.s.
b. names, addresses and initial (if any) and updated values of memory location
4. Write down the Data Types (DCW, DCD, DCB etc.) used in Assembly language and
number of bytes allocated for each type in a tabular format.
5. Write down the syntax that define 4 variables in the data memory using assembler
directives of
a. Byte wide
b. Half word wide
c. Word wide
d. Double word wide
6. Write down the addresses at which the variables defined in Q. 5 are stored in SRAM
(starting from 0x20000000)

-----------------------------------------

You might also like