Professional Documents
Culture Documents
LECTURE 4 - ECE521 - MP Assembly Language
LECTURE 4 - ECE521 - MP Assembly Language
LECTURE 4 - ECE521 - MP Assembly Language
Microprocessor System
Microprocessor Assembly Language Programming
What we will learn in this section:
myfile.asm
Assembler Program
Linker
Downloaded to
myfile.map myfile.hex the
Program Memory
2. source file containing the program code created in step 1 is fed to the ARM assembler
3. The assembler converts the asm file’s Assembly language instructions into machine
language and provides the object file (.o) and a listing file (.lst).
❑ The object file has an “o” as its extension. The object file is used as input to a
simulator.
❑ The list file has “. lst” extension ,which is very useful to the programmer. The list shows
the binary and source code; it also shows which instructions are used in the source
code, and the amount of memory the program uses.
4. The object file plus a linker script file are used by the linker to produce the map file which
has the extension “. map” and the memory image files.
Creating an ARM Assembly Program (cont..)
4. The memory image file contains the binary code that can be
downloaded to the target device or the simulator for execution
By default, Keil IDE produces a “. axf” file that contains the binary code and
the symbols for debugger
Optionally, a hex format file which has “. hex” extension may be produced
The linker script file (or scatter file in Keil) is optional and can be replaced by
some command line options
After a successful link, the hex file is ready to be burned into the ARM
processor’s program FLASH memory and is downloaded into the ARM chip
More about asm and object files
before a program can be assembled, it must be free of syntax errors
Keil uVision IDE provides error messages to show the location and nature
of the syntax error
assembler will not assemble the program until all the syntax errors are
fixed
sample of an error message is shown in Figure 3-2
; ARM Assembly language program to add some data and store the SUM in R3.
AREA PROG_3-1, CODE, READONLY
ENTRY
EXPORT main
main
MOV R1, #0x25 ; R1 = 0x25
MOV R2, #0x34 ; R2 = 0x34
ADD R3, R2, R1 ; R3 = R2 + R1
HERE B HERE
END
Map files
Example:
EXPORT main
END directive
indicates to the assembler the end of the source code
(not the file)
END directive is the last line of the ARM assembly
program, meaning that anything after the END
directive in the source file is ignored by the assembler
Note: does not stop the execution of the program
EQU (equate) directive
used to define a constant value or a fixed address by a name to make the
program easier to read
Example: uses EQU for the counter constant, and then the constant is used
to load the R2 register:
COUNT EQU 0x25
... ... ....
MOV R2, #COUNT ; R2 = 0x25
When assembler compiles the line with #COUNT, it replaces COUNT by
the value 0x25 and the instruction MOV R2, #COUNT is compiled as
MOV R2, #0x25
EQU directive (cont…)
advantages of using EQU
enhances the readability
if a constant is used multiple times throughout the program
and the programmer wants to change its value everywhere,
the programmer can just change the EQU statement, and the
assembler will change all of its occurrences in the program
Using EQU for fixed data assignment
Example:
AREA Example, CODE, READONLY
INCLUDE file1.a ; includes file1
INCLUDE c:\project\file2.a ; includes file2
Assembler data allocation directives