-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathnumsearch.s
More file actions
68 lines (54 loc) · 935 Bytes
/
Copy pathnumsearch.s
File metadata and controls
68 lines (54 loc) · 935 Bytes
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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
.global _start
_start:
// program to find a number in an array, if not found, returns -1
// r0 = pointer to list
// r1 = return value
// r2 = target
// r3 = length of list
// r4 = counter
// r5 = target value
ldr r0, =list
ldr r5, =target
// setting r5 as the value of target, and not the adress using temp register
ldr r8, [r5]
mov r5, r8
// clearing r8
and r8, r8, #0
mov r3, #10
b loop
loop:
// exit condition
cmp r3, r4
blt exit
// finding current element
ldr r2, [r0], #4
add r4, #1
// loop condition
cmp r2, r5
beq equal
b loop
equal:
ldr r1, [r0]
// resetting all registers
and r0, r0, #0
and r1, r1, #0
and r3, r3, #0
and r4, r4, #0
and r5, r5, #0
//exiting
mov r7, #1
swi 0
exit:
// resetting all registers
and r0, r0, #0
and r1, r1, #0
and r3, r3, #0
and r4, r4, #0
and r5, r5, #0
mov r7, #1
swi 0
.data
list:
.word 1,2,3,4,5,6,7,8,9,10
target:
.word 1