Lab1 v1
Lab1 v1
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.
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
----------------------
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)
-----------------------------------------