Dismiss Notice
Join Physics Forums Today!
The friendliest, high quality science and math community on the planet! Everyone who loves science is here!

MIPS Input/Output?

  1. Nov 19, 2012 #1
    This is the program I need to translate:
    Code (Text):

    main()
    {
        int i;
        int number=0;
        int result=0;

        for(i=0; i<10; i++){
            printf("Testing:");
            scanf("%i",&number);


            result = PerfectSquare(number);

            if(result==0)
                printf("Fail\n");
            else
                printf("%i\n",result);

        }
     
    And this is my attempt...But it's not working on the SPIM compiler.

    Code (Text):

    .data                          
    promptmsg:.asciiz "Testing:"   
    msg1:.asciiz "Fail!"   
    .text
    .globl main


    main:               #start of code

    li  $v0,4           #store 4 in $v0
    la  $a0,promptmsg       #copy RAM address of promptmsg into $a0
        syscall         #print msg
    li  $v0,5           #store 5 in $v0
    li  $t0,10          #t0 is a constant 0
    li  $t1,0           #t1 is the counter(i) for loop
    loop:
    beq     $t1,$t0,end     #if t1==10 we are done
        syscall         #call operating system to perform operation
    add     $a0,$v0,$0      #move $v0 to $a0

    jal     PerfectSquare       #call PerfectSquare function
    add     $a0,$v0,$0      #move to $a0

    li  $v0,1           #store 1 in $v0
    la  $a0,msg1        #copy RAM address of promptmsg into $a0
        syscall         # call operating system to perform operation

    li  $v0,10          #store 10 in $v0
        syscall         # call operating system to perform operation
    end:
     
     
  2. jcsd
  3. Nov 19, 2012 #2

    Mark44

    Staff: Mentor

    Where is the code for the PerfectSquare function?
    "Not working" is pretty vague. Are you getting assembler errors? If not, what output are you getting?
     
Know someone interested in this topic? Share this thread via Reddit, Google+, Twitter, or Facebook