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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T10:39:13+00:00 2026-05-26T10:39:13+00:00

Thank everyone for the help I have made some really good changes but now

  • 0

Thank everyone for the help I have made some really good changes but now it gives me an answer of +4198498 instead of 5 for the first set of values which I know is wrong. Did i push something wrong or did not pop a reg correctly? I cleaned up the stack right by using the ret 8 which should clean up the stack for the next call is that right?

Here is what I have so far:

TITLE MASM GCD                      (GCD.asm)


; Description:GCD recursive
; 
; Revision date:

INCLUDE Irvine32.inc
.data
myMessage BYTE "Assignment 7 GCD Recursive style",0dh,0ah,0
myMess2   BYTE "GCD = " ,0dh,0ah,0


;first set of nums
val1 DWORD  5
val2 DWORD  20

;second set of nums
val3 DWORD  24
val4 DWORD  18

;3rd set
val5 DWORD  11
val6 DWORD  7

;4th set
val7 DWORD  432
val8 DWORD  226

;5th set
val9 DWORD  26
val10 DWORD  13

.code
main PROC
    call Clrscr  

    mov  edx,offset myMessage
    call WriteString        ;write message
    call Crlf               ;new line
    push val1
    push val2
    call GCD

    exit
main ENDP

;------------------------------------------------
GCD PROC,
; This finds GCD
; Gets values from stored values
;returns NA

;------------------------------------------------

        xor edx,edx
        mov eax,dword ptr[esp+8] ;dividend
        mov ebx,dword ptr[esp+4] ;divisor
        div ebx              ;eax/ebx
        cmp  edx,0           ;remainder in edx
        je   L1              ;yes: quit
        call GCD             ;no: call GCD agian
    L1:
        mov eax,ebx          ;move the divisor into eax for printing i.e GCD    
        mov  edx,offset myMess2
        call WriteString
        call WriteInt        ;Display GCD WriteInt uses EAX = qutent
        call crlf
        ret 8                ;clean up the stack
GCD ENDP

END main
  • 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-26T10:39:13+00:00Added an answer on May 26, 2026 at 10:39 am

    First I see a few errors and bad habits:

    GCD PROC,
        dividend:DWORD,
        divisor:DWORD
    

    Declaring local variables for your procedures is a bad habit in my opinion. (result from high level languages)

    You need to put that in your data segment. Additionally there’s a syntax error, the dwords are uninitialized thus you should declare them like this:

    .DATA ?
    dividend  dword ?
    divisor dword ?
    

    You also have a problem with the registers for the div instruction:

    xor edx,edx
    mov eax,xxx ;dividend
    mov ebx,yyy ;divisor
    div ebx     ;eax/ebx
    cmp  edx,0  ;remainder in edx
    

    Now to use your sets of values and divide them you ave different choices:

    1-move them manually 1 by 1 in your registers

    mov eax,dword ptr[val01] ;dividend
    mov ebx,dword ptr[val02] ;divisor
    

    2-you push them directly on the stack (like function parameters)

    push val01
    push val02
    call GDC
    
    ;in GDC proc
    mov eax,dword ptr[esp+8]
    mov ebx,dword ptr[esp+4]
    

    3-put them in an “array” and loop through them

    exercise for you
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Good evening everyone! I am working on learning some java and I have made
First, I would to thank everyone for all the help they provide via this
THIS PROBLEM IS NOW SOLVED. THANK YOU TO EVERYONE WHO REPLIED. Hello, I am
I have another SQL/access 2007 question that seems really basic but I'm not sure
thank you everyone for helping me out with this. i am new to ruby
Thanks to everyone out there helping newbies like me. So far I have this:
Thank you all for your help. A number of you posted (as I should
I have a dll that I have made that works perfectly. I need to
i have a java chat server & client, that works fine. I made a
I have a piece of jQuery that will not load at all for some

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.