0% found this document useful (0 votes)
21 views

ARM Slides Part2

ARM has a 32-bit instruction set with three main categories: data transfer, data processing, and control flow instructions. Data transfer instructions like MOV and MVN move data between registers. Data processing instructions perform arithmetic like ADD, SUB, and ADC. Control flow instructions include branches. Assembler directives like AREA, ENTRY, and END are used to define sections of code and data and mark program entry/exit points.
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
21 views

ARM Slides Part2

ARM has a 32-bit instruction set with three main categories: data transfer, data processing, and control flow instructions. Data transfer instructions like MOV and MVN move data between registers. Data processing instructions perform arithmetic like ADD, SUB, and ADC. Control flow instructions include branches. Assembler directives like AREA, ENTRY, and END are used to define sections of code and data and mark program entry/exit points.
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 17

Topic 3: ARM

Part 2: Introduction to the instruction set


ARM Instruction Set - Overview

 ARM processors share the same basic


instruction set
 Every instruction is just 32-bit long (we’ll
discuss the format of instructions and
indicate how binary strings are assigned
to different `portions’ of instructions later)

2
Categories of ARM instructions

 Data transfer instructions


 Data processing instructions
 Control flow instructions

3
Data Transfer

 Basic instructions are MOV and MVN


 MOV r0, #11 ; put the value 11 in register
r0
 MOV r0, r2 ; r0 := r2
 MVN r0, r2 ; r0 := not r2
(MVN stands for move negated: it leaves
the result register set to the value
obtained by inverting every bit in source
4 operand)
Data Processing - Arithmetic

 ADD uses three operands


– Two sources and one destination
Form: ADD a, b, c ; a gets b + c
(everything to right of ; is a comment)

5
Arithmetic – More on addition

 ADD is used to add two 32-bit values


 Operands may be unsigned or 2’s
complement signed integers
 ADDS does the same but sets a carry flag
 The carry flag can be checked via the
Current Program Status Register (CPSR)

6
Same basic form for other operations !

 Arithmetic operations have the same basic form:


 ADC x, y, z does x = y + z + C where C is
a bit in the Current Program Status
Register (CPSR); ADC stands for add with
carry
 C
SUB x, y, z does x = y – z while
 SBC x, y, z does x = y – z -
SBC subtracts z and NOT(carry flag) from
7 y; so it is the same as y – z + C -1
Control Flow Instructions

 Branch, if-then instructions


 Specific instructions include B
(unconditional branch), BEQ, BNEQ etc.
 Will discuss in more detail later

8
Introduction to assembler directives

 To get a complete program which an


assembler can handle, need some way of
defining storage space, specify where
program and data blocks are to be placed
in memory ...
 In other words, we need instructions to
the assembler for creating areas of code,
marking the end of the code etc.

9
The AREA directive

 Area: This directive instructs the assembler to


begin a new code or data section in general

 AREA CODE READONLY


specifies two attributes for the AREA directive:
(a) CODE: the section is only for code (and not for
data).
(b) READONLY: this section should not be written
to, and can therefore be placed in read-only
memory
Other directives

 EQU : This directive is used to define symbolic


names for constants. For example
abc EQU 2 ; assigns the value 2 to the
; symbol abc
 ENTRY: This directive specifies the program
entry point
 END: This directive must appear at the end of a
source file
 There are also directives such as DCD and DCW
etc. to allocate few bytes of memory
Sample program (can call it
myprog.s)

AREA Reset, CODE, READONLY


ENTRY
MOV r0, #11
ADD r1, r0, #3
MOV r2, #11
stop
B stop ; defines an infinite loop
END

12
Explanation

 The first two lines in the program (as well


as the last line) have assembler
directives
 In between the assembler directives, we
have ARM code consisting of data
transfer, data processing and control flow
instructions
 Exercise: Determine the final contents of
r1 and r2
13
Running myprog.s in Keil µVision5

Select Project → New µVision Project (and give a name in


the window that comes up)

Then in “Select Device for Target”, choose “Legacy Device


Database” instead of “Software Packs” and select LPC2378
under NXP

Now at the prompt:


Copy `LPC2300.s' to Project Folder and Add File to Project ?
-- Say "No"

14
Running the program (continued)

Then click on “Source Group 1” and Add myprog.s using “Add Files to Group" .
Thereafter, select Project → Build Target
Now select Debug → Start/Stop session

You may get a window with a message as "Evaluation Mode: Code size limit is 32K“
-- just click "Ok"

You will see the cursor stopping at the first ARM instruction. Just single step (use F11
key) and see how the register contents are changing on the left hand side

Can also observe memory contents at the bottom

Note that you need to pay attention to indenting (use one Tab space for ARM
instructions, AREA etc.)

15
Register operands

 Unlike programs in high-level languages


like C, operands of arithmetic instructions
are restricted: they must come from a
limited number of special locations built
directly in hardware called registers.
Operands of ADD are contents of
registers (in the CPU)
 Size of a register in ARM is 32 bits
 There are sixteen 32-bit registers in ARM
16
Reference

D. Patterson and J. Hennessy, Computer


Organization and Design, ARM Edition

17

You might also like