Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 1013689
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T10:08:33+00:00 2026-05-16T10:08:33+00:00

I am new to assembly language. I have written a program for taking an

  • 0

I am new to assembly language. I have written a program for taking an input and then displaying whether the number is prime or not.

Here is my source code.

.intel_syntax noprefix

.include "console.i"


.data

        Num:    .long 0

.text

        ask:    .asciz "Enter a +ve number : "
        ansp:   .asciz " is prime."
        ans:    .asciz " is not prime."

_entry:

        Prompt ask
        GetInt Num

        mov eax,Num # store Number in eax
        #mov ecx,0   # Reset ecx to 0
        mov ecx,0    # Reset ecx t0 2 for dividing.
        cdq

1:      inc ecx       # increment ecx
        mov ebx,eax   #backup eax
        Div ecx       #Divide eax by ecx

        cmp edx,0     #if remainder is zero num is not prime
        je 2f
        mov edx,0     #reset edx to 0
        mov eax,ebx   #reset eax to Num

        cmp eax,ecx   if ecx is less than number.
        jl 1b


        #Prime
        PutInt Num
        Prompt ansp
        jmp 3f

2:      #Not Prime
        PutInt Num
        Prompt ans

3:      PutEol
        ret

.global _entry

.end

When ever I run the program it always displays it is not a prime number.

For example if I input 7 it displays 7 is not prime.

I am using Intel x86 Architecture and devloping it on Ubuntu.

Edit 1 : According to Darron, I have initalized ecx register to 1 and then incremented ecx to 1 so that it starts the loop from 2.

But the problem is when I enter 9 it shows me 9 is prime. I don’t know what’s wrong with my logic.

Edit 2 : I am storing my number in eax, and then I divide it by ecx and then finally check if the reaminder is zero in edx register.

Thanks.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-16T10:08:33+00:00Added an answer on May 16, 2026 at 10:08 am

    I have solved my problem using gdb(GNU Project Debugger).

    In my logic I was dividing the number up to the given number, for example if I input 15 the logic was dividing the number upto 15, but for prime numbers we have to divide up to number -1 ie(15-1).

    Here is my updated block of loop.

    1:      inc ecx 
            mov eax,ebx 
            Div ecx
    
            cmp edx,r
            je 2f
    
            mov edx,0
            mov eax,ebx
            Sub eax,1
            cmp ecx,eax
            jl 1b
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am new to assembly language. It seems that gcc doesn't have _bittestandset function
I'm new to assembly language, and would like to learn. I have Vista-64 (will
Ok, here we go.. I have a control, which in the assembly.. lets call
does anyone have any resources for learning assembly language on x86? I'm trying to
I have a little game written in C#. It uses a database as back-end.
I am a DSP, embedded software programmer, looking to improve my assembly language programming
New class is a subclass of the original object It needs to be php4
New to javascript/jquery and having a hard time with using this or $(this) to
New to xml. Looking for XPath to search a xml file with python ElementTree
New to silverlight. Traditionally if I were to design a wizard-like process where a

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.