12 Replies - 11425 Views - Last Post: 16 January 2014 - 08:09 PM

Modulus in MIPS

Posted 06 February 2012 - 06:29 AM

Hi guys I"ve been given an assignment in MIPS assembly where i need to create a program that takes two numbers from a user and performs several arithmetic function on those values. i don't know much about asm language so been digging around on several sites and don't really seem to be able to find what i'm looking for.

my tutor suggested i create the program in java first to help me get a better understanding of how i could implement things in asm. the main problem i'm having though is performing a modulus i.e div num1 by num2 and display the remainder, raising num1 to the power of num2 and displaying prime number between num1 and num2.

I"M NOT ASKING FOR CODE! but if any one can suggest a place i might be able to find the information i need to implement these functions or maybe what algorithms i need look at to achieve this in asm i will be eternally grateful:)

Oh also, I was only given two weeks to complete this assignment and my tutor says we wont be using ASM again after this project so as much as i"d love to take a few months to learn the ins and out of asm language I really don't need too nor do i have the time:( thanks, C

This post has been edited by Curtis Rutland: 22 March 2012 - 06:21 AM
Reason for edit:: Renamed title to be more descriptive and moved to Assembly

Replies To: Modulus in MIPS

Re: Modulus in MIPS

my tutor suggested i create the program in java first to help me get a better understanding of how i could implement things in asm.

I doubt that will help. If you don't know how to implement those things in a high-level language, you shouldn't be doing them in assembler.

Once you delve into coding, here are some key things to help:

Quote

i'm having though is performing a modulus i.e div num1 by num2 and display the remainder

Use div $r1, $r2 to get the remainder into Hi and mfhi $r1 to get Hi into a register.

Quote

raising num1 to the power of num2

Do a string of multiplications using a loop. Use mult $r1, $r2, $r3 and j Label.

Quote

displaying prime number between num1 and num2

This is a combination of the previous two tasks with a bit more complexity. You loop from num1 to num2, and test each number for primeness by looping from 2 to itself doing modulo operations. Use syscall 1 to print an integer.

The first two tasks aren't so hard. You didn't mention whether the numbers your operating on had to be retrieved from the console or hard coded into your program. Consider picking up Patterson and Hennessey's book. It's cover MIPS very well and can be read quickly.

Choose an Option…..
//--------------------------------------//
As you can see I have to take input from the user and then allow them to perform the operations in the list above. I created most of it in java no problem but it’s not really helped me tbh. I’ve managed to produce the menu and get up to option 8 fairly easily except on option 6 I need to display the remainder too. I think your suggestions have helped shed some light on things. I’ll give it a go and let you know how I get on. Once again thanks for your help and the book suggestion. Enjoy the rest of your day, thanks, C

Re: Modulus in MIPS

Posted 09 February 2012 - 09:05 AM

Ok, just a follow up on my thread about how to do division in MIPS and output the remainder for anyone else having trouble with this.
After many hours of trying to figure this out I’ve found two methods to do this. The first (I think) is the preferred method and the second method works fine but is maybe not the right way to go about things, who cares if it works it works!

The first method suggested by blackcompe in a thread above I couldn’t get to work at first, but after a day of frustration and a lot of patience I finally figured it out!

Re: Modulus in MIPS

Posted 24 December 2012 - 05:51 AM

HI There,
i have to carry out the same task as you did back in February.... how did you go past the last two options (for raising num1 to the power if num2) and also for finding the prime numbers in between them
Please your help would be very much appreciated as i need to hand these in on the 3rd of January.

Re: Modulus in MIPS

Posted 16 January 2014 - 07:06 PM

First your last post was a bit over 2 years ago, and you are adding a reply with no real use. That being said, I am removing your github url. Please do not post the completed assignment here or link to it here. This helps nobody learn.

Re: Modulus in MIPS

Posted 16 January 2014 - 07:53 PM

GunnerInc, on 17 January 2014 - 02:06 AM, said:

First your last post was a bit over 2 years ago, and you are adding a reply with no real use. That being said, I am removing your github url. Please do not post the completed assignment here or link to it here. This helps nobody learn.

That's funny because I get around 20-30 emails a year over the Xmas period since my original post asking for help with this assignment!
The reason for my post 2 years later is that someone removed my email address from a earlier post and knowing how many people are having difficulty with this assignment I thought that I would just post a link to the code for reference use ONLY!

What's your problem anyway have you got nothing better to do than monitor endless strings of text on a forum that is designed to help and educate people?

Remove the link, I don't care, It's not me you're hurting but the people that are having trouble with this stuff.

Re: Modulus in MIPS

I'm actually the one that removed the email address. I didn't notice it until someone bumped the thread today. We remove email addresses so spam bots don't pick up your email and bombard you.

Seeing a solution to homework is not the same as learning how to do it. Let's be honest- many people that see solutions are inclined to copy them, rather than learn from them. There is an honor code policy as well. Your handing out solutions freely devalues the learning experience you got, as others will have had the same class but less learning by your efforts. These people are also not as prepared for the industry as those who take the time to learn. We compete with them for jobs, and lose out far too often. Everyone pays for this. Qualified people find themselves without work. Employers have unqualified people on whom they squander money, and underqualified people find themselves in over their heads. This is why we have a good faith effort policy. Obviously we aren't changing the industry on a large scale, but we also refuse to propagate and encourage this issue.

I am closing this thread, as I don't see a reason for further off-topic discussion.