Question
I'm trying to run the assembly asm program code given for Chapter 7.10, Problem 5PE of Irvine's Assembly Language for x86 Processors (7th Edition) The
I'm trying to run the assembly asm program code given for Chapter 7.10, Problem 5PE of Irvine's Assembly Language for x86 Processors (7th Edition)
The slightly edited code is as follows:
________________________________
TITLE Prime Numbers (primeNum.asm) ; This program clears the screen, finds the prime numbers ; between 2 and 1000 ; finally displays the prime numbers INCLUDE Irvine32.inc SPACE=32 TRUE=1 FALSE=0 .data str1 BYTE "The prime numbers between 2 and 1000 are: ",0 arr1 DWORD 1000 DUP(?) multiple DWORD 1 inputNo DWORD 1 checkPrime DWORD 2 divisor DWORD 2 rem DWORD ? IsPrimeNo BYTE FALSE .code main PROC ; calls the procedures call Clrscr ; clears the screen ; Fill the array elements with all 0s mov ecx,1000 mov eax,0 ; EAX=0 mov edi,OFFSET arr1 cld ; Increment the EDI pointer rep stosw ; save EAX in location given by EDI call Sieve_of_eratosthenes; finds the prime numbers ; Display the prime numbers between 2 and 1000 mov edx,OFFSET str1 call WriteString ; write string str1 call Crlf mov ecx,1000 dec ecx ; there are 999 numbers mov esi,2 ; start displaying from no. 2 L1: cmp arr1[esi],0 ; an entry 0 specifies primeno jne L2 mov eax,esi call WriteDec ; write value in EAX mov AL,SPACE ; AL = call WriteChar ; leave a space L2: inc esi ; point to next array element loop L1 exit main ENDP Sieve_of_eratosthenes PROC USES eax ebx ecx esi edi ; finds the prime numbers between 2 and 1000 ; Receives: Nothing ; Returns: Nothing mov ecx,1000 dec ecx ; there are 999 numbers Start: mov eax,checkPrime ; starts from number 2 call IsPrime ; check if it is prime cmp IsPrimeNo,0 je L2 ; if jumps, not prime ; find the count of multiples of checkPrime till 1000 mov eax,1000 ; EAX=1000 mov ebx,checkPrime div ebx ; EAX contains count of multiples of checkPrime mov ecx,eax mov multiple,2 L1: mov arr1[multiple*checkPrime],1 ; write 1 in all its multiples inc multiple loop L1 L2: inc checkPrime ; check next number loop Start ret Sieve_of_eratosthenes ENDP IsPrime PROC USES eax ebx edx ; finds if a number is Prime or not ; Receives: EAX = number to be checked if prime ; Returns: Nothing Label1: ; calculate the remainder using DIV instruction mov edx,0 ; EDX stores the remainder mov ebx,divisor ; initially 2 div ebx mov rem,edx ; store the remainder in rem ; check the remainder for 0 else increment the divisor cmp rem,0 je Label2 inc ebx ; increment the divisor cmp ebx,inputNo ; check if divisor is number checked je Label3 loop Label1 Label2: mov IsPrimeNo,FALSE ; not a Prime number jmp Label4 Label3: mov IsPrimeNo,TRUE ; a Prime number Label4: ret IsPrime ENDP END main
_______________________________
When ran however, I recieve the following error: Error A2026 constant expected
This is in reference to line 63 of the code. "mov arr1[multiple*checkPrime],1 ; write 1 in all its multiples"
Please edit this code (without drastically changing the code's structure, or removing the Irvine32.inc functionality) to allow it to run.
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started