isa assembler format (4d) · isa (4d) assembler format – summary 5 young won lim 12/11/19 arm rn...

47
Young Won Lim 12/11/19 ISA Assembler Format (4D) Summary

Upload: others

Post on 27-Mar-2020

5 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: ISA Assembler Format (4D) · ISA (4D) Assembler Format – Summary 5 Young Won Lim 12/11/19 ARM Rn 1st Operand Reg / Base Reg Rd Source / Destination Reg S Set Condition Codes / Signed

Young Won Lim12/11/19

ISA Assembler Format (4D)

Summary

Page 2: ISA Assembler Format (4D) · ISA (4D) Assembler Format – Summary 5 Young Won Lim 12/11/19 ARM Rn 1st Operand Reg / Base Reg Rd Source / Destination Reg S Set Condition Codes / Signed

Young Won Lim12/11/19

Copyright (c) 2014 - 2019 Young W. Lim.

Permission is granted to copy, distribute and/or modify this document under the terms of the GNU Free Documentation License, Version 1.2 or any later version published by the Free Software Foundation; with no Invariant Sections, no Front-Cover Texts, and no Back-Cover Texts. A copy of the license is included in the section entitled "GNU Free Documentation License".

Please send corrections (or suggestions) to [email protected].

This document was produced by using LibreOffice.

Page 3: ISA Assembler Format (4D) · ISA (4D) Assembler Format – Summary 5 Young Won Lim 12/11/19 ARM Rn 1st Operand Reg / Base Reg Rd Source / Destination Reg S Set Condition Codes / Signed

ISA (4D) Assembler Format – Summary

3 Young Won Lim12/11/19

Based on

ARM System-on-Chip Architecture, 2nd ed, Steve Furber

Page 4: ISA Assembler Format (4D) · ISA (4D) Assembler Format – Summary 5 Young Won Lim 12/11/19 ARM Rn 1st Operand Reg / Base Reg Rd Source / Destination Reg S Set Condition Codes / Signed

ISA (4D) Assembler Format – Summary

4 Young Won Lim12/11/19

ARM

Rn 1st Operand Reg / Base Reg

Rd Left most Reg : Source / Destination Reg

Set Condition Codes / Signed / Restore PSR and force user bit S

Pre/Post IndexP

Up/DownU

Unsigned Byte/WordB

Write-back (auto-index)W

Link / Load/StoreL

Half-word AddressH

4-bit op codesOpcode

2nd Operand Reg / Operand Reg / Offset Reg / Source Reg Rm

Shift type Sh

CPSR/SPSRR

Page 5: ISA Assembler Format (4D) · ISA (4D) Assembler Format – Summary 5 Young Won Lim 12/11/19 ARM Rn 1st Operand Reg / Base Reg Rd Source / Destination Reg S Set Condition Codes / Signed

ISA (4D) Assembler Format – Summary

5 Young Won Lim12/11/19

ARM

Rn 1st Operand Reg / Base Reg

Rd Source / Destination Reg

Set Condition Codes / Signed / Restore PSR and force user bit S

Unsigned Byte/WordB

Link / Load/StoreL

Half-word AddressH

2nd Operand Reg / Operand Reg / Offset Reg / Source Reg Rm

Selects the user view in the non-usermodesT

Page 6: ISA Assembler Format (4D) · ISA (4D) Assembler Format – Summary 5 Young Won Lim 12/11/19 ARM Rn 1st Operand Reg / Base Reg Rd Source / Destination Reg S Set Condition Codes / Signed

ISA (4D) Assembler Format – Summary

6 Young Won Lim12/11/19

ARM

<cond> Conditions for conditional execution

CPSR Current Program Status Register

Saved Program Status RegisterSPSR

The most significant 32-bitsRdHi

The least significant 32-bitsRdLo

aa

aa

aa

aa

aa

Shift type and the shift amount (except RRX)<shift>

aa

aRa

Page 7: ISA Assembler Format (4D) · ISA (4D) Assembler Format – Summary 5 Young Won Lim 12/11/19 ARM Rn 1st Operand Reg / Base Reg Rd Source / Destination Reg S Set Condition Codes / Signed

ISA (4D) Assembler Format – Summary

7 Young Won Lim12/11/19

ARM

<CP#> Coprocessor number

<Cop2> Coprocessor operation 2

Coprocessor RdCRd

Coprocessor RnCRn

Coprocessor RmCRm

a<CP#>

aa

a<Cop2>

a<Cop1>

aa

Coprocessor operation 1<Cop1>

aa

aa

Page 8: ISA Assembler Format (4D) · ISA (4D) Assembler Format – Summary 5 Young Won Lim 12/11/19 ARM Rn 1st Operand Reg / Base Reg Rd Source / Destination Reg S Set Condition Codes / Signed

ISA (4D) Assembler Format – Summary

8 Young Won Lim12/11/19

Assembler Format (1)

Branch and Branch with Link (B, BL)B{L} {<cond>} <target address>

Branch, Branch with Link and eXchange (BX, BLX)B{L}X {<cond>} RmBLX <target address>

Data Processing Instructions<op> {<cond>} {S} Rd, Rn, #<32-bit immediate><op> {<cond>} {S} Rd, Rn, Rm, {<shift>}

Single Word and Unsigned Byte Transfer InstructionsLDR | STR {<cond>} {B} Rd, [Rn, <offset>] {!}LDR | STR {<cond>} {B} {T} Rd, [Rn], <offset>LDR | STR {<cond>} {B} Rd, LABEL

Half-word and Signed Byte Transfer InstructionsLDR | STR {<cond>} H | SH | SB Rd, [Rn, <offset>] {!}LDR | STR {<cond>} H | SH | SB Rd, [Rn], <offset>

Multiple Register Transfer InstructionsLDM | STM {<cond>} <add mode> Rn{!}, <registers>

Page 9: ISA Assembler Format (4D) · ISA (4D) Assembler Format – Summary 5 Young Won Lim 12/11/19 ARM Rn 1st Operand Reg / Base Reg Rd Source / Destination Reg S Set Condition Codes / Signed

ISA (4D) Assembler Format – Summary

9 Young Won Lim12/11/19

Assembler Format (2)

Status Register to General Register Transfer InstructionsMRS {<cond>} Rd, CPSR | SPSR

General Register to Status Register Transfer InstructionsMSR {<cond>} CPSR_f | SPSR_f, #<32-bit immediate>MSR {<cond>} CPSR_<field> | SPSR_<field>, Rm

Multiply InstructionsMUL {<cond>} {S} Rd, Rm, RsMLA {<cond>} {S} Rd, Rm, Rs, Rn <mul> {<cond>} {S} RdHi, RdLo, Rm, Rs

UMULL, UMLAL, SMULL, SMLALSoftware Interrupt (SWI)

SWI {<cond>} <24-bit immediate>Swap Memory and Register Instrucitons

SWP {<cond>} {B} Rd, Rm, [Rn]Count Leading Zeros (CLZ)

CLZ {<cond>} Rd, Rm

Page 10: ISA Assembler Format (4D) · ISA (4D) Assembler Format – Summary 5 Young Won Lim 12/11/19 ARM Rn 1st Operand Reg / Base Reg Rd Source / Destination Reg S Set Condition Codes / Signed

ISA (4D) Assembler Format – Summary

10 Young Won Lim12/11/19

Assembler Format (3)

Coprocessor Data Operations

CDP {<cond>} <CP#>, <Cop1>, CRd, CRn, CRmCDP {<cond>} <CP#>, <Cop1>, CRd, CRn, CRm, <Cop2>

Coprocessor Data Transfers

LDC | STC {<cond>} {L} <CP#>, CRd, [Rn, <offset>] {!}LDC | STC {<cond>} {L} <CP#>, CRd, [Rn], <offset>

Copressor Register Transfers

MRC {<cond>} <CP#>, <Cop1>, Rd, CRn, CRmMRC {<cond>} <CP#>, <Cop1>, Rd, CRn, CRm, <Cop2>MCR {<cond>}, <Cop1>, Rd, CRn, CRm MCR {<cond>}, <Cop1>, Rd, CRn, CRm, <Cop2>

Breakpoint Instruction (BKPT)

BKT

Unused Instruction Space

Page 11: ISA Assembler Format (4D) · ISA (4D) Assembler Format – Summary 5 Young Won Lim 12/11/19 ARM Rn 1st Operand Reg / Base Reg Rd Source / Destination Reg S Set Condition Codes / Signed

ISA (4D) Assembler Format – Summary

11 Young Won Lim12/11/19

Branch and Branch with Link (B, BL)

Branch and Branch with Link (B, BL)B{L} {<cond>} <target address>

L : the branch and link<cond> : condition codes, AL if omitted<target address> : a label in the assembler code

The assembler will generate the offset target address – branch instruction address + 8

B <target address>B<cond> <target address>BL <target address>BL<cond> <target address>

Page 12: ISA Assembler Format (4D) · ISA (4D) Assembler Format – Summary 5 Young Won Lim 12/11/19 ARM Rn 1st Operand Reg / Base Reg Rd Source / Destination Reg S Set Condition Codes / Signed

ISA (4D) Assembler Format – Summary

12 Young Won Lim12/11/19

Branch, Branch with Link and eXchange (BX, BLX)

Branch, Branch with Link and eXchange (BX, BLX)B{L}X {<cond>} RmBLX <target address>

L : the branch and link<cond> : condition codes, AL if omitted<target address> : a label in the assembler code

The assembler will generate the offset target address – branch instruction address + 8

BX RmBLX RmBLX <target address>BX<cond> RmBLX<cond> RmBLX<cond> <target address>

Page 13: ISA Assembler Format (4D) · ISA (4D) Assembler Format – Summary 5 Young Won Lim 12/11/19 ARM Rn 1st Operand Reg / Base Reg Rd Source / Destination Reg S Set Condition Codes / Signed

ISA (4D) Assembler Format – Summary

13 Young Won Lim12/11/19

Data Processing Instructions

Data Processing Instructions<op> {<cond>} {S} Rd, Rn, #<32-bit immediate><op> {<cond>} {S} Rd, Rn, Rm, {<shift>}

Omitting Rn when the instruction is monadic (MOV, MVN)Omitting Rd when the instruction only produces condition code

(CMP, CMN, TST, TEQ)<shift> specifies the shift type (LSL, LSR, ASL, ASR, ROR, RRX)the shift amount (except RRX)

By a 5-bit immediate (# <#shift>)By a register (Rs)

Page 14: ISA Assembler Format (4D) · ISA (4D) Assembler Format – Summary 5 Young Won Lim 12/11/19 ARM Rn 1st Operand Reg / Base Reg Rd Source / Destination Reg S Set Condition Codes / Signed

ISA (4D) Assembler Format – Summary

14 Young Won Lim12/11/19

Data Processing Type 1 – no 1st operand Rn

Data Processing Instructions – no 1st operand Rd <op1> {<cond>} {S} Rd, #<32-bit immediate><op1> {<cond>} {S} Rd, Rm, {<shift>}

MOV MoveMVN Move Negated

Rn : SBZ (Should Be Zero) fields

#<32-bit immediate>

<shift>Rd, Rm

Rd,

Page 15: ISA Assembler Format (4D) · ISA (4D) Assembler Format – Summary 5 Young Won Lim 12/11/19 ARM Rn 1st Operand Reg / Base Reg Rd Source / Destination Reg S Set Condition Codes / Signed

ISA (4D) Assembler Format – Summary

15 Young Won Lim12/11/19

Data Processing Type 2 – no destination Rd

Data Processing Instructions – no destination Rd <op2> {<cond>} Rn, #<32-bit immediate><op2> {<cond>} Rn, Rm, {<shift>}

CMP Compare CMN Compare NegatedTST TestTEQ Test Equivalence

S is implicitly implied

Rd : SBZ (Should Be Zero) fields

#<32-bit immediate>

<shift> Rn, Rm

Rn, <op>

<op>

Page 16: ISA Assembler Format (4D) · ISA (4D) Assembler Format – Summary 5 Young Won Lim 12/11/19 ARM Rn 1st Operand Reg / Base Reg Rd Source / Destination Reg S Set Condition Codes / Signed

ISA (4D) Assembler Format – Summary

16 Young Won Lim12/11/19

Data Processing Type 3 – Arithmetic & Logical Instructions

Data Processing Instructions<op> {<cond>} {S} Rd, Rn, #<32-bit immediate><op> {<cond>} {S} Rd, Rn, Rm, {<shift>}

AND logical bit-wise ANDEOR logical bit-wise Exclusive ORSUB SubtractRSB Reverse SubtractADD AddADC Add with CarrySBC Subtract with Carry RSC Reverse Subtract with CarryORR logical bit-wise ORBIC Bit Clear

#<32-bit immediate>

<shift>Rd, Rn, Rm

Rd, Rn,

<op>

<op>

Page 17: ISA Assembler Format (4D) · ISA (4D) Assembler Format – Summary 5 Young Won Lim 12/11/19 ARM Rn 1st Operand Reg / Base Reg Rd Source / Destination Reg S Set Condition Codes / Signed

ISA (4D) Assembler Format – Summary

17 Young Won Lim12/11/19

Data Processing – Format Listings

Data Processing Instructions<op> {<cond>} {S} Rd, Rn, #<32-bit immediate><op> {<cond>} {S} Rd, Rn, Rm, {<shift>}

<op> Rd, Rn, #<32-bit immediate><op> Rd, Rn, Rm<op> Rd, Rn, Rm, <shift><op> <cond> Rd, Rn, #<32-bit immediate><op> <cond> Rd, Rn, Rm<op> <cond> Rd, Rn, Rm<op> S Rd, Rn, #<32-bit immediate><op> S Rd, Rn, Rm<op> S Rd, Rn, Rm, <shift><op> <cond> S Rd, Rn, #<32-bit immediate><op> <cond> S Rd, Rn, Rm<op> <cond> S Rd, Rn, Rm, <shift>

Page 18: ISA Assembler Format (4D) · ISA (4D) Assembler Format – Summary 5 Young Won Lim 12/11/19 ARM Rn 1st Operand Reg / Base Reg Rd Source / Destination Reg S Set Condition Codes / Signed

ISA (4D) Assembler Format – Summary

18 Young Won Lim12/11/19

Data Processing – <shift> operand

Data Processing Instructions with <shift><op> {<cond>} {S} Rd, Rn, Rm, {<shift>} AND,EOR,SUB,RSB,ADD,ADC,SBC,RSC,ORR,BIC

<op1> {<cond>} {S} Rd, Rm, {<shift>} MOV, MVN … special case

<op2> {<cond>} Rn, Rm, {<shift>} CMP, CMN, TST,TEQ … special case

<shift><shift type> # <#shift> …. instruction-specified shift amount<shift type> Rs …. register-specified shift amountLSL, ASL, Logical Shift Left, Arithmetic Shift LeftLSR, Logical Shift RightASR, Arithmetic Shift RightROR Rotate Right

<shift type> RRX Rotate Right Extended … no shift amount

Page 19: ISA Assembler Format (4D) · ISA (4D) Assembler Format – Summary 5 Young Won Lim 12/11/19 ARM Rn 1st Operand Reg / Base Reg Rd Source / Destination Reg S Set Condition Codes / Signed

ISA (4D) Assembler Format – Summary

19 Young Won Lim12/11/19

Data Processing – simulating shift instruction

Move Instructions with <shift>MOV {<cond>} {S} Rd, Rm, <shift>

<shift><shift type> # <#shift> …. instruction-specified shift amount<shift type> Rs …. register-specified shift amount

can simulate statndalone shift instructions of other machines

MOV R0. R0, LSR 2MOV R0. R0, LSR Rs

Stand Alone Shift Instruction Synonyms … syntactic sugars op {S} {cond} Rd, Rm, <shift>

LSL, LSR, ASL, LSR, ASR, ROR no RRX

RealView Development Suite Ver 4.0 http://infocenter.arm.com/help/index.jsp?topic=/com.arm.doc.dui0204j/Cjacbgca.html

Page 20: ISA Assembler Format (4D) · ISA (4D) Assembler Format – Summary 5 Young Won Lim 12/11/19 ARM Rn 1st Operand Reg / Base Reg Rd Source / Destination Reg S Set Condition Codes / Signed

ISA (4D) Assembler Format – Summary

20 Young Won Lim12/11/19

Multiply Instructions – 32 bit products

Producing the least significant 32 bits of productsMUL {<cond>} {S} Rd, Rm, RsMLA {<cond>} {S} Rd, Rm, Rs, Rn

MUL Rd, Rm, RsMUL S Rd, Rm, RsMUL <cond> Rd, Rm, RsMUL S <cond> Rd, Rm, Rs

MLA Rd, Rm, Rs, RnMLA S Rd, Rm, Rs, RnMLA <cond> Rd, Rm, Rs, RnMLA S <cond> Rd, Rm, Rs, Rn

Rd Rm * Rs

Rd Rm * Rs Rn

Rd := (Rm * Rs)Rd := (Rm * Rs + Rn)

Page 21: ISA Assembler Format (4D) · ISA (4D) Assembler Format – Summary 5 Young Won Lim 12/11/19 ARM Rn 1st Operand Reg / Base Reg Rd Source / Destination Reg S Set Condition Codes / Signed

ISA (4D) Assembler Format – Summary

21 Young Won Lim12/11/19

Multiply Instructions – 64 bit products

Producing the full 64 bits of products<mul> {<cond>} {S} RdHi, RdLo, Rm, Rs

<mul> : UMULLUMLALSMULLSMLAL

<mul> RdHi, RdLo, Rm, Rs<mul>S RdHi, RdLo, Rm, Rs<mul> <cond> RdHi, RdLo, Rm, Rs<mul>S <cond> RdHi, RdLo, Rm, Rs

Rm * RsRdHi, RdLo

RdHi:RdLo := Rm * Rs

Page 22: ISA Assembler Format (4D) · ISA (4D) Assembler Format – Summary 5 Young Won Lim 12/11/19 ARM Rn 1st Operand Reg / Base Reg Rd Source / Destination Reg S Set Condition Codes / Signed

ISA (4D) Assembler Format – Summary

22 Young Won Lim12/11/19

Status Reg to General Reg Transfer Instructions

Status Register to General Register Transfer InstructionsMRS {<cond>} Rd, CPSR | SPSR

MRS Rd, CPSRMRS Rd, SPSRMRS <cond> Rd, CPSRMRS <cond> Rd, SPSR

M R S

Page 23: ISA Assembler Format (4D) · ISA (4D) Assembler Format – Summary 5 Young Won Lim 12/11/19 ARM Rn 1st Operand Reg / Base Reg Rd Source / Destination Reg S Set Condition Codes / Signed

ISA (4D) Assembler Format – Summary

23 Young Won Lim12/11/19

General Reg to Status Reg Transfer Instructions

General Register to Status Register Transfer InstructionsMSR {<cond>} CPSR_f | SPSR_f, #<32-bit immediate>MSR {<cond>} CPSR_<field> | SPSR_<field>, Rm

_<field> is one of _c : the control field PSR[ 7: 0]_x : the extension field PSR[15: 8] (unused on current ARMs)_s : the status field PSR[23:16] (unused on current ARMs)_f : the flag field PSR[31:24]

MSR CPSR_f, #<32-bit immediate>MSR SPSR_f, #<32-bit immediate>MSR <cond> CPSR_f, #<32-bit immediate>MSR <cond> SPSR_f, #<32-bit immediate>MSR CPSR_<field>, RmMSR SPSR_<field>, RmMSR <cond> CPSR_<field>, RmMSR <cond> SPSR_<field>, Rm M S R

Page 24: ISA Assembler Format (4D) · ISA (4D) Assembler Format – Summary 5 Young Won Lim 12/11/19 ARM Rn 1st Operand Reg / Base Reg Rd Source / Destination Reg S Set Condition Codes / Signed

ISA (4D) Assembler Format – Summary

24 Young Won Lim12/11/19

Data Transfer Instructions

The pre-indexed form of the instructionLDR | STR {<cond>} {B} Rd, [Rn, <offset>] {!}

The post-indexed form LDR | STR {<cond>} {B} {T} Rd, [Rn], <offset>

A useful PC-relative form (assembler does all the work)LDR | STR {<cond>} Rd, LABEL

The pre-indexed form of the instructionLDR | STR {<cond>} H | SH | SB Rd, [Rn, <offset>] {!}

The post-indexed form LDR | STR {<cond>} H | SH | SB Rd, [Rn], <offset>

Single Word and Unsigned Byte

Half Word and Signed Data

Page 25: ISA Assembler Format (4D) · ISA (4D) Assembler Format – Summary 5 Young Won Lim 12/11/19 ARM Rn 1st Operand Reg / Base Reg Rd Source / Destination Reg S Set Condition Codes / Signed

ISA (4D) Assembler Format – Summary

25 Young Won Lim12/11/19

Data Transfer Instructions – single word and unsigned byte

The pre-indexed form of the instructionLDR | STR {<cond>} {B} Rd, [Rn, <offset>] {!}

The post-indexed form LDR | STR {<cond>} {B} {T} Rd, [Rn], <offset>

A useful PC-relative form (assembler does all the work)LDR | STR {<cond>} Rd, LABEL

B selects unsigned byte transfer, the default is word <offset> = 1. #+/–<12-bit immediate>

= 2. +/–Rm {, <shift>}! selects write-back (auto-indexing) in the pre-indexed form T selects the user view of the memory translation and protection system should only be used in non-user mode<shift> general shift operation but you cannot specify

the shift amount by a register.

Single Word and Unsigned Byte

Page 26: ISA Assembler Format (4D) · ISA (4D) Assembler Format – Summary 5 Young Won Lim 12/11/19 ARM Rn 1st Operand Reg / Base Reg Rd Source / Destination Reg S Set Condition Codes / Signed

ISA (4D) Assembler Format – Summary

26 Young Won Lim12/11/19

Data Transfer Instructions – single word and unsigned byte

The pre-indexed form of the instructionLDR | STR {<cond>} {B} Rd, [Rn, <offset>] {!}

LDR | STR Rd, [Rn, +-Rm] {!}LDR | STR Rd, [Rn, +-Rm, <sh>, amount] {!}LDR | STR Rd, [Rn, #+-<12-bit immediate>] {!}LDR | STR B Rd, [Rn, +-Rm]] {!}LDR | STR B Rd, [Rn, +-Rm, <sh>, amount] {!}LDR | STR B Rd, [Rn, #+-<12-bit immediate>] {!}LDR | STR <cond> Rd, [Rn, +-Rm] {!}LDR | STR <cond> Rd, [Rn, +-Rm, <sh>, amount] {!}LDR | STR <cond> Rd, [Rn, #+-<12-bit immediate>] {!}LDR | STR <cond> B Rd, [Rn, +-Rm]] {!}LDR | STR <cond> B Rd, [Rn, +-Rm, <sh>, amount] {!}LDR | STR <cond> B Rd, [Rn, #+-<12-bit immediate>] {!}

Page 27: ISA Assembler Format (4D) · ISA (4D) Assembler Format – Summary 5 Young Won Lim 12/11/19 ARM Rn 1st Operand Reg / Base Reg Rd Source / Destination Reg S Set Condition Codes / Signed

ISA (4D) Assembler Format – Summary

27 Young Won Lim12/11/19

Data Transfer Instructions – single word and unsigned byte

The post-indexed form LDR | STR {<cond>} {B} {T} Rd, [Rn], <offset>

LDR | STR Rd, [Rn], +-Rm LDR | STR Rd, [Rn], +-Rm, <sh>, amount LDR | STR Rd, [Rn], #+-<12-bit immediate> LDR | STR {B}{T} Rd, [Rn], +-Rm LDR | STR {B}{T} Rd, [Rn], +-Rm, <sh>, amount LDR | STR {B}{T} Rd, [Rn], #+-<12-bit immediate> LDR | STR <cond> Rd, [Rn], +-Rm LDR | STR <cond> Rd, [Rn], +-Rm, <sh>, amount LDR | STR <cond> Rd, [Rn], #+-<12-bit immediate> LDR | STR <cond> {B}{T} Rd, [Rn], +-Rm LDR | STR <cond> {B}{T} Rd, [Rn], +-Rm, <sh>, amount LDR | STR <cond> {B}{T} Rd, [Rn], #+-<12-bit immediate>

Page 28: ISA Assembler Format (4D) · ISA (4D) Assembler Format – Summary 5 Young Won Lim 12/11/19 ARM Rn 1st Operand Reg / Base Reg Rd Source / Destination Reg S Set Condition Codes / Signed

ISA (4D) Assembler Format – Summary

28 Young Won Lim12/11/19

Data Transfer Instructions – single word and unsigned byte

A useful PC-relative form (assembler does all the work)LDR | STR {<cond>} Rd, LABEL

LDR | STR Rd, LABELLDR | STR <cond> Rd, LABEL

Page 29: ISA Assembler Format (4D) · ISA (4D) Assembler Format – Summary 5 Young Won Lim 12/11/19 ARM Rn 1st Operand Reg / Base Reg Rd Source / Destination Reg S Set Condition Codes / Signed

ISA (4D) Assembler Format – Summary

29 Young Won Lim12/11/19

Data Transfer Instructions – half-word and signed data

The pre-indexed form of the instructionLDR | STR {<cond>} H | SH | SB Rd, [Rn, <offset>] {!}

The post-indexed form LDR | STR {<cond>} H | SH | SB Rd, [Rn], <offset>

H|SH|SB selects the data type (H: half-word, S:signed)<offset> = 1. #+/–<8-bit immediate>

= 2. +/–Rm …. no shifted operand! selects write-back (auto-indexing) in the pre-indexed form

Half Word and Signed Data

Page 30: ISA Assembler Format (4D) · ISA (4D) Assembler Format – Summary 5 Young Won Lim 12/11/19 ARM Rn 1st Operand Reg / Base Reg Rd Source / Destination Reg S Set Condition Codes / Signed

ISA (4D) Assembler Format – Summary

30 Young Won Lim12/11/19

Data Transfer Instructions – half-word and signed data

The pre-indexed form of the instructionLDR | STR {<cond>} H | SH | SB Rd, [Rn, <offset>] {!}

LDR | STR H Rd, [Rn, #+-Rm] {!}LDR | STR H Rd, [Rn, #+-<8-bit immediate>] {!}LDR | STR SH Rd, [Rn, #+-Rm] {!}LDR | STR SH Rd, [Rn, #+-<8-bit immediate>] {!}LDR | STR SB Rd, [Rn, #+-Rm] {!}LDR | STR SB Rd, [Rn, #+-<8-bit immediate>] {!}LDR | STR <cond> H Rd, [Rn, #+-Rm] {!}LDR | STR <cond> H Rd, [Rn, #+-<8-bit immediate>] {!}LDR | STR <cond> SH Rd, [Rn, #+-Rm] {!}LDR | STR <cond> SH Rd, [Rn, #+-<8-bit immediate>] {!}LDR | STR <cond> SB Rd, [Rn, #+-Rm] {!}LDR | STR <cond> SB Rd, [Rn, #+-<8-bit immediate>] {!}

Page 31: ISA Assembler Format (4D) · ISA (4D) Assembler Format – Summary 5 Young Won Lim 12/11/19 ARM Rn 1st Operand Reg / Base Reg Rd Source / Destination Reg S Set Condition Codes / Signed

ISA (4D) Assembler Format – Summary

31 Young Won Lim12/11/19

Data Transfer Instructions – half-word and signed data

The post-indexed form LDR | STR {<cond>} H | SH | SB Rd, [Rn], <offset>

LDR | STR H Rd, [Rn], #+-RmLDR | STR H Rd, [Rn], #+-<8-bit immediate>LDR | STR SH Rd, [Rn], #+-RmLDR | STR SH Rd, [Rn], #+-<8-bit immediate>LDR | STR SB Rd, [Rn], #+-RmLDR | STR SB Rd, [Rn], #+-<8-bit immediate>LDR | STR <cond> H Rd, [Rn], #+-RmLDR | STR <cond> H Rd, [Rn], #+-<8-bit immediate>LDR | STR <cond> SH Rd, [Rn], #+-RmLDR | STR <cond> SH Rd, [Rn], #+-<8-bit immediate>LDR | STR <cond> SB Rd, [Rn], #+-RmLDR | STR <cond> SB Rd, [Rn], #+-<8-bit immediate>

Page 32: ISA Assembler Format (4D) · ISA (4D) Assembler Format – Summary 5 Young Won Lim 12/11/19 ARM Rn 1st Operand Reg / Base Reg Rd Source / Destination Reg S Set Condition Codes / Signed

ISA (4D) Assembler Format – Summary

32 Young Won Lim12/11/19

Data Transfer with Shifted Operand Instructions

The pre-indexed form of the instructionLDR | STR {<cond>} {B} Rd, [Rn, <offset>] {!} shifted operand

The post-indexed form LDR | STR {<cond>} {B} {T} Rd, [Rn], <offset> shifted operand

A useful PC-relative form (assembler does all the work)LDR | STR {<cond>} Rd, LABEL shifted operand

The pre-indexed form of the instructionLDR | STR {<cond>} H | SH | SB Rd, [Rn, <offset>] {!} shifted operand

The post-indexed form LDR | STR {<cond>} H | SH | SB Rd, [Rn], <offset> shifted operand

only single (word / unsigned byte) data transfer instructions support shifted offset

Single Word and Unsigned Byte

Half Word and Signed Data

Page 33: ISA Assembler Format (4D) · ISA (4D) Assembler Format – Summary 5 Young Won Lim 12/11/19 ARM Rn 1st Operand Reg / Base Reg Rd Source / Destination Reg S Set Condition Codes / Signed

ISA (4D) Assembler Format – Summary

33 Young Won Lim12/11/19

Data Transfer Offset – <shift> operand

Data Transfer Instructions with <shift>LDR | STR {<cond>} {B} Rd, [Rn, <offset>] {!}LDR | STR {<cond>} {B} {T} Rd, [Rn], <offset>

<offset> #+/–<12-bit immediate>+/–Rm {, <shift>}

<shift type> # <#shift><shift type> Rs … not allowed in single data transfers

LSL, ASL, Logical Shift Left, Arithmetic Shift LeftLSR, Logical Shift RightASR, Arithmetic Shift RightROR Rotate Right

<shift type> RRX Rotate Right Extended

Page 34: ISA Assembler Format (4D) · ISA (4D) Assembler Format – Summary 5 Young Won Lim 12/11/19 ARM Rn 1st Operand Reg / Base Reg Rd Source / Destination Reg S Set Condition Codes / Signed

ISA (4D) Assembler Format – Summary

34 Young Won Lim12/11/19

Multiple data transfer instructions

The normal form LDM | STM {<cond>} <add mode> Rn {!}, registers

<add mode> specifies one of the addressing mode

(I,D)x(B,A) | (F,E)x(A,D)IB Inc Before | FA Full AscendingIA Inc After | FD Full DescendingDB Dec Before | EA Empty AscendingDA Dec After | ED Empty Descending

Rn ! Updates the base register Rn Increment / Decrement the base register Rn

LDMIB, LDMIA / LDMDB, LDMDASTMIB, STMIA / STMDB, STMDA

Increment / Decrement the stack top register Rn

Page 35: ISA Assembler Format (4D) · ISA (4D) Assembler Format – Summary 5 Young Won Lim 12/11/19 ARM Rn 1st Operand Reg / Base Reg Rd Source / Destination Reg S Set Condition Codes / Signed

ISA (4D) Assembler Format – Summary

35 Young Won Lim12/11/19

Multiple data transfer instructions – the normal form

The normal form LDM | STM {<cond>} <add mode> Rn {!}, registers

<add mode> specifies one of the addressing mode IB, IA, DB, DA, FA, FD, EA, ED (I,D)x(B,A) | (F,E)x(A,D)

LDM | STM IB | IA | DB | DA | FA | FD | EA | ED Rn, Registers LDM | STM IB | IA | DB | DA | FA | FD | EA | ED Rn!, Registers LDM | STM <cond> IB | IA | DB | DA | FA | FD | EA | ED Rn, Registers LDM | STM <cond> IB | IA | DB | DA | FA | FD | EA | ED Rn!, Registers

Page 36: ISA Assembler Format (4D) · ISA (4D) Assembler Format – Summary 5 Young Won Lim 12/11/19 ARM Rn 1st Operand Reg / Base Reg Rd Source / Destination Reg S Set Condition Codes / Signed

ISA (4D) Assembler Format – Summary

36 Young Won Lim12/11/19

Multiple data transfer instructions – non-user mode

To restore the CPSR in a non-user modeLDM {<cond>} <add mode> Rn {!}, <registers + pc>^

To save / restore the use registers in a non-user modeLDM | STM {<cond>} <add mode> Rn, <registers - pc>^

when pc is included in the <reglist> … returning from an execution handler

SPSR → CPSR

when pc is not included in the <reglist> load to <registers> … load to the user mode registersstore from <register> ... store from the user mode registers

Page 37: ISA Assembler Format (4D) · ISA (4D) Assembler Format – Summary 5 Young Won Lim 12/11/19 ARM Rn 1st Operand Reg / Base Reg Rd Source / Destination Reg S Set Condition Codes / Signed

ISA (4D) Assembler Format – Summary

37 Young Won Lim12/11/19

Software Interrupt (SWI)

Software Interrupt (SWI)SWI {<cond>} <24-bit immediate>

Page 38: ISA Assembler Format (4D) · ISA (4D) Assembler Format – Summary 5 Young Won Lim 12/11/19 ARM Rn 1st Operand Reg / Base Reg Rd Source / Destination Reg S Set Condition Codes / Signed

ISA (4D) Assembler Format – Summary

38 Young Won Lim12/11/19

Swap Memory and Register Instructions

Swap Memory and Register InstrucitonsSWP {<cond>} {B} Rd, Rm, [Rn]

Rd := [Rn], [Rn] = Rmthe swap address by the base register (Rn)

Rd, Rm, [Rn]

(1)

(2)

Page 39: ISA Assembler Format (4D) · ISA (4D) Assembler Format – Summary 5 Young Won Lim 12/11/19 ARM Rn 1st Operand Reg / Base Reg Rd Source / Destination Reg S Set Condition Codes / Signed

ISA (4D) Assembler Format – Summary

39 Young Won Lim12/11/19

Count Leading Zeros (CLZ)

Count Leading Zeros (CLZ)CLZ {<cond>} Rd, Rm

Page 40: ISA Assembler Format (4D) · ISA (4D) Assembler Format – Summary 5 Young Won Lim 12/11/19 ARM Rn 1st Operand Reg / Base Reg Rd Source / Destination Reg S Set Condition Codes / Signed

ISA (4D) Assembler Format – Summary

40 Young Won Lim12/11/19

Coprocessor Instruction

Coprocessor Data TransfersLDC | STC {<cond>} {L} <CP#>, CRd, [Rn, <offset>] {!}LDC | STC {<cond>} {L} <CP#>, CRd, [Rn], <offset>

Coprocessor Data OperationsCDP {<cond>} <CP#>, <Cop1>, CRd, CRn, CRm {, <Cop2>}

Coprocessor Register TransfersMRC {<cond>} <CP#>, <Cop1>, Rd, CRn, CRm {, <Cop2>}MCR {<cond>} <CP#>, <Cop1>, Rd, CRn, CRm {, <Cop2>}

Page 41: ISA Assembler Format (4D) · ISA (4D) Assembler Format – Summary 5 Young Won Lim 12/11/19 ARM Rn 1st Operand Reg / Base Reg Rd Source / Destination Reg S Set Condition Codes / Signed

ISA (4D) Assembler Format – Summary

41 Young Won Lim12/11/19

Coprocessor Data Transfers – Preindex

Preindex Coprocessor Data TransferLDC | STC {<cond>} {L} <CP#>, CRd, [Rn, <offset>] {!}

CP# : Coprocessor Number

LDC | STC <CP#>, CRd, [Rn, <offset>] LDC | STC <cond> <CP#>, CRd, [Rn, <offset>]LDC | STC L <CP#>, CRd, [Rn, <offset>]LDC | STC <cond> L <CP#>, CRd, [Rn, <offset>]LDC | STC <CP#>, CRd, [Rn, <offset>] !LDC | STC <cond> <CP#>, CRd, [Rn, <offset>] !LDC | STC L <CP#>, CRd, [Rn, <offset>] !LDC | STC <cond> L <CP#>, CRd, [Rn, <offset>] !

Page 42: ISA Assembler Format (4D) · ISA (4D) Assembler Format – Summary 5 Young Won Lim 12/11/19 ARM Rn 1st Operand Reg / Base Reg Rd Source / Destination Reg S Set Condition Codes / Signed

ISA (4D) Assembler Format – Summary

42 Young Won Lim12/11/19

Coprocessor Data Transfers – Postindex

Postindex Coprocessor Data TransferLDC | STC {<cond>} {L} <CP#>, CRd, [Rn], <offset>

CP# : Coprocessor Number

LDC | STC <CP#>, CRd, [Rn], <offset> LDC | STC <cond> <CP#>, CRd, [Rn], <offset>LDC | STC L <CP#>, CRd, [Rn], <offset>LDC | STC <cond> L <CP#>, CRd, [Rn], <offset>LDC | STC <CP#>, CRd, [Rn], <offset> !LDC | STC <cond> <CP#>, CRd, [Rn], <offset> !LDC | STC L <CP#>, CRd, [Rn], <offset> !LDC | STC <cond> L <CP#>, CRd, [Rn], <offset> !

Page 43: ISA Assembler Format (4D) · ISA (4D) Assembler Format – Summary 5 Young Won Lim 12/11/19 ARM Rn 1st Operand Reg / Base Reg Rd Source / Destination Reg S Set Condition Codes / Signed

ISA (4D) Assembler Format – Summary

43 Young Won Lim12/11/19

Coprocessor Data Operations

Coprocessor Data Processing OperationsCDP {<cond>} <CP#>, <Cop1>, CRd, CRn, CRmCDP {<cond>} <CP#>, <Cop1>, CRd, CRn, CRm, <Cop2>

CP# : Coprocessor Number

CDP <CP#>, <Cop1>, CRd, CRn, CRm CDP <CP#>, <Cop1>, CRd, CRn, Crm, <Cop2>CDP <cond> <CP#>, <Cop1>, CRd, CRn, CRm CDP <cond> <CP#>, <Cop1>, CRd, CRn, CRm, <Cop2>

Page 44: ISA Assembler Format (4D) · ISA (4D) Assembler Format – Summary 5 Young Won Lim 12/11/19 ARM Rn 1st Operand Reg / Base Reg Rd Source / Destination Reg S Set Condition Codes / Signed

ISA (4D) Assembler Format – Summary

44 Young Won Lim12/11/19

Coprocessor Register Transfers (R←C)

Move to ARM Register from CoprocessorMRC {<cond>} <CP#>, <Cop1>, Rd, CRn, CRmMRC {<cond>} <CP#>, <Cop1>, Rd, CRn, CRm, <Cop2>

CP# : Coprocessor Number

MRC <CP#>, <Cop1>, Rd, CRn, CRmMRC <CP#>, <Cop1>, Rd, CRn, CRm, <Cop2>MRC <cond> <CP#>, <Cop1>, Rd, CRn, CRmMRC <cond> <CP#>, <Cop1>, Rd, CRn, CRm, <Cop2>

Page 45: ISA Assembler Format (4D) · ISA (4D) Assembler Format – Summary 5 Young Won Lim 12/11/19 ARM Rn 1st Operand Reg / Base Reg Rd Source / Destination Reg S Set Condition Codes / Signed

ISA (4D) Assembler Format – Summary

45 Young Won Lim12/11/19

Coprocessor Register Transfers (C←R)

Move to Coprocessor from ARM RegistersMCR {<cond>} <CP#>, <Cop1>, Rd, CRn, CRm MCR {<cond>} <CP#>, <Cop1>, Rd, CRn, CRm, <Cop2>

CP# : Coprocessor Number

MCR <CP#>, <Cop1>, Rd, CRn, CRmMCR <CP#>, <Cop1>, Rd, CRn, CRm, <Cop2>MCR <cond> <CP#>, <Cop1>, Rd, CRn, CRmMCR <cond> <CP#>, <Cop1>, Rd, CRn, CRm, <Cop2>

Page 46: ISA Assembler Format (4D) · ISA (4D) Assembler Format – Summary 5 Young Won Lim 12/11/19 ARM Rn 1st Operand Reg / Base Reg Rd Source / Destination Reg S Set Condition Codes / Signed

ISA (4D) Assembler Format – Summary

46 Young Won Lim12/11/19

Breakpoint Instruction

Breakpoint Instruction (BKPT)BRK

Page 47: ISA Assembler Format (4D) · ISA (4D) Assembler Format – Summary 5 Young Won Lim 12/11/19 ARM Rn 1st Operand Reg / Base Reg Rd Source / Destination Reg S Set Condition Codes / Signed

ISA (4D) Assembler Format – Summary

47 Young Won Lim12/11/19

References

[1] ftp://ftp.geoinfo.tuwien.ac.at/navratil/HaskellTutorial.pdf[2] https://www.umiacs.umd.edu/~hal/docs/daume02yaht.pdf