From d2edbc38cac8da52f58c5cd3da6c0c625fa05736 Mon Sep 17 00:00:00 2001 From: Santo Cariotti Date: Sat, 6 Feb 2021 19:56:36 +0100 Subject: conf: rename --- Year_1/Computer_Architecture/biggest.asm | 31 +++++++ Year_1/Computer_Architecture/counter_numbers.asm | 33 +++++++ Year_1/Computer_Architecture/division.asm | 23 +++++ Year_1/Computer_Architecture/find_elem.asm | 34 +++++++ Year_1/Computer_Architecture/lowest.asm | 31 +++++++ Year_1/Computer_Architecture/multiply.asm | 21 +++++ Year_1/Computer_Architecture/num_of_1s.asm | 20 ++++ Year_1/Computer_Architecture/odd_even_numbers.asm | 36 +++++++ .../subsequence_less_than_5.asm | 30 ++++++ Year_1/Computer_Architecture/sum_n_nums.asm | 23 +++++ Year_1/Computer_Architecture/vector_prod.asm | 103 +++++++++++++++++++++ 11 files changed, 385 insertions(+) create mode 100644 Year_1/Computer_Architecture/biggest.asm create mode 100644 Year_1/Computer_Architecture/counter_numbers.asm create mode 100644 Year_1/Computer_Architecture/division.asm create mode 100644 Year_1/Computer_Architecture/find_elem.asm create mode 100644 Year_1/Computer_Architecture/lowest.asm create mode 100644 Year_1/Computer_Architecture/multiply.asm create mode 100644 Year_1/Computer_Architecture/num_of_1s.asm create mode 100644 Year_1/Computer_Architecture/odd_even_numbers.asm create mode 100644 Year_1/Computer_Architecture/subsequence_less_than_5.asm create mode 100644 Year_1/Computer_Architecture/sum_n_nums.asm create mode 100644 Year_1/Computer_Architecture/vector_prod.asm (limited to 'Year_1/Computer_Architecture') diff --git a/Year_1/Computer_Architecture/biggest.asm b/Year_1/Computer_Architecture/biggest.asm new file mode 100644 index 0000000..a604350 --- /dev/null +++ b/Year_1/Computer_Architecture/biggest.asm @@ -0,0 +1,31 @@ +array dcd 3, 6, 10, 55, -1, 120, 10, -2, 0, 0, 13 +arr_n dcd 12 + + mov r0, #arr_n + ldr r1, [r0] ; r1 = grandezza dell'array + + mov r0, #array ; r0 = array[0] + ldr r3, [r0] ; r3 = numero maggiore + +loop + cmp r1, #0 + beq loop_end + + ldr r2, [r0] + + cmp r2, r3 + bgt assign_gt + + add r0, r0, #4 + +loop_back + sub r1, r1, #1 + + b loop + +assign_gt + mov r3, r2 + b loop_back + +loop_end + end diff --git a/Year_1/Computer_Architecture/counter_numbers.asm b/Year_1/Computer_Architecture/counter_numbers.asm new file mode 100644 index 0000000..e48f1e3 --- /dev/null +++ b/Year_1/Computer_Architecture/counter_numbers.asm @@ -0,0 +1,33 @@ +array dcd 1, 24, 0, 12, 24, 2, 24, 24 +arr_n dcd 8 +elem dcd 24 + + mov r0, #arr_n + ldr r1, [r0] ; r1 = lunghezza array + + mov r0, #elem + ldr r2, [r0] ; r2 = elemento da controllare + + mov r0, #array + mov r4, #0 ; r4 = contatore delle occorrenze + +loop + cmp r1, #0 + beq loop_end + + ldr r3, [r0] ; r3 = valore in cui punta r0 + cmp r3, r2 + beq found + +loop_back + add r0, r0, #4 ; r0 punta alla nuova word + sub r1, r1, #1 + + b loop + +found + add r4, r4, #1 + b loop_back + +loop_end + end diff --git a/Year_1/Computer_Architecture/division.asm b/Year_1/Computer_Architecture/division.asm new file mode 100644 index 0000000..6b9f80a --- /dev/null +++ b/Year_1/Computer_Architecture/division.asm @@ -0,0 +1,23 @@ +op_a dcd 42 +op_b dcd 6 + + mov r0, #op_a + ldr r1, [r0] + + mov r0, #op_b + ldr r2, [r0] + + mov r0, #0 + +loop + cmp r1, r2 + blt loop_end + + sub r1, r1, r2 + add r0, r0, #1 + + b loop + +loop_end + + end diff --git a/Year_1/Computer_Architecture/find_elem.asm b/Year_1/Computer_Architecture/find_elem.asm new file mode 100644 index 0000000..db7dc35 --- /dev/null +++ b/Year_1/Computer_Architecture/find_elem.asm @@ -0,0 +1,34 @@ +array dcd 1, 3, 2, 4, 0 +arr_n dcd 5 +elem dcd 3 + + mov r0, #arr_n + ldr r1, [r0] ; r1 <- lunghezza array + + mov r0, #elem + ldr r2, [r0] ; r2 <- elemento da cercare + + mov r0, #array ; r0 <- puntatore al primo elemento dell'array + +loop + cmp r1, #0 + beq loop_end + + ldr r3, [r0] + + cmp r3, r2 + beq found + + add r0, r0, #4 + sub r1, r1, #1 + + + b loop + +found + mov r4, #0 ; r4 = 1, quindi trovato + end + +loop_end + mov r4, #1 ; r4 = 0, quindi non trovto + end diff --git a/Year_1/Computer_Architecture/lowest.asm b/Year_1/Computer_Architecture/lowest.asm new file mode 100644 index 0000000..3dccb4a --- /dev/null +++ b/Year_1/Computer_Architecture/lowest.asm @@ -0,0 +1,31 @@ +array dcd 3, 6, 10, 55, -1, 120, 10, -2, 0, 0, 13 +arr_n dcd 12 + + mov r0, #arr_n + ldr r1, [r0] ; r1 = grandezza dell'array + + mov r0, #array ; r0 = array[0] + ldr r3, [r0] ; r3 = numero maggiore + +loop + cmp r1, #0 + beq loop_end + + ldr r2, [r0] + + cmp r2, r3 + blt assign_lt + + add r0, r0, #4 + +loop_back + sub r1, r1, #1 + + b loop + +assign_lt + mov r3, r2 + b loop_back + +loop_end + end diff --git a/Year_1/Computer_Architecture/multiply.asm b/Year_1/Computer_Architecture/multiply.asm new file mode 100644 index 0000000..1635a6d --- /dev/null +++ b/Year_1/Computer_Architecture/multiply.asm @@ -0,0 +1,21 @@ +op_1 dcd 4 +op_2 dcd 10 + + mov r0, #op_1 + ldr r1, [r0] + + mov r0, #op_2 + ldr r2, [r0] + + mov r0, #0 + +loop + cmp r2, #0 + beq loop_end + + add r0, r0, r1 + sub r2, r2, #1 + b loop + +loop_end + end diff --git a/Year_1/Computer_Architecture/num_of_1s.asm b/Year_1/Computer_Architecture/num_of_1s.asm new file mode 100644 index 0000000..ffbd4f4 --- /dev/null +++ b/Year_1/Computer_Architecture/num_of_1s.asm @@ -0,0 +1,20 @@ +num dcd 27 ; 0b11011 + + mov r0, #num + ldr r0, [r0] + mov r2, r0 + + mov r1, #32 + +loop + and r4, r2, #1 + cmp r4, #1 + bne itszero + add r3, r3, #1 +itszero + lsr r2, r2, #1 + sub r1, r1, #1 + cmp r1, #0 + bne loop + + end diff --git a/Year_1/Computer_Architecture/odd_even_numbers.asm b/Year_1/Computer_Architecture/odd_even_numbers.asm new file mode 100644 index 0000000..996fd62 --- /dev/null +++ b/Year_1/Computer_Architecture/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/Year_1/Computer_Architecture/subsequence_less_than_5.asm b/Year_1/Computer_Architecture/subsequence_less_than_5.asm new file mode 100644 index 0000000..3c266d5 --- /dev/null +++ b/Year_1/Computer_Architecture/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 diff --git a/Year_1/Computer_Architecture/sum_n_nums.asm b/Year_1/Computer_Architecture/sum_n_nums.asm new file mode 100644 index 0000000..0efcedc --- /dev/null +++ b/Year_1/Computer_Architecture/sum_n_nums.asm @@ -0,0 +1,23 @@ +arr_1 dcd 3, 2, 1, 5 +a_len dcd 4 + + mov r0, #a_len + ldr r1, [r0] ; valore N, grandezza array + + mov r0, #arr_1 ; puntatore dell'array + ldr r2, [r0] ; primo valore dell'array + mov r3, #0 + +loop + cmp r1, #0 + beq loop_end + + add r3, r3, r2 + add r0, r0, #4 ; incrementa di un byte il puntatore dell'array + ldr r2, [r0] + + sub r1, r1, #1 + b loop + +loop_end + end diff --git a/Year_1/Computer_Architecture/vector_prod.asm b/Year_1/Computer_Architecture/vector_prod.asm new file mode 100644 index 0000000..cf5e4ef --- /dev/null +++ b/Year_1/Computer_Architecture/vector_prod.asm @@ -0,0 +1,103 @@ +array1 dcd 1, 3, 4, 1 +array2 dcd 1, 0, 2, 0 +arrayn dcd 4 + + mov r0, #arrayn + ldr r0, [r0] ; r0 = lunghezza array + + mov r1, #array1 ; r1 = puntatore al primo array + mov r2, #array2 ; r2 = puntatore al secondo array + +loop + cmp r0, #0 + beq loop_end + + ldr r3, [r1] ; r3 = valore a cui punta r1 + ldr r4, [r2] ; r4 = valore a cui punta r2 + + cmp r3, #0 ; se r3 è 0, la moltiplicazione sarà 0 + beq r3_store + blt after_neg3 ; se r3 è negativo, cambia il filtro a 1 +jp_before4 + cmp r4, #0 ; se r4 è 0, la moltiplicazione sarà 0 + beq r4_store + blt after_neg4 ; se r4 è negativo, controlla se il filtro è già 1, in caso lo cambia +jp_after4 + cmp r3, r4 ; confronta r3 e r4 per fare la moltiplicazione con ciclo minore + bgt mul_r3 + ble mul_r4 + +loop_back + add r1, r1, #4 ; incrementa i puntatori e decrementa contatore + add r2, r2, #4 + sub r0, r0, #1 + mov r6, #0 + + b loop + +after_neg3 + mvn r3, r3 + add r3, r3, #1 + mov r6, #1 + b jp_before4 + +restart_r6 + mov r6, #0 + b jp_afte4 + +after_neg4 + mvn r4, r4 + add r4, r4, #1 + cmp r6, #1 + beq restart_r6 ; re inserisce il valore 0 perché fa prodotto di due negativi + + mov r6, #1 + b jp_after4 + +neg3 + mvn r3, r3 + add r3, r3, #1 + add r5, r5, r3 + b loop_back + +r3_store + cmp r6, #1 + beq neg3 + str r3, [r1] + add r5, r5, r3 + b loop_back + +neg4 + mvn r4, r4 + add r4, r4, #1 + str r4, [r1] + add r5, r5, r4 + b loop_back + +r4_store + cmp r6, #1 + beq neg4 + str r4, [r1] + add r5, r5, r4 + b loop_back + +mul_r3 + cmp r4, #1 + ble r3_store + + add r3, r3, r3 + + sub r4, r4, #1 + b mul_r3 + +mul_r4 + cmp r3, #1 + ble r4_store + + add r4, r4, r4 + + sub r3, r3, #1 + b mul_r4 + +loop_end + end -- cgit v1.2.3-18-g5258