-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathexercise_medium_5_1.s
More file actions
46 lines (35 loc) · 1.24 KB
/
exercise_medium_5_1.s
File metadata and controls
46 lines (35 loc) · 1.24 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
/*
Program to know what elements are less than or equal
in a vector.
*/
.data
Vector: .word 2, 4, 6, 6, 10, 2, 8, 7, 2, 3, 4, 5 @ vector
n: .word 12 @ length of the vector
result: .word 0 @ result <-- Example, if exists 3 num less of equal in 1,2,3,4,5,6, we seen result = 3
num: .word 5 @ num that will be the discriminator
sum: .word 0 @ sum of the elements in the vector.
.text
main: ldr r0, =Vector @ r0 <-- Vector
ldr r1, =n @ r1 <-- n
ldr r1, [r1]
ldr r2, =sum @ r2 <-- sum
ldr r2, [r2]
ldr r5, =num
ldr r5, [r5]
ldr r6, =result @ r6 <-- result
ldr r6, [r6]
mov r3, #0 @ r3 <-- #0
loop: cmp r3, r1 @ loop while r3 equal to r1
beq finlop @ branch on equa (Z==1)
ldr r4, [r0] @ r4 <--- Vector[i]
add r2, r2, r4 @ r2 <-- r2 + r4
add r0, r0, #4 @ r0 <-- r2 + 4
add r3, r3, #1 @ r3 <-- r1 + 1
cmp r4, r5 @ check if r5 is less or equal to r5
bls total @ branch on less than ((N xorV)==1)
b loop @ return to loop
total: add r6, r6, #1 @ func to count the number of r5
b loop
finlop: ldr r0, =sum @ finlop
str r2, [r0]
stop: wfi