Professional Documents
Culture Documents
Laboratory Sheet 3:
1.0 Introduction
This laboratory aims to provide an introduction to writing assembly language
programs. A good introduction to ARM assembly language programming is available
in chapter 3 of the course text [1] and Keil help documents [2,3]. For most
applications it is more appropriate to program in a high-level language such as C or
C++ but occasionally (e.g. for time critical sections of code) the programmer might
need the extra level of control afforded by assembly language. Assembly language
allows the target to be programmed at the lowest level since there is a 1:1 relationship
between assembly language instructions and machine code (as opposed to the many:1
relationship that exists for a high level language). Assembly language programmers
must be familiar with the programmer’s model for the machine they are targeting [4]
so it is an excellent way of learning about the machine’s architecture.
2.0 Objective
3.0 Procedure
Create a new project named asmBlinky (or a copy of myBlinky) and rebuild the
application you created in Lab 1.
/* Function Prototypes */
extern void wait(void);
value = delay;
while(value > 0)
value = value-1;
The programmer must decide which registers are used to store variables and
constants and which assembly language instructions to use. This sounds daunting
but it’s easy to learn by looking at a few example assembly language programs
[2].
Modify the assembly language subroutine so the delay produced depends on the
value of an input parameter i.e.
/* Function Prototypes */
void wait(unsigned long value);
Calls between separately assembled or compiled modules must comply with the
restrictions and conventions defined by the procedure call standard. See the
Procedure Call Standard for the ARM Architecture specification on the ARM
website for more information. For this exercise it’s sufficient for you to know
that parameters are passed using the register block, starting with R0, so your
assembly language subroutine can expect R0 to contain the delay value.
4.0 References
[1] D. Lewis, Fundamentals of Embedded Software with the ARM Cortex-M3 (2e),
Pearson, 2013.
[2] Keil, RealView Assembler User Guide, Rev. B, 2008.
[3] Keil, ARM InstructionSet User’s Guide, 2004.
[4] ST Microelectronics, STM32F10xxx Cortex-M3 programming manual,
http://www2.cmp.uea.ac.uk/~mhf/embedded/resources/15491.pdf (accessed Sept.
2013).
Appendix B
/**************************************************************/
/* asmBlinky: Very Simple LED Flasher with ASM subroutine */
/**************************************************************/
/* waitA() provides a fixed delay - hard coded in assembler */
/* waitB() provides a variable delay set by a passed param. */
/* */
/* Dr. Mark Fisher, CMP, UEA, Norwich, UK. */
/* Last updated 30.06.10 */
/**************************************************************/
#include <stm32f10x_cl.h>
/* Function Prototypes */
void waitA(void);
void waitB(unsigned long value );
SystemInit();