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 9156555
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T12:48:08+00:00 2026-06-17T12:48:08+00:00

Here’s my attempt to write a function in TASM that returns true if a

  • 0

Here’s my attempt to write a function in TASM that returns true if a number is prime and false otherwise.

masm
model small

.data
pos db "Yes, it's Prime",13,10,"$"
negat db "No, it's not Prime",13,10,"$"

.stack 256

.code


isPrime proc
    push bp;
    mov bp,sp;
    push bx;
    push cx;

    mov bx, [bp+4]
    mov cx, 2;

    cmp bx, 0; check for zero
    je isPrimeFalse;
    cmp bx, 3; ;check for <=3
    jle IsPrimeTrue; 

    isPrimeCycle:   
        cmp bx, cx; 
        je IsPrimeTrue;
        mov ax, bx;
        xor dx, dx;
        DIV cx;
        cmp ah, 0h;
        je IsPrimeFalse;
        inc cx;
        jmp isPrimeCycle;

IsPrimeFalse:
    mov ax, 0; false
    jmp IsPrimeExit;
IsPrimeTrue:
    mov ax, 1;
IsPrimeExit:
    pop cx;
    pop bx;
    pop bp;
    ret 2;
isPrime endp

main:
    push 5;
    call isPrime
    cmp ax, 0;
    je no;
    jmp yes;
yes: ...
no: ...
end main

It works for number that are not prime, but for prime number(number>3, for example 5 above) it still shows NO.

Where is my mistake? The reminder should be stored in AH, but when i debug the code above in ollydbg(i changed the registers to x32 to make it work) the reminder is stored in edx, not in ah. Why?! is it so in the code above?

My main problem is I can’t debug my code, because I use tasm and the only good powerful debugger I know is ollydbg, but it is x32bit assembler, not 16. So i have to change registers and maybe not everything is the same…

  • 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-06-17T12:48:10+00:00Added an answer on June 17, 2026 at 12:48 pm

    For DIV CX (and generally DIV r/m16) the remainder goes to DX, the quotient to AX.

    Only for 8-bit divisor the remainder goes to AH. But you obviously wanted 16-bit divisor, since you’re zeroing DX before you divide.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Here's my code to find the prime factors of a number : #include <iostream>
Here is another spoj problem that asks how to find the number of distinct
Here is the code in a function I'm trying to revise. This example works
Here is the Javascript I currently have <script type=text/javascript> $(function() { $('.slideshow').hover( function() {
Here are my functions: function dropmenu() { $(.dropdownitem).show('slow'); } function hidemenu() { $(.dropdownitem).hide('slow'); }
Here is my code and I expect it prints out a number, instead, it
Here's the setup - I have a view that lists products. On that same
Here is a scenario: User installs .NET application that you have made. After some
Here's a sample of a SpinBox that writes its changes to underlying variables. The
Here is my function: function reCalculate(i) { document.getElementById(Q + i).value = document.getElementById(C + i).value

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.