Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # finding element in an array
- .data
- array: .word 3, 5, 7, 9, 11, 13, 15
- n: .word 7 # length of array
- key: .word 13
- .text
- start:
- la x5, array
- lw x6, n # array length
- lw x7, key
- li x8, 0
- search:
- beq x8, x6, not_found
- lw x9, 0(x5)
- beq x7, x9, found
- addi x5, x5, 4 # jump to next element
- addi x8, x8, 1 # add 1 to counter
- j search
- not_found:
- li x1, 0 # update result = 0
- j end
- found:
- li x1, 1 # update result = 1
- j end
- end:
- nop
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement