Create a procedure that fills an array of doublewords with N random integers, ma
ID: 3700417 • Letter: C
Question
Create a procedure that fills an array of doublewords with N random integers, making sure the values fall within the range j...k, inclusive. When calling the procedure, pass a pointer to the array that will hold the data, pass N, and pass the values of j and K. Preserve all register values between calls to the procedure. Write a test program that calls the procedure twice, using different value for J and K. Verify your result using a debugger.
The following are the instructions. Please help me fill this out
INCLUDE Irvine32.inc
.data
intArray sdword 50 DUP(?) ; Declare an integer array
count DWORD 0 ; initialize a counter
.code
main PROC
; call Randomize from Irvine32.inc
; point to the array
; length of into ecx
; set the lower limit (j)
; set the upper limit (k)
; Call your function “fillWithRandom”
; move 5 into ebx
; move upper limit (50) into eax
; Call your function again
exit
main ENDP
fillWithRandom proc
; Input parameters:
; ESI points to the array, ECX is the size
; EBX = lower base, EAX = upper limit
; use pushad
; calculate interval size
; increment eax
; save the interval size start of Loop 1
; generates value (0 to EAX-1) Call RandomRange
; add it to the base
; move eax into the esi array
; pop eax
; move 4 into esi
; Loop back to L1
; popad
; ret
fillWithRandom endp
END main
Explanation / Answer
Answer :
data
array1 SDWORD 50 DUP(?) ;allocate room for array
;ptr3 SDWORD array1
count DD 0 ;count variable
deduct dd 0 ;deduct variable
.code
main PROC
mov ecx,50 ;move 50 to loop counter
mov esi, OFFSET array1-4 ;point to the array
loop1:
add esi,4 ;point to first element
call Random32 ;generate random 32 bit integer
call WriteInt
mov [esi],eax ;mov integer to memory
call Crlf ;create a new line
loop loop1
mov ecx,50 ;mov 50 to loop counter
mov esi,OFFSET array1-4 ;point to array
mov ebx,0
step:
add esi,4 ;point to element
mov eax,[esi] ;mov 1st element in memory to eax
cmp eax,0 ;compare eax to 0
.if (eax < 0)
inc count
.else
dec deduct
.endif
loop step
mov eax,count ;mov the count to eax
call WriteInt ;write number to screen
exit
main ENDP
END main
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.