userct 0 Newbie Poster

Hello,

I'm trying to write a program using MIPS Assembly Language (I write the code in TextWrangler and run it in QTSpim)

I was wondering how I would go about checking if a number is perfect or not. I know my first lines of code may be partially incorrect but when I figure out the loop or how to check if a number is perfect it will all be easier to solve. Does anyone have any suggestions? My code so far is below and I put a note where I would put the check to see if a number is perfect.

.text
.globl main

main:
start:
        addiu   $s3, 1      # Load register $s3 with 1

        li      $v0,4       # print prompt
        la      $a0,prompt  #
        syscall


        li      $v0,5       # code 5 == read integer
        syscall             # Invoke the operating system.

    #BELOW CODE CHECKS IF INTEGER IS <1 and ENDS IF IT IS        
        sltu  d,s,t         #  if ( $s < $t )
                            #    d = 1
                            #  else
                            #    d = 0


        li      $v0,10      # code 10 == exit
        syscall             # Halt the program.
    # THIS IS THE END OF CHECKING IF INTEGER < 1 

    # BELOW WILL DETERMINE IF THE INTEGER IS PERFECT







    # END OF DETERMINING IF INTERGER IS PERFECT


        li      $v0,4       # code 4 == print perfect
        la      $a0,perfect # $a0 == address of the string
        syscall             # Invoke the exception handler.

        li      $v0,4       # code 4 == print string
        la      $a1,notper  # $a0 == address of the not perfect
        syscall             # Invoke the exception handler.


        j start             # JUMP TO THE START OF THE PROGRAM

      # ---------------------- Below may not be needed, keep for now

        sltu  d,s,t         #  if ( $s < $t )
                            #    d = 1
                            #  else
                            #    d = 0



         .data
perfect: .asciiz  "The number you entered is Perfect."
notper:  .asciiz  "The number you entered is NOT Perfect."
prompt:  .asciiz  "Please enter an Integer: "

(Not sure if this maces any sense or if it would work but: I'd set T equal to whatever the integer entered is. Then I'd start a loop and divide the integer entered by T and keep decreasing T until it is equal to one. Each time the remainder is 0 it will add the divisor to a register. If at the end all the numbers added to the register is the same as the integer entered it will print that the number is perfect.)

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.