0% found this document useful (0 votes)
42 views10 pages

Lec 3

The document provides an overview of ARM Cortex-M assembly language, detailing basic data instructions, load/store instructions, and examples of translating C code into assembly. It explains the ARM architecture's data sizes, instruction sets, and various operations such as addition, subtraction, and logical shifts. Additionally, it includes examples of how to implement C assignments and conditional statements in ARM assembly language.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
42 views10 pages

Lec 3

The document provides an overview of ARM Cortex-M assembly language, detailing basic data instructions, load/store instructions, and examples of translating C code into assembly. It explains the ARM architecture's data sizes, instruction sets, and various operations such as addition, subtraction, and logical shifts. Additionally, it includes examples of how to implement C assignments and conditional statements in ARM assembly language.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 10

ARM Cortex -

M Assembly
Language
ARM data instruction

• Basic format:
ADD R0,R1,R2 R0=R1+R2
- Computes R1+R2 , Stores in
R0.
• Immediate operand:
ADD R0,R1,#2 R0=R1+2
- Computes R1+R2, stores in
R0.
ARM data instruction
• ADD, ADC : add(w. carry)
• SUB, SBC : Subtract (w. carry)
• MUL : multiply
• AND , ORR, EOR
• BIC : bit clear Like AND
• LSL , LSR : logical shift left/right
• ROR : rotate right
Data Sizes and Instruction Sets

The ARM is a 32-bit architecture.

When used in relation to the ARM:

Byte means 8 bits

Halfword means 16 bits (two bytes)

Word means 32 bits (four bytes)

Most ARM’s implement two instruction sets

32-bit ARM Instruction Set


4

16-bit Thumb Instruction Set


ARM assembly language

• Outline
• The ARM programmers’ model
• The ARM instruction set
• Writing simple programs

5
ARM load/store instructions

• LDR, LDRH,LDRB : load (half- word, byte)


• STR, STRH, STRB : store (half- word, byte)
• Addressing modes:
- Register indirect : LDR R0, [R1]
- With constant : LDR R0 ,[R1,#4]
• Load from memory into a register
LDR R8,[R10]
• C:
Example: C X=(a+b)-c;
• Assembler:
assignments LDR R4,=4 ;get address for a
R4= address a
R0= value a
LDR R0,[R4] ;get value of a
LDR R4,=B ; get address for b , reusing r4 R4= address b
LDR R1,[R4] ; get value of b R1= value b
ADD R3,R0,R1 ; compute a+b R3=R0+R1=a+b
LDR R4,=C ; get address for c R4= address c
LDR R2,[R4] ; get value of c
R2= value c
SUB R3,R3,R2 ; complete computation of x
R3=R3-R2=a+b-c
LDR R4,=X ; get address for x
STR R3,[R4] ; store value of 1 R4= address x
R4=R3
Example: C assignments
• C:
y=a*(b+c);
• Assembler

MUL R2,R2,R0 ; Compute final value for y


LDR R4,=Y ; get address for y
STR R2, [R4] ; store y
Example: C assignments
• C:
Z= (A<<2) I (B&15);
• Assembler
Example: if statement
• C:
If (a>b) {x=5; y=c+d;} else x=c-d;
• Assembler

You might also like