I want to be able to write a program that repeatedly prompts the user to enter an integer. The program determines if that numbers is perfect and then writes out a message saying if it is or not, then prompts once again.
I'll end the loop (and the entire program for that matter) when the user enters an integer which is less than one.

I'll try to use mnemonic names for registers (like $s0, $t3) and any extended assembly instructions but will ignore branch delays and load delays.

Does anyone have any suggestions on how exactly I would go about this? I know I obviously need a loop but am relatively new to this to I'm not sure how to really prompt the user for one and run it.

Thanks for any assistance.

Recommended Answers

All 4 Replies

Which version of assembly?

Sounds like you're trying to use MIPS, which MIPS are you trying to use? MIPS I, III, IV, V ?
And what do you mean by "but will ignore branch delays and load delays"? Those are architectural details, are you
talking about using synthesized instructions (like assembler instructions) to make it seem like you're ignoring those details?

I'm using MIPS althought I'm not sure what version. Not sure if this makes a difference but I run it with the latest QTSpim on my Mac. By ignor branch delays I think that really means not to use them if that's possible.

I have this just to start of and structure my program. I'll have to create a loop where that first prompt is included in but I'm wondering how to check if the number is perfect or not.
Any suggestions on what methods I'll use? I'll be using mnemonic names for the registers like I've started doing.

.text
.globl main

main:

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


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


        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 not perfect
        la      $a1,notper  # $a0 == address of the string
        syscall             # Invoke the exception handler.


        li      $v0,10      # code 10 == exit
        syscall             # Halt the program.

         .data
perfect: .asciiz  "The number you entered is NOT Perfect."
notper:  .asciiz  "The number you entered is Perfect."
prompt:  .asciiz  "Please enter an Integer: "
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.