-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsequential.s
50 lines (43 loc) · 1.03 KB
/
sequential.s
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
.include "functions.s"
#-----------constant-----------#
.global main
.equ _SYS_WR, 64
.equ _SYS_EX, 93
.section .rodata
msgStart: .string "Number to find: %d, the array length is %d\n"
msgEnd: .string "The index of the number is: a[%d]\n"
msgErr: .string "The number isn't in the array\n"
#-----------global symbol-----------#
.section .data
array: .byte 11, 15, 21, 23, 27, 31, 39, 40, 47, 50, 51, 52, 63
num: .byte 12
len: .byte 13
#-----------code-----------#
.section .text
main:
#startin message
la a0, msgStart
la a1, num
lb a1, 0(a1)
la a2, len
lb a2, 0(a2)
jal ra, printf
#call sequential_search
la a0, array #array address
la a1, num
lb a1, 0(a1) #number to find
la a2, len
lb a2, 0(a2) #array length
jal ra, sequential_search
#return sequential_search
blt a0, zero, else
mv a1, a0
la a0, msgEnd
jal ra, printf
beq zero, zero, _end
else:
la a0, msgErr
jal ra, printf
_end:
li a7, _SYS_EX
ecall