Lab 2 - Program - in - Assembly
Lab 2 - Program - in - Assembly
Objectives:
Introduction
To study the basic instructions in ARM is a good way to understand the ARM architecture.
Some basic instruction categories are covered in the lectures. However, the rich and detailed
information on ARM instructions can be found in MicroVision Help Manual and the reference
manual, Cortex-M4 Programming Manual (PM0214).
The ARM and Thumb Instruction summary is especially useful. It lists all the ARM Thumb
instructions. You don’t have to understand all of them, but for the basic categories, you are
expected to know them. A detailed explanation can be found for each instruction in the
manuals. You can also use search to find the explanation of any particular instruction you
want to know. With aid of the sample program in Lab 1 and the resources mentioned above,
you shall be able to do simple assembly programming. In this lab practice, you are required
to write some codes to perform some simple tasks.
Preliminary
Each laboratory contains some preliminary questions. These will involve reading part of the
references and answering questions. The objective is to have students prepare some material
that will assist in performing the laboratory procedure. These questions do not involve copying
quantities of information from references but rather a summary to demonstrate your
understanding.
a) Give a sample instruction for each of the following actions. Provide explanation for the
instruction.
0x81,0x72,0x83,0x74,0x85,0x76,0x87,0x78
Your answers will be useful for you to check your program later
References
1. Lecture Notes week1-3
2. Tutorial 1-3
3. Instructions set under Microvision Help manual
4. Cortex-M4 Programming Manual
5. Lab1 sample program
Tasks
In this laboratory exercise, you are required to write assembly codes to perform a series of
small tasks. A skeleton of the program is provided and it can be found in the appendix of this
document.
Task1: copy the data array from Array 1 in ROM to Array 2 in RAM .
Task 2: Write a subroutine to swap two 8 bit unsigned numbers in memory only if the first
number is larger than the second one
The detailed requirements of these tasks can be found in the skeleton program
You better do the task one by one. Don’t try to finish all the codes and pray all will work.
Procedure
1. Start a new project in the Keil development environment. The Keil start up code is not
required. Save the project as Lab02. Create the sample program Lab02.s given in the
appendix.
2. Start to code the tasks one by one. Go though the code – debug cycle till it works.
Then move on to next task. Task 2 and 3 can be combined for debugging.
3. Record the memory locations for Array1, Array2 and Stack ( Initial top and size)
4. With multiple memory windows, you can easily check if your tasks are correctly
completed. Take screen snapshot should be included in your reports to demonstrate
the results.
Questions
1. ARM has instructions for multiple data transfer between registers and memory block.
Give an example of such instructions.
2. What is the limit for the number of layers of nested subroutines? [ Note: For two
layers, it means inside subroutine 1 there is call to subroutine 2. For three layers, it
means inside subroutine 1, there is at least one call to subroutine2. Inside subroutine
2, there is at least one call to subroutine 3. So on so forth. ]
3. In your subroutine, r3 and r4 are kept in the stack. If there is a nested subroutine call
in your subroutine, how your stack operations shall be modified? Justify your
modification.
4. Task 8 is the hardest one among all of them. If you have completed it, elaborate your
experience . If you have no time to finish it, describe the challenges and your partial
work if you have tried it.
Report
As well as summarising what you did and answering the questions your report should highlight
any challenges the laboratory presented and how you overcame these. Consider you are writing
a laboratory guide for other students. Attempt to document something to assist them with any
problems you perceive they might have..
Looking ahead
For first and second laboratories, assembly language is used. Assembly language is helpful on
understanding the architecture of the microcontroller. However, Assembly is not efficient
language for development. In laboratory 3, Programming ARM microcontroller by C will be
introduced.
Appendix: Lab2 Assembly Program Skeleton
=====================================
; "Lab2.s" by J Wang 2020
; 2. farmiliarize with
; Stack operations
; Subroutines
; Task1
EXPORT __Vectors
__Vectors
DCD 0
DCD Reset_Handler
EXPORT Reset_Handler
Reset_Handler PROC
; *** Task1: copy the data array from Array 1 in ROM to Array 2 in RAM ***
; This is for advanced students. you can get full marks for this lab only if you can do this one)
ENDP
; Task 2 Write a subroutine to swap two 8 bit unsigned numbers in memory only if the first number is
larger than the second one
Swap2U PROC
ENDP
AREA Table1, DATA, READONLY
Init_S_Top DCB 0x88 ; this serve as the initial top of the stack
END