Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon.

Pages: 1-

Goddamn assembly...

Name: Anonymous 2007-03-29 23:33 ID:1vfRpdnx

For an assignment, I need to use MIPS to create a program that will check a number to see if it's a perfect number (All factors add up to the number.)  I have no freaking clue how to go about doing this.  It seems like I'd have to have it check every number before it to see if it's a factor, then add them all up to check to see if they work.  This seems kinda insane since it's more of a beginner class...

How would I go about even beginning something like this?  Is there any easier way to do it?

Name: Anonymous 2007-03-29 23:39 ID:pSRBsz5S

you only have to check each number up to and including the square root of, every factor (save the root itself) thus determined will have a corresponding factor which can be worked out by simple division.

Name: Anonymous 2007-03-30 4:53 ID:RRCWbVv8

>>2
You can have a simpler set of loops by walking the whole set. SQRT is a pain if you don't have a function to do it for you.

Anyway, due to boredom:
(place value to test into $t0)
ADD $t3 $0 $0//x = 0
ADDI $t1 $0 2//$t2 = 1
loop:
ADDI $t1 $t1 1//$t1++
SLT $t2 $t0 $t1 // $t2 = ($t0 < $t1) ? 1 : 0
BEQ $t2 $0 end  //IF !$t2 GOTO end
DIV $t0 $t1     //$HI = $t0 % $t1
MFHI $t2        //$t2 = $HI
BNE $t2 $0 loop //IF !$t2 GOTO loop
ADD $t3 $t3 $t1 //$t3 += $t1
j loop          //GOTO loop
end:


Anyway, all that's left is putting the result of $t3 == $t0 into a return register and JRing your way back into the flow.

Name: Anonymous 2009-01-14 14:52

Worse then Perl

Name: Anonymous 2009-03-06 6:40

The Microsofties of course   lol How are   we to know   when we need   more Also people   using sockpuppets could   easily stall editing   efforts by purposefully.

Name: Anonymous 2009-03-06 7:22

Bash A lexicon in.

Name: Sgt.Kabu䷡旧kiman࿃瑭 2012-05-28 23:44

Bringing /prog/ back to its people
All work and no play makes Jack a dull boy
All work and no play makes Jack a dull boy
All work and no play makes Jack a dull boy
All work and no play makes Jack a dull boy
All work and no play makes Jack a dull boy
All work and no play makes Jack a dull boy
All work and no play makes Jack a dull boy

Don't change these.
Name: Email:
Entire Thread Thread List