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

This program is supposed to be in assembly language. Please use basic MASM only.

ID: 3678776 • Letter: T

Question

This program is supposed to be in assembly language. Please use basic MASM only.

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
values for j and k. Verify your results using a debugger.

Change the following code to fulfil the requirements.

INCLUDE Irvine32.inc

ARRAYSIZE = 50

.data

buffer SDWORD ARRAYSIZE DUP(0)

.code
main PROC
call Randomize

;part 1 - fill array with random numbers
mov ecx, ARRAYSIZE
mov esi, OFFSET buffer
L1:
call Random32
mov [esi], eax
add esi, TYPE buffer
loop L1

;part 2 - loop through the array, display each value, count negative numbers
mov esi, OFFSET buffer
mov ecx, ARRAYSIZE
L2:
mov eax, [esi]
cmp eax, 0
jge @F
inc counter
@@:
call WriteInt
call Crlf
add esi, TYPE buffer
loop L2

exit
main ENDP
END main

Explanation / 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

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote