This is Assembly Language using Visual Studio 15 MASM Create a procedure that fi
ID: 3598687 • Letter: T
Question
This is Assembly Language using Visual Studio 15 MASM
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.
PLEASE POST SOURCE CODE AS ANSWER TOO
Hint :
To fill the array with random values be sure to point to the array like the following.
mov esi,OFFSET intArray ; point to the array
mov ecx,LENGTHOF intArray ; loop counter
L1: call Random32 ; EAX = random value
call WriteInt
call Crlf
mov [esi],eax
add esi,4
; to search for negative values you have to point to the array and do a loop counter again and then you have to compare value to zero and look for negative value. If the result is yes then you will add it to the count like the following:
L2:
cmp dword ptr [esi],0 ; compare value to zero
jge L3 ; negative value?
inc count ; yes: add to count
L3:
add esi,4
loop L2
mov eax,count
call WriteDec
call Crlf
Explanation / Answer
CODE
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
IF ANY QUERIES REGARDING CODE PLEASE GET BACK TO ME
THANK YOU
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.