summaryrefslogtreecommitdiff
path: root/I_anno/Architettura_Elaboratori
diff options
context:
space:
mode:
authorSanto Cariotti <dcariotti24@gmail.com>2020-05-10 18:02:05 +0200
committerSanto Cariotti <dcariotti24@gmail.com>2020-05-10 18:02:05 +0200
commit4527eda2f32a3d200b03aee03ea108aa49262589 (patch)
treee1e61ddc7880efaa46bdaaf8a01397033cffabfb /I_anno/Architettura_Elaboratori
parentf3f1bd47f8af2c5c445d2201792d82dd02b24c9b (diff)
feat: add ram manipulation exercises
Diffstat (limited to 'I_anno/Architettura_Elaboratori')
-rw-r--r--I_anno/Architettura_Elaboratori/odd_even_numbers.asm36
-rw-r--r--I_anno/Architettura_Elaboratori/subsequence_less_than_5.asm30
2 files changed, 66 insertions, 0 deletions
diff --git a/I_anno/Architettura_Elaboratori/odd_even_numbers.asm b/I_anno/Architettura_Elaboratori/odd_even_numbers.asm
new file mode 100644
index 0000000..996fd62
--- /dev/null
+++ b/I_anno/Architettura_Elaboratori/odd_even_numbers.asm
@@ -0,0 +1,36 @@
+arr_n dcd 8
+array dcd 1, 2, 4, 6, -5, 8, 7, 3
+s_arr dcd 0
+
+ mov r0, #arr_n
+ ldr r0, [r0]
+ mov r1, r0
+
+ mov r4, #1 ; 0 = even, 1 = odd
+ mov r6, #0 ; number of elements on new sequence
+
+ mov r2, #s_arr
+
+ mov r1, #array
+
+loop
+ cmp r0, #0
+ beq end_program
+ ldr r3, [r1], #4
+ mov r5, r3
+
+ and r5, r3, #1
+ cmp r5, r4 ; check if element stored in r3 is odd or even
+ beq data_store
+subn_loop
+ sub r0, r0, #1
+ b loop
+
+data_store
+ str r3, [r2], #4
+ add r6, r6, #1
+ b subn_loop
+
+end_program
+ str r6, [r2]
+ end
diff --git a/I_anno/Architettura_Elaboratori/subsequence_less_than_5.asm b/I_anno/Architettura_Elaboratori/subsequence_less_than_5.asm
new file mode 100644
index 0000000..3c266d5
--- /dev/null
+++ b/I_anno/Architettura_Elaboratori/subsequence_less_than_5.asm
@@ -0,0 +1,30 @@
+arr_n dcd 6
+array dcd 3, 6, 7, 2, 9, 0
+s_arr dcd 1
+
+ mov r0, #arr_n
+ ldr r0, [r0]
+ mov r1, r0
+
+ mov r2, #s_arr
+ mov r1, #array
+ mov r4, #0 ; number of elements on new sequence
+
+loop
+ cmp r0, #0
+ beq end_program
+ ldr r3, [r1], #4
+ cmp r3, #5 ; number to compare
+ blt data_store
+subn_loop
+ sub r0, r0, #1
+ b loop
+
+data_store
+ str r3, [r2], #4
+ add r4, r4, #1
+ b subn_loop
+
+end_program
+ str r4, [r2]
+ end