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

  • Home
  • SEARCH
  • 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 6759017
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T13:52:45+00:00 2026-05-26T13:52:45+00:00

My program is supposed to read an integer n from the user and then

  • 0

My program is supposed to read an integer n from the user and then calculate all the divisors and if they are prime or not. I am using the Irvine 32 library. Now this is the weird part, when I enter in an even number my program executes as it is supposed to. When I enter in and odd number my program gets the error which is the title of this post.

My main Proc:

main PROC
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; This block displays greeting and newline;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
mov edx, OFFSET greeting  
call Writestring
call Crlf   

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; This block gets the integer from the user;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
call GetInt 
call Crlf

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; This block gets calculates the divsiors and prime divisors.;
; It then puts them in to an array to get ready to display.  ;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
call CalcDivisors

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; This block displays the results to the screen.             ;
; in an n-1 by 3 table.                                      ;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
call Display_Results

exit
main ENDP

Now the Proc that has produces the error:

CalcDivisors PROC uses eax ebx ecx edx esi edi
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; Function calculates divisors then pushes them on to an array;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;


mov eax,0
    mov ecx,0
    mov ebx,0
    mov edx,0
    mov esi,0
    mov edi,0

    mov ecx,n
    sub ecx,1
    mov eax,n
    mov ebx,divisors
    mov esi,OFFSET prime_arr
    mov edi,OFFSET div_arr
    push eax    

    Calc_Div:
             call dumpregs
             div ebx
             call dumpregs
             cmp edx,0
             jz Calc_Prime_Div
             inc ebx
             mov edx,0
             mov eax,n
             loop Calc_Div

    Calc_Prime_Div:
                    cmp ebx,2
                    jz Push_2_array


                    push ebx
                    push ecx

                    mov eax,0
                    mov eax,ebx
                    mov ecx,ebx
                    mov divisor_counter,ebx
                    sub ecx,2
                    mov ebx,0
                    mov ebx,prime_divisors


                    P1:
                       call dumpregs
                       div ebx
                       call dumpregs
                       cmp edx,0
                       jz Push_div_array
                       inc ebx
                       mov eax,divisor_counter
                       mov edx,0
                       loop P1

     jmp Push_prime_array

     Jump_above:
                call dumpregs
                loop Calc_div
                call dumpregs
                jmp foo

     Push_prime_array:
                      pop ecx
                      pop ebx
                      mov [esi],ebx
                      mov eax,[esi]
                      call writedec
                      add esi,4
                      mov eax,0
                      mov eax,n
                      call dumpregs
                      inc ebx
                      call dumpregs
                      jmp jump_above
                      call dumpregs
     Push_div_array:
                      pop ecx
                      pop ebx
                      mov [edi],ebx
                      mov eax,[edi]
                      call writedec
                      add edi,4
                      mov eax,0
                      mov eax,n
                      call dumpregs
                      inc ebx
                      jmp Jump_above
     Push_2_array:
                  mov [esi],ebx
                  add esi,4
                  inc ebx
                  pop eax
                  jmp Jump_above
      foo:
          ret

CalcDivisors ENDP

Now the line that is giving me the exact error is the following:

foo:
    ret

It is boggling my mind as to why it is crashing when I enter in an odd number for n and not crashing when n is even. Any suggestions?

  • 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-26T13:52:45+00:00Added an answer on May 26, 2026 at 1:52 pm

    It looks like you forget to pop some values from the stack. Check the number of push and pop instructions executed.

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

Sidebar

Related Questions

My code is supposed to read a line from the user, if the line
i want to read 2 values from user input using lisp. I want to
Working on a school project, the program is supposed to read from a text
The program is supposed to accept telnet connections on port 8888 and then send
I am supposed to write a program in JavaScript to find all the anagrams
I am supposed to write a program that gets some PNG images from the
I have simple serial port program that is supposed to read the serial port
I'm writing a program which is supposed to read two strings that can contain
I am trying to write a c++ program that would read key frames from
So, this program is supposed to take stats from Auburn's football season and compute

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.