Hey there,

I am writing MIPS assembly for computing the gcd of two given numbers (recursively), but am struggling!

I vaguely understand changing the frame point counter, stack pointer etc. but I'm really at sea with how to implement the algorithm recursively (e.g. how to check if each number is even or odd, then somehow call the code again and again until input1=input2)

Any assistance will be very appreciated!

Thanks

nikki_2000b@hot
0
Newbie Poster

## Recommended Answers

Jump to PostThe stack is just a piece of memory where you can

pushvalues on the end orpopvalues from the end. The $sp register always points to thenextavailable spot.

Visually:`[ ] [ ] [ ] <-- $sp [-7] [12]`

If we push 42 onto the stack, …

Jump to PostYour teacher is having you implement the Binary GCD Algorithm in assembly? Yoinks.

Well, you can test any positive number for even or odd by looking at the LSB of the number.

`# $s0 : number to check for odd/even # $t0 : result: 1 = odd, 0 = …`

Jump to Post`# CSIT 311: MIPS - Euclidean Iterative # #int gcd_recursive(int a, int b) #{ # if ( b == 0 ) # return a; # # else # return gcd_recursive(b, a % b); #} .text .globl main main: # Prompt for user input la $a0, prompt # $a0 holds prompt …`

## All 10 Replies

Duoas
1,025
Postaholic
Featured Poster

nikki_2000b@hot
0
Newbie Poster

Duoas
1,025
Postaholic
Featured Poster

Striker9
0
Newbie Poster

Duoas
1,025
Postaholic
Featured Poster

nikki_2000b@hot
0
Newbie Poster

Duoas
1,025
Postaholic
Featured Poster

nikki_2000b@hot
0
Newbie Poster

bStiffler582
0
Newbie Poster

Duoas
1,025
Postaholic
Featured Poster

Be a part of the DaniWeb community

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