newGains 0 Newbie Poster

pretty new to programming in assembly but my assignment is to write a GCD program but my program works sometimes and sometimes it doesn't work. if i put the smaller number first then the larger number i don't get the correct GCD but if i do the opposite i get the right answer
example:
if i enter 209 then 2585 it says the GCD is 209, which is incorrect
but, if i enter 2585 then 209 it says the GCD is 11 which is correct
looking for some guidance on to why my program is working one way and not the other
here is my code:

# Lab 2 - GCD
#
    .data
A:  .word 0
B:  .word 0
Prompt: .asciiz "Type integer for A, press ENTER. Type integer for B, press ENTER \n"
Result: .asciiz "\nThe GCD is "

    .globl main
    .text

main:
    li $v0,4        # syscall to print String
    la $a0,Prompt       # load address of Prompt
    syscall         # print Prompt String

    li $v0,5        # syscall to read integer
    syscall         # read first intger
    move $a0,$v0        # move integer in $v0 to $a0

    li $v0,5        # syscall to read integer
    syscall         # read next integer
    move $a1,$v0        # move integer in $v0 to $a1

baseCase:
    bne $a1,$zero,recCase   # if $a1 != 0 branch to recCase
    li $v0,4        # syscall to print String
    la $a0,Result       # load address of Result
    syscall         # print result String

    lw $a0,A        # load A
    li $v0,1        # syscall to print integer
    syscall         # print A

    li $v0,10       # terminate prog running
    syscall         # return control to system

recCase:
    sub $sp,$sp,12      # push stack
    sw $ra,0($sp)       # save return address
    sw $a0,4($sp)       # save registers
    sw $a1,8($sp)       
    move $t0,$a1        # move $a1 to $t0
    rem $a1,$a0,$a1     # $a1 =  A%B
    sw $t0,A        # store A for output
    jal baseCase        # jump to baseCase

    lw $ra,0($sp)       # load main
    addi $sp,$sp,12     # 
    jr $ra          # return to main
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.