Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

The following code is [ ARM Assembly Raspian] for generating random numbers for array[0-99]. Can you please convert it to make to generate numbers between

The following code is [ ARM Assembly Raspian] for generating random numbers for array[0-99]. Can you please convert it to make to generate numbers between 0-999 and print out Min and Max?

An example of proper execution is provided below for referrence

a[0] = 5

a[1] = 120

a[2] = 3

a[3] = 555

a[4] = 875

a[5] = 20

a[6] = 163

a[7] = 23

a[8] = 14

a[9] = 501

MINIMUM VALUE = 3

MAXIMUM VALUE = 875

Code for Generating random array numbers

.global main
.func main
main:
BL _seedrand @ seed random number generator with current time
MOV R0, #0 @ initialze index variable
writeloop:
CMP R0, #100 @ check to see if we are done iterating
BEQ writedone @ exit loop if done
LDR R1, =a @ get address of a
LSL R2, R0, #2 @ multiply index*4 to get array offset
ADD R2, R1, R2 @ R2 now has the element address
PUSH {R0} @ backup iterator before procedure call
PUSH {R2} @ backup element address before procedure call
BL _getrand @ get a random number
POP {R2} @ restore element address
STR R0, [R2] @ write the address of a[i] to a[i]
POP {R0} @ restore iterator
ADD R0, R0, #1 @ increment index
B writeloop @ branch to next loop iteration
writedone:
MOV R0, #0 @ initialze index variable
readloop:
CMP R0, #100 @ check to see if we are done iterating
BEQ readdone @ exit loop if done
LDR R1, =a @ get address of a
LSL R2, R0, #2 @ multiply index*4 to get array offset
ADD R2, R1, R2 @ R2 now has the element address
LDR R1, [R2] @ read the array at address
PUSH {R0} @ backup register before printf
PUSH {R1} @ backup register before printf
PUSH {R2} @ backup register before printf
MOV R2, R1 @ move array value to R2 for printf
MOV R1, R0 @ move array index to R1 for printf
BL _printf @ branch to print procedure with return
POP {R2} @ restore register
POP {R1} @ restore register
POP {R0} @ restore register
ADD R0, R0, #1 @ increment index
B readloop @ branch to next loop iteration
readdone:
B _exit @ exit if done
_exit:
MOV R7, #4 @ write syscall, 4
MOV R0, #1 @ output stream to monitor, 1
MOV R2, #21 @ print string length
LDR R1, =exit_str @ string at label exit_str:
SWI 0 @ execute syscall
MOV R7, #1 @ terminate syscall, 1
SWI 0 @ execute syscall
_printf:
PUSH {LR} @ store the return address
LDR R0, =printf_str @ R0 contains formatted string address
BL printf @ call printf
POP {PC} @ restore the stack pointer and return
_seedrand:
PUSH {LR} @ backup return address
MOV R0, #0 @ pass 0 as argument to time call
BL time @ get system time
MOV R1, R0 @ pass sytem time as argument to srand
BL srand @ seed the random number generator
POP {PC} @ return
_getrand:
PUSH {LR} @ backup return address
BL rand @ get a random number
POP {PC} @ return
.data
.balign 4
a: .skip 400
printf_str: .asciz "a[%d] = %d "
debug_str:
.asciz "R%-2d 0x%08X %011d "
exit_str: .ascii "Terminating program. "

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Ehs 2.0 Revolutionizing The Future Of Safety With Digital Technology

Authors: Tony Mudd

1st Edition

B0CN69B3HW, 979-8867463663

More Books

Students also viewed these Databases questions