Docsity

ARM Instruction Set: A Guide for Computer Organization and Assembly, Exercises of Logic

Partial preview of the text

Download ARM Instruction Set: A Guide for Computer Organization and Assembly and more Exercises Logic in PDF only on Docsity!

ARM Instruction Set Computer Organization and Assembly Languagesp

g^ z^

y^

g^ g

Yung-Yu Chuangwith slides by Peng-Sheng Chen

Introduction • The ARM processor is easy to program at theassembly level

(It is a RISC)

assembly level. (It is a RISC)• We will learn ARM assembly programming at the

l^ l

d^

it^

GBA^

l t

user level and run it on a GBA emulator.

Memory system • Memory is a linear array ofbytes addressed from 0 to

00

0x

bytes addressed from 0 to^32 2 -1 W^ d

h lf

d^ b t

10 20

0x000000010x

  • Word, half-word, byte• Little-endian

30 FF

0x000000030x

FF FF 0x00000004 0x000000050x

00

0x00000006 0 FFFFFFFD

00 00 0xFFFFFFFD0xFFFFFFFE0xFFFFFFFF

Byte ordering • Big Endian

Least significant byte has

00

0x

  • Least significant byte hashighest addressWord address 0x

00 10 20

0x00000000 0x000000010 00000002

Value: 00102030• Little Endian

20 30 FF

0 x000000020x

  • Least significant byte haslowest address

FF FF FF

0x000000040x

Word address 0x00000000Value: 30201000

FF 00

0x

00 00

0xFFFFFFFD 0xFFFFFFFE

00

0xFFFFFFFE 0xFFFFFFFF

Instruction set ARM instructionsare all 32 bit longare all 32-bit long(except forThumb mode)Thumb mode).There are 2

32

possible machinepossible machineinstructions.Fortunately

they

Fortunately, theyare structured.

Features of ARM instruction set • Load-store architecture^3

dd^

i^

i

  • 3-address instructions• Conditional execution of every instruction• Possible to load/store multiple registers atonce• Possible to combine shift and ALU operations ina single instructiona single instruction

Data processing • They are move, arithmetic, logical, comparisonand multiply instructionsand multiply instructions.• Most data processing instructions can process

f th i

d^

i^ th

b^

l^ hift

one of their operands using the barrel shifter. • General rules:^ – All operands are 32-bit, comingfrom registers or literals.^ – The result, if any, is 32-bit andplaced in a register (with the

ti^ f

l^

g^ lti l

exception for long multiplywhich produces a 64-bit result)3 address format– 3-address format

Instruction set MOV

Rd,

MOVCS

R0,

R^

@^ if

carry

is^

set

@^ then

R0:=R

MOVS

R0,

#^

@^ R0:=0@^ Z=1,

N=0,

@^ C,

V^ unaffected

Register movement

immediate,register,shift

-^ MOV

R0, R

@ R0 = R

@^0

-^ MVN

R0, R

@ R0 = ~R

t d move negated

Addressing modes • Register operands^ ADD

R

R

R

ADD^

R0,^

R1,^

R

  • Immediate operands

a literal; most can be represented ADD^

R^

R^

#^

@^ R3:=R3+

a literal; most can be represented

by (0..255)x

2n^ 0<n<

ADD^

R3,^

R3,^

#^

@^ R3:=R3+

AND^

R8,^

R7,^

#0xff

@^ R8=R7[7:0]

a hexadecimal literalThis is assembler dependent syntaxThis is assembler dependent syntax.

Shifted register operands

Logical shift left^ CC^

0

register

MOV^

R0,^

R2,^

LSL^

#2^ @

R0:=R2<<2@ R^

unchanged

g

Example:

Before

R2=0x Before

R^

0x After

R0=0x000000C0R2=0x00000030R2=0x

Arithmetic shift right

MSB^

register

C

MOV^

R0,^

R2,^

ASR^

#2^ @

R0:=R2>>2@ R^

unchanged

g

Example:

Before

R2=0xA Before

R^

0xA After

R0=0xE800000CR2=0xA0000030R2=0xA

Rotate right

register

MOV^

R0,^

R2,^

ROR^

#2^ @

R0:=R

rotate @^ R

unchanged

g

Example:

Before

R2=0x Before

R^

0x After

R0=0x4000000CR2=0x00000031R2=0x