416F22 Chapter2 POST
416F22 Chapter2 POST
1
9/9/2022
ARM Instruction
ARM Instruction
• 3-part instruction format:
• Opcode (Mnemonic) destination, source1, source2
• EX
• MOV Rn, Op2
• Load Rn register with Op2 (operand 2)
• Op2 can be a register Rm or an immediate value of 8-bit
2
9/9/2022
ADD (Add)
ADD Rd, Rn, Op2 ; Rn+Op2 Rd
EX) MOV r1, #0x25
MOV r7, #0x34
ADD r5, r1, r7 ; r1 + r7 r1
SUB (Subtract)
SUB Rd, Rn, Op2 ; Rn - Op2 Rd
EX) MOV r1, #0x25
SUB r5, r1, #0x25 // r1 – 0x25 r5
3
9/9/2022
A simple program
1) Write a program which calculates 19 + 95
Load-Store Instructions
4
9/9/2022
Load-Store Instructions
• Example: LDR R7, [R5]
• Pre: R5=0x40000200
• Post: R7=[2bytes from 0x40000203 |2 bytes from 0x40000202|2
bytes from 0x40000201|2 bytes from 0x40000200]
• “Little Endian”
Load-Store Instructions
• Store
• Format :STR source, destination
• STR Rx, [Rd]
• “Little Endian”
10
10
5
9/9/2022
Load-Store Instructions
• Example: STR R3, [R6]
• Pre: R3=0x4152 6374, R6=0x4000 0200
• Post: Write 2bytes to 0x4000 0203; 2 bytes to 0x4000 0202; 2
bytes to 0x4000 0201; 2 bytes to 0x4000 0200]
• “Little Endian”
11
11
12
12
6
9/9/2022
• “Little Endian”
13
13
• STRB Example
• STRB R1, [R5]
• //R5=0x4000 0200 R1= 0x41526374
• “Little Endian”
14
14
7
9/9/2022
• STRH Example
• STRH R3, [R6]
//R6=0x2000 R3=0x41526374
• “Little Endian”
15
15
Manual Execution
• State the contents of RAM locations 0x92 to 0x94 after the
following program is executed
16
16
8
9/9/2022
• Z (Zero flag):
• C (Carry flag)
• V (Overflow flag)
17
17
18
18
9
9/9/2022
19
19
20
10
9/9/2022
CPUlator
• Architecture: Select ARMv7
• System: Select ARMv7 generic
• Go: Click Go
21
21
CPUlator
22
22
11
9/9/2022
CPUlator
23
23
CPUlator
24
12
9/9/2022
Load/Store – Simulation
• Load: LDR, LDRH, LDRB
• Store: STR, STRH, STRB
25
25
13