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

%3Col%20class%3D%22c2%22%20start%3D%221%22%20type%3D%221%22%3E%0A%3Cli%20class%3

ID: 3552568 • Letter: #

Question

%3Col%20class%3D%22c2%22%20start%3D%221%22%20type%3D%221%22%3E%0A%3Cli%20class%3D%22MsoNormal%22%3E%3Cspan%20lang%3D%22EN-US%22%20class%3D%22c1%22%20xml%3Alang%3D%0A%22EN-US%22%3EDraft%20a%20program%20that%20scans%20an%20array%20testing%20each%20index%20for%0Aa%20positive%20value.%20If%20a%20positive%20value%20is%20found%20%20the%20program%0Ashould%20print%20%E2%80%9Cfound%E2%80%9D%20and%20the%20value.%26nbsp%3B%20If%20no%20positive%20value%20is%0Afound%20the%20program%20should%20print%20%E2%80%9Cnot%20found.%E2%80%9D%3C%2Fspan%3E%3C%2Fli%3E%0A%3C%2Fol%3E%0A%3Cp%20class%3D%22MsoNormal%20c3%22%3E%3Cspan%20lang%3D%22EN-US%22%20class%3D%22c1%22%20xml%3Alang%3D%0A%22EN-US%22%3EUse%3A%26nbsp%3B%3C%2Fspan%3E%3C%2Fp%3E%0A%3Cp%20class%3D%22MsoNormal%22%3E%3Cbr%20%2F%3E%3C%2Fp%3E%0A%3Cp%20class%3D%22MsoNormal%20c5%22%3E%3Cspan%20lang%3D%22EN-US%22%20class%3D%22c4%22%20xml%3Alang%3D%0A%22EN-US%22%3E.data%3C%2Fspan%3E%3C%2Fp%3E%0A%3Cp%20class%3D%22MsoNormal%20c5%22%3E%3Cspan%20lang%3D%22EN-US%22%20class%3D%22c4%22%20xml%3Alang%3D%0A%22EN-US%22%3EmyArray1%20SWORD%20-12%2C4%2C1%2C23%2C-21%2C45%2C12%2C-2%3C%2Fspan%3E%3C%2Fp%3E%0A%3Cp%20class%3D%22MsoNormal%20c5%22%3E%3Cspan%20lang%3D%22EN-US%22%20class%3D%22c4%22%20xml%3Alang%3D%0A%22EN-US%22%3Esentinel%20SWORD%200%3C%2Fspan%3E%3C%2Fp%3E%0A%3Cp%20class%3D%22MsoNormal%20c5%22%3E%3Cspan%20lang%3D%22EN-US%22%20class%3D%22c6%22%20xml%3Alang%3D%0A%22EN-US%22%3E%26nbsp%3B%3C%2Fspan%3E%3C%2Fp%3E%0A%3Cp%20class%3D%22MsoNormal%20c5%22%3E%3Cspan%20lang%3D%22EN-US%22%20class%3D%22c7%22%20xml%3Alang%3D%0A%22EN-US%22%3ENext%2C%20change%20the%20array%20so%20that%20all%20values%20are%20negative%20and%0Ashow%20the%20run.%26nbsp%3B%26nbsp%3B%3C%2Fspan%3E%3C%2Fp%3E%0A%3Cp%20class%3D%22MsoNormal%20c5%22%3E%3Cspan%20lang%3D%22EN-US%22%20class%3D%22c7%22%20xml%3Alang%3D%0A%22EN-US%22%3E%3Cbr%20%2F%3E%3C%2Fspan%3E%3C%2Fp%3E%0A%3Cp%20class%3D%22MsoNormal%20c5%22%3E%3Cspan%20lang%3D%22EN-US%22%20class%3D%22c7%22%20xml%3Alang%3D%0A%22EN-US%22%3E%3Cbr%20%2F%3E%3C%2Fspan%3E%3C%2Fp%3E%0A%3Cp%20class%3D%22MsoNormal%20c5%22%3E%3Cspan%20lang%3D%22EN-US%22%20class%3D%22c7%22%20xml%3Alang%3D%0A%22EN-US%22%3E%3Cbr%20%2F%3E%3C%2Fspan%3E%3C%2Fp%3E%0A%3Cp%20class%3D%22MsoNormal%20c5%22%3E%3Cspan%20class%3D%22c8%22%3EHELP%20ME%20PLEASE%3C%2Fspan%3E%3C%2Fp%3E%0A

Explanation / Answer

Hello the program below will exit as soon as it hits the first positive number.

if you need to check all the array for positive numbers then uncommant the line above end21


INCLUDE D:masm32irvineIrvine32.inc

includelib D:masm32libkernel32.lib

includelib D:masm32libuser32.lib

includelib D:masm32irvineIrvine32.lib

.data


print BYTE 10,"found " , 0

myArray1 SWORD -12,-4,-1,-23,21,-45,12,-2

sentinel SWORD 8 ; number of elements in the array

print1 BYTE 10,"notfound ", 0



.code


main PROC

mov ebx,0 ; initalising ebx with 0

mov eax,0 ; initalising eax with 0

mov ecx,0 ; initalising ecx with 0

LOOP_READ:

mov ax, myArray1[ebx*2] ; read the value from array

cmp ax,0;compare with zero to check for positivity

jge found; negative number found print and exit

fork:

inc ebx ;increment ebx

cmp bx,sentinel[0] ; compare ebx with sentinel to check if all the values are checked

jl LOOP_READ ; jump back if there still values to be checked from array

mov edx,OFFSET print1; printing not found

cmp ecx,1; checking if a positive integer is found

je end21

call WriteString ;

jmp end21 ;

found:

mov ecx,1; flag indicating a positive number is found

mov edx,OFFSET print; printing found

call WriteString ;

call Writeint ; print the first negative value found in ax

jmp fork ;jump back to check remaining members in array

end21:

exit ; end of prgram

main ENDP


END main