0% found this document useful (0 votes)
317 views21 pages

Arm Assembler Directives New

The document discusses ARM assembler directives which provide additional information to the assembler beyond CPU instructions. Some key directives include AREA to describe code/data sections, ENTRY to declare a program entry point, and data reservation directives like DCB, DCW, DCD to declare constants in memory. Comments can also be added using semicolons. The assembler translates assembly code to machine code understood by ARM processors.

Uploaded by

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

Arm Assembler Directives New

The document discusses ARM assembler directives which provide additional information to the assembler beyond CPU instructions. Some key directives include AREA to describe code/data sections, ENTRY to declare a program entry point, and data reservation directives like DCB, DCW, DCD to declare constants in memory. Comments can also be added using semicolons. The assembler translates assembly code to machine code understood by ARM processors.

Uploaded by

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

ARM ASSEMBLER DIRECTIVES

08/12/2021 ARM PROCESSOR & APPLN 15EECC207 1


Assembler Fields
ARM Cross-Assembler
• The ARM cross-assembler takes assembly source code and
translates it to machine code that the ARM understands. The
assembler is run on a standard PC.
• The cross-assembler reads the text file (*.s file) and decodes
the text depending on which column the text is in. There are four
columns that are called assembler fields:

1) Label (optional)
2) Opcode/Instruction Mnemonic (must be white space in front)
3) Operand (any required machine code operands)
4) Comment (usually after a semi-colon)

08/12/2021 ARM PROCESSOR & APPLN 15EECC207 2


Assembler Fields
LABEL
MNEMONICS

COMMENT

08/12/2021 ARM PROCESSOR & APPLN 15EECC207 3


Label Field
• Text that is not preceded by a white space character (i.e., the first
character of a line) is treated as a label. A label is a piece of text that
gets assigned the memory address of where it is located in the file.

• Useful for giving global variables (or peripheral registers) a name.


Global variables are memory locations in RAM.

• Also useful for flagging the destination line for a branch instruction.

• Different assemblers will put different restrictions on what characters can


be used in a label.

• Some assemblers allow for an optional colon (:) after the label and some
don’t. Labels may or may not be case-sensitive depending on the
assembler and settings.

08/12/2021 ARM PROCESSOR & APPLN 15EECC207 4


Opcode/Mnemonic Field
- Text that is proceeded by 1 group of white space (or a tab) is treated as an
opcode/mnemonic.
- Only instruction mnemonics (or assembler directives) can be used in this field.
If the assembler does not recognize the mnemonic (it doesn’t exist), it will present
an error.
- Example mnemonics: MOV, LDR, STR, ADD, …

Operand Field
- Text that follows a mnemonic is treated as an operand (3rd column)
MOV R0, #0x0280

08/12/2021 ARM PROCESSOR & APPLN 15EECC207 5


Comment Field

Comments are used to make notes about what you are doing.
There are a couple of ways to enter a comment:
1. The fourth column of the text file is treated as a comment field.
2. Place a semicolon (;) in front of the comment to make it readable and
Ensure the assembler treats what follows it as a comment.
The assembler disregards comments because they are only for the
programmer’s use and are no use to the assembler.

Ex) MOV R4,#0x55 ; this instruction initializes 0x55 into R4 and zeroes
; out the upper 24 bits
2. Placing a semicolon (;) as the first character of a line. The entire line Is treated as a comment.
Ex) ; start of code
; Start MOV R4,#0x55 ; this line will be skipped by the assembler

08/12/2021 ARM PROCESSOR & APPLN 15EECC207 6


Assembler Directives
Source Code – When you write a program, you will include additional
information besides just CPU instructions. Sometimes the
assembler needs more information:

1) Where in memory should the program be loaded?


2) Memory allocation for program data
3) Variable names
4) Global constants

Directives - We accomplish the above using assembler directives.


The assembler directives are specific to the cross-
assembler. The assembler recognizes directives as
keywords and knows what to do. Directives are not
CPU instructions!

08/12/2021 ARM PROCESSOR & APPLN 15EECC207 7


Examples of Directives:
Assembler Directives
DCB : declare constant byte (8-bit, use in non-volatile memory)
DCW : declare constant word (16-bit, use in non-volatile memory)
DCD : declare constant double (32-bit, use in non-volatile memory)
SPACE : reserve space for variable (any size, use in volatile memory)
EQU : equate two things
AREA : describes the attributes of the following section of the file
ALIGN : insert padding as necessary to meet alignment criteria
THUMB: tell assembler to use the Thumb instruction set exclusively
END : file is done—ignore anything that comes after it

08/12/2021 ARM PROCESSOR & APPLN 15EECC207 8


There are directives to declare:
Assembler Directives
• Control placement of code/data (using AREA).
• Declare constants of various sizes (using DCB/DCW/DCD).
• Reserve space for a global variable (using SPACE).
• Initialize constant character strings (using DCB).

Assembler directives are very specific to the assembler you are


using—while the machine code lines are specific only to the target
architecture.

08/12/2021 ARM PROCESSOR & APPLN 15EECC207 9


AREA
• The AREA directive instructs the assembler to assemble a new code or data section.
Sections are independent, named, indivisible chunks of code or data that are
manipulated by the linker.
Syntax
AREA sectionname{,attr}{,attr}...
where:
• Sectionname is the name to give to the section.
• attr are one or more comma-delimited section attributes.
Valid attributes are:
CODE Contains machine instructions. READONLY is the default.
DATA Contains data, not instructions. READWRITE is the default.
READONLY Indicates that this section must not be written to.
This is the default for Code areas.
READWRITE Indicates that this section can be read from and written to.
This is the default for Data areas.

08/12/2021 ARM PROCESSOR & APPLN 15EECC207 10


AREA

• EX
AREA FIRST,CODE,READONLY
AREA AA,DATA,READWRITE

08/12/2021 ARM PROCESSOR & APPLN 15EECC207 11


ENTRY

• The ENTRY directive declares an entry point to a program.


• Syntax
ENTRY
• You must specify at least one ENTRY point for a program. If
no ENTRY exists, a warning is generated at link time.
• You must not use more than one ENTRY directive in a single source file.
Not every source file has to have an ENTRY directive. If more than
one ENTRY exists in a single source file, an error message is generated at
assembly time.
Example
AREA ARMex, CODE, READONLY
ENTRY ; Entry point for the application

08/12/2021 ARM PROCESSOR & APPLN 15EECC207 12


END

• The END directive informs the assembler that it has reached the end of a


source file.
• Syntax
END
• Every assembly language source file must end with END on a line by itself.

08/12/2021 ARM PROCESSOR & APPLN 15EECC207 13


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.

08/12/2021 ARM PROCESSOR & APPLN 15EECC207 14


DCB
• The DCB directive allocates one or more bytes of memory, and defines
the initial runtime contents of the memory. = is a synonym for DCB.
• Syntax
{label} DCB expr{,expr}...
where:
• expr is either:
• a numeric expression that evaluates to an integer in the range -128 to
255.
• a quoted string. The characters of the string are loaded into consecutive
bytes of store.
Example
C_string DCB "C_string",0
Array1 DCB 0x12,0x23,0x45
• Unlike C strings, ARM assembler strings are not null-terminated. You can
construct a null-terminated C string using DCB 
08/12/2021 ARM PROCESSOR & APPLN 15EECC207 15
DCD
• The DCD directive allocates one or more words of memory, aligned on
four-byte boundaries, and defines the initial runtime contents of the
memory.& is a synonym for DCD.
• Syntax
{label} DCD expr{,expr}
• where:
• Expr is either:
• a numeric expression.
• a PC-relative expression.
Examples
• data1 DCD 1,5,20 ; Defines 3 words containing ; decimal values 1, 5, and 20
ADD2 DCD 0X40000000 ;Defines a word containing the value 0x40000000

08/12/2021 ARM PROCESSOR & APPLN 15EECC207 16


DCW
• The DCW directive allocates one or more half words of memory, aligned
on two-byte boundaries, and defines the initial runtime contents of the
memory.
• Syntax
• {label} DCW{U} expr{,expr}...
• where:
• Expr is a numeric expression that evaluates to an integer in the range
-32768 to 65535.
Examples
data DCW 0x1234; defines a halfword
Data_array DCW 0xaaaa,0xbbbb ; defines an array containing two halfwords

08/12/2021 ARM PROCESSOR & APPLN 15EECC207 17


SPACE
• The SPACE directive reserves a zeroed block of memory. 
• Syntax
• {label} SPACE expr
• where:
• Label is an optional label.
• Expr evaluates to the number of bytes to fill or zero.
• Example
AREA MyData, DATA, READWRITE
data1 SPACE 255 ; defines 255 bytes of zeroed store

08/12/2021 ARM PROCESSOR & APPLN 15EECC207 18


EQU

• The EQU directive gives a symbolic name to a numeric constant, a register-


relative value or a PC-relative value. * is a synonym for EQU.
• Syntax
• name EQU expr{, type}
• where:
• nameis the symbolic name to assign to the value.
• expris a register-relative address, a PC-relative address, an absolute
address, or a 32-bit integer constant.
• typeis optional. type can be any one of:
• ARM
• THUMB
• CODE32
• CODE16
• DATA
08/12/2021 ARM PROCESSOR & APPLN 15EECC207 19
• Use EQU to define constants.
• This is similar to the use of #define to define a constant in C.
• Examples
• abc EQU 2 ; assigns the value 2 to the symbol abc.
• xyz EQU label+8 ; assigns the address (label+8) to the ; symbol xyz.

08/12/2021 ARM PROCESSOR & APPLN 15EECC207 20


RN

• The RN directive defines a register name for a specified register.


• Syntax
• name RN expr
• where:
• Name is the name to be assigned to the register. name cannot be the
same as any of the predefined names.
• Expr evaluates to a register number from 0 to 15.
• Use RN to allocate convenient names to registers, to help you to
remember what you use each register for. Be careful to avoid conflicting
uses of the same register under different names.
• Examples
• regname RN 11 ; defines regname for register 11
• sqr4 RN r6 ; defines sqr4 for register 6

08/12/2021 ARM PROCESSOR & APPLN 15EECC207 21

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy