Skip to content

Commit 36f6061

Browse files
committed
copied part 4 example asm code into files
1 parent 99aa549 commit 36f6061

File tree

3 files changed

+54
-0
lines changed

3 files changed

+54
-0
lines changed

part4/lsex1.s

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
.data /* the .data section is dynamically created and its addresses cannot be easily predicted */
2+
var1: .word 3 /* variable 1 in memory */
3+
var2: .word 4 /* variable 2 in memory */
4+
5+
.text /* start of the text (code) section */
6+
.global _start
7+
8+
_start:
9+
ldr r0, adr_var1 @ load the memory address of var1 via label adr_var1 into R0
10+
ldr r1, adr_var2 @ load the memory address of var2 via label adr_var2 into R1
11+
ldr r2, [r0] @ load the value (0x03) at memory address found in R0 to register R2
12+
str r2, [r1, #2] @ address mode: offset. Store the value found in R2 (0x03) to the memory address found in R1 plus 2. Base register (R1) unmodified.
13+
str r2, [r1, #4]! @ address mode: pre-indexed. Store the value found in R2 (0x03) to the memory address found in R1 plus 4. Base register (R1) modified: R1 = R1+4
14+
ldr r3, [r1], #4 @ address mode: post-indexed. Load the value at memory address found in R1 to register R3. Base register (R1) modified: R1 = R1+4
15+
bkpt
16+
17+
adr_var1: .word var1 /* address to var1 stored here */
18+
adr_var2: .word var2 /* address to var2 stored here */

part4/lsex2.s

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
.data /* the .data section is dynamically created and its addresses cannot be easily predicted */
2+
var1: .word 3 /* variable 1 in memory */
3+
var2: .word 4 /* variable 2 in memory */
4+
5+
.text /* start of the text (code) section */
6+
.global _start
7+
8+
_start:
9+
ldr r0, adr_var1 @ load the memory address of var1 via label adr_var1 into R0
10+
ldr r1, adr_var2 @ load the memory address of var2 via label adr_var2 into R1
11+
ldr r2, [r0] @ load the value (0x03) at memory address found in R0 to register R2
12+
str r2, [r1, r2] @ address mode: offset. Store the value found in R2 (0x03) to the memory address found in R1 with the offset R2 (0x03). Base register (R1) unmodified.
13+
str r2, [r1, r2]! @ address mode: pre-indexed. Store the value found in R2 (0x03) to the memory address found in R1 with the offset R2 (0x03). Base register (R1) modified: R1 = R1+R2.
14+
ldr r3, [r1], r2 @ address mode: post-indexed. Load the value at memory address found in R1 to register R3. Then modify base register: R1 = R1+R2.
15+
bx lr
16+
17+
adr_var1: .word var1 /* address to var1 stored here */
18+
adr_var2: .word var2 /* address to var2 stored here */

part4/lsex3.s

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
.data /* the .data section is dynamically created and its addresses cannot be easily predicted */
2+
var1: .word 3 /* variable 1 in memory */
3+
var2: .word 4 /* variable 2 in memory */
4+
5+
.text /* start of the text (code) section */
6+
.global _start
7+
8+
_start:
9+
ldr r0, adr_var1 @ load the memory address of var1 via label adr_var1 into R0
10+
ldr r1, adr_var2 @ load the memory address of var2 via label adr_var2 into R1
11+
ldr r2, [r0] @ load the value (0x03) at memory address found in R0 to register R2
12+
str r2, [r1, r2, LSL#2] @ address mode: offset. Store the value found in R2 (0x03) to the memory address found in R1 with the offset R2 left-shifted by 2. Base register (R1) unmodified.
13+
str r2, [r1, r2, LSL#2]! @ address mode: pre-indexed. Store the value found in R2 (0x03) to the memory address found in R1 with the offset R2 left-shifted by 2. Base register modified: R1 = R1+R2<<2
14+
ldr r3, [r1], r2, LSL#2 @ address mode: post-indexed. Load the value at memory address found in R1 to register R3. Base register (R1) modified: R1 = R1+R2<<2
15+
bkpt
16+
17+
adr_var1: .word var1 /* address to var1 stored here */
18+
adr_var2: .word var2 /* address to var2 stored here */

0 commit comments

Comments
 (0)