Professional Documents
Culture Documents
Microprocessor System
Microprocessor Assembly Language Programming
What we will learn in this section:
Addressing Modes
Instruction sets: Data Transfer
MOV instruction
LDR / STR Instruction
ECE 521:
Microprocessor System
Addressing Modes
Addressing modes
refer to the ways the operands are specified in the instruction.
Specifies the ways , the effective address of an operand is
represented in the instruction.
the way CPU generates addresses from instruction to read/
write the operands in the memory
Some of the simple ARM addressing modes are:
1. Register
2. Immediate
3. Register indirect (indexed addressing mode)
Destinations of all ARM instructions are always a register, except
the “STR” instructions.
Register Addressing Mode
The register addressing mode involves the use of registers to hold the data to be
manipulated, symbol R.
Memory is not accessed; therefore, it is relatively fast
Examples of register addressing mode:
MOV R6, R2 ; copy the contents of R2 into R6
ADD R1, R1, R3 ; add the contents of R3 to contents of R1
SUB R7, R7, R2 ; subtract R2 from R7
Notes: cannot load values larger than 0xFFFF (0–65535) into registers R0 to
R12 using the MOV instruction (for ARM CORTEX M)
MOV instruction (Immediate Values)
MOV R2,#0x25 ;load R2 with 0x25 (R2 = 0x25)
MOV R1,#0x87 ;copy 0x87 into R1 (R1 = 0x87)
MOV R1,#87 ;copy decimal value 87 into R1(R1=0x135)
Notes:
We put # in front of every immediate value.
If we want to present a number in hex, we put a 0x in front of it. If we put nothing in front of a
number, it is in decimal. For example, in “MOV R1,#50”, R1 is loaded with 50 in decimal,
whereas in “MOV R1,#0x50”, R1 is loaded with 50 in hex ( 80 in decimal).
If values 0 to FF are moved into a 32-bit register, the rest of the bits are assumed to be all zeros.
For example, in “MOV R1,#0x5” the result will be R1=0x00000005; that is,
R1=00000000000000000000000000000101 in binary.
MOVS (update flags)
Flags: Affected: C, N, Z
Format: MOVS Rd,#imm_value
Function: Load the Rd register with an immediate value
and update the flags.
Example:
MOVS R0,#0x25 ;R0=0x25,N=0,Z=0, and C=0
MOVS R0,#0x0 ;R0=0x0, N=0,Z=1, and C=0
MVN instruction
MVN instruction store the negative of OP2 (1st complement)
in Rd.
the following formats:
Example:
MOVW R1,#0x5555 ;R1=0x5555
MOVT (Move Top)
Format:
MOVT Rd,#imm_value
Function: Loads the upper 16-bit of Rd register with an
immediate value.
The immediate value cannot be larger than 0xFFFF (0–65535).
The lower 16-bit of the Rd register remains unchanged.
Example:
LDR R0,=0x25579934 ;R0=0x25579934
MOVT R0,#0xAAAA ;R0=0xAAAA9934
Load and Store Instructions
External
1.0GB
Mainly used for external peripherals. device
0xA0000000
0x9FFFFFFF
External
Mainly used for external memory. 1.0GB
RAM 0x43FFFFFF
0x60000000 0x42000000
0x5FFFFFFF
tells the CPU to load (copy) into register Rd one word (32-bit or 4
bytes) of data starting from the memory location pointed to by
(stored in) Rx
Rx contains a value 0x00000000 to 0xFFFFFFFF which the
instruction will interpret as an address
Since ARM is a byte addressable CPU, each memory location
holds one byte. So, LDR will bring in 4 bytes of data from 4
consecutive memory locations ( SRAM, Flash memory or I/ O
registers)
22 Load Instruction (LDR)
Location Data
Memory to register
R5 0x40000202 0x05
0x40000203 0x34
0x40000204 0xA2
0x40000205 0x3B
Location Data
Memory to register
R5 0x40000202 0x05
0x40000203 0x34
0x40000204 0xA2
0x40000205 0x3B
Location Data
Memory to register
R5 0x40000202 0x05
0x40000203 0x34
0x40000204 0xA2
0x40000205 0x3B
STR-word
STRH-halfword
STRB-byte
Assume that R4 = 0X40000300 and R3 contain value
0X00234067.After running the following instruction;
28 STR Rx, [Rd] STR R3,[R4], What is the value contain in the memory
location pointed by R4?
AREA A_SIMPLE_PROGRAM,CODE,READONLY
ENTRY
EXPORT main
main
LDR R5,=0x40000200
LDR R3,=0X11223344
STR R3,[R5]
LDRB R7,[R5]
HERE B HERE
END
34 EXERCISE
QUESTION 10
State the contents of registers and memory location after the
execution of the following program. (Please use KEIL assembler)
MOV R2,#0x06 ;load R2 with 6
MOV R1,#0x08 ;load R1 with 8
ADD R2,R1,R2 ;R2 = R1 + R2
ADD R2,R1,R2 ;R2 = R1 + R2
LDR R5,=0x40000000 ;R5 = 0x40000000
STRB R2,[R5] ;store R2 into location pointed to by R5