Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Please help Write a program to find the location (index) of a data value in an a

ID: 3691830 • Letter: P

Question

Please help

Write a program to find the location (index) of a data value in an array. The array index starts from 0 (zero) not 1. For this program you are given an array of 20 values, array name: dataArray. Your program will solve a common problem, location of a particular data in an array. The data value to look for is given in R5, you may assume that R5 is already initialized with the data value we are searching for. Once you find the data in the array, leave its location (index) in R0. If the value is not found then R0 should contain 0xFFFFFFFF.

Here is some random test data: dataArray DCW 0x23, 0x85, 0xBC, 0xAB, 0x2B, 0xF4, 0xD4, 0x45, 0x5D, 0x16, 0x25, 0xC7, 0x8F, 0x9A, 0xDF, 0xB1, 0xCA, 0xFF, 0x8C, 0xAE

a) Draw the Flow chart of your program.

b) Your job is to write a complete ARM Cortex-M4 assembly language program to find the location of the value in R5 in the dataArray. Remember the location of value in R5 should be left in R0. The program should work for ANY reasonable value in R5.

Example 1 : If the value in R5 = 0x8F Result in R0 = 12

Example 2 : If the value in R5 = 0xBF Result in R0 = FFFFFFFF

Explanation / Answer

main:
mov w0, 0
ret
isvalueinarray(int, int*, int):
sub sp, sp, #32
str w0, [sp,12]
str x1, [sp]
str w2, [sp,8]
str wzr, [sp,28]
b .L4
.L7:
ldrsw x0, [sp,28]
lsl x0, x0, 2
ldr x1, [sp]
add x0, x1, x0
ldr w1, [x0]
ldr w0, [sp,12]
cmp w1, w0
bne .L5
mov w0, 1
b .L6
.L5:
ldr w0, [sp,28]
add w0, w0, 1
str w0, [sp,28]
.L4:
ldr w1, [sp,28]
ldr w0, [sp,8]
cmp w1, w0
blt .L7
mov w0, 0
.L6:
add sp, sp, 32
ret
__static_initialization_and_destruction_0(int, int):
stp x29, x30, [sp, -32]!
add x29, sp, 0
str w0, [x29,28]
str w1, [x29,24]
ldr w0, [x29,28]
cmp w0, 1
bne .L8
ldr w1, [x29,24]
mov w0, 65535
cmp w1, w0
bne .L8
adrp x0, std::__ioinit
add x0, x0, :lo12:std::__ioinit
bl std::ios_base::Init::Init()
adrp x0, std::ios_base::Init::~Init()
add x0, x0, :lo12:std::ios_base::Init::~Init()
adrp x1, std::__ioinit
add x1, x1, :lo12:std::__ioinit
adrp x2, __dso_handle
add x2, x2, :lo12:__dso_handle
bl __cxa_atexit
.L8:
ldp x29, x30, [sp], 32
ret
stp x29, x30, [sp, -16]!
add x29, sp, 0
mov w0, 1
mov w1, 65535
bl __static_initialization_and_destruction_0(int, int)
ldp x29, x30, [sp], 16
ret