Question: The following code is supposed to get the first 1 0 0 prime numbers using assembly lang. It runs indefinitly with no progress. Could you
The following code is supposed to get the first prime numbers using assembly lang. It runs indefinitly with no progress. Could you help me fix it:
MODEL FLAT
INCLUDE ioh
STACK
DATA
primeArray DWORD DUP
CODE
MainProc PROC
mov eax, ; initialize prime to
mov dword ptr primeArray eax ; store prime
mov eax, ; initialize prime to
mov dword ptr primeArray eax ; store prime
mov ecx, ; initialize primeCount to
mov esi, ; initialize candidate to
outerLoop:
cmp ecx, ; check if primeCount
jge endOuterLoop ; if not, exit loop
mov ebx, ; initialize index to
innerLoop:
mov eax, dword ptr primeArrayebx ; load primeindex into eax
cmp eax, ; check if primeindex is end of array
je primeFound ; if so prime not found, jump to primeFound
mov edx, ; clear edx for division
mov eax, esi ; load candidate into eax
div dword ptr primeArrayebx ; divide candidate by primeindex
cmp edx, ; check if there is a remainder
je notPrime ; if no remainder, candidate is not prime, jump to notPrime
add ebx, ; increment index
jmp innerLoop ; repeat inner loop
notPrime:
add ebx, ; increment index
jmp innerLoop ; repeat inner loop
primeFound:
cmp ebx, ecx ; check if index primeCount
jle incrementCandidate ; if not, candidate is not prime, increment candidate
mov dword ptr primeArrayecx esi ; store candidate in primeArray at primeCount
add ecx, ; increment primeCount
incrementCandidate:
add esi, ; increment candidate by
jmp outerLoop ; repeat outer loop
endOuterLoop:
mov eax, ; return
ret
MainProc ENDP
END
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
