views:

175

answers:

1

i m trying to write a MIPS program that will examine set of ten single digit numbers (positive, zero,or negative) that can be inputted from the terminal. After examining the numbers, only the negative numbers (with appropriate sign) along with their count needs to be outputted to the terminal.

BELOW IS MY MIPS PROGRAM

        .data
prompt: .asciiz "Input Score: "
        .align 2
HR_Neg:        .asciiz "\n negative Scores: "
        .align 2
HR_Pos:        .asciiz "\n positive Scores: "
        .align 2
HR_Negsc:        .asciiz "\n Number of Negative Scores: "
        .align 2
HR_Posc: .asciiz "\n Number of positive Scores: "
        .align 2
HR_coma: .asciiz ", "
        .align 2
HR_brk:         .asciiz "\n\n"
        .align 2
NEg:        .space 10
        .align 2
Pos:        .space 10
        .align 2

        .globl main
        .text
main:
        li $t0, 0
        la $t1, Neg
        li $t2, 0
        la $t3, pos
        li $t4, 0
        li $t5, 0
        li $t6, 0

loop:
        li $v0, 4
        la $a0, prompt
        syscall

        li $v0, 5
        syscall

        bltu $v0, 50, else
        sw $v0, 0($t1)
        addi $t1, $t1, 4
        addi $t0, $t0, 1
        b l_end

else:
        sw $v0, 0($t3)
        addi $t3, $t3, 4
        addi $t2, $t2, 1

l_end:
        addi $t4, $t4, 1
        bltu $t4, 15, loop

#output counts
        li $v0, 4
        la $a0, HR_negc
        syscall

        la $v0, 1
        add $a0, $t0, 0
        syscall

        li $v0, 4
        la $a0, HR_posc
        syscall

        la $v0, 1
        add $a0, $t2, 0
        syscall

#output neg scores
        li $v0, 4
        la $a0, HR_neg
        syscall

        la $t1, Neg
        lw $a0, 0($t1)
        li $v0, 1
+1  A: 

Please put some comments in your code so those of us who are interested can try to understand what it is trying to do.

Also, the code above has a typo in that you have a label HR_Negsc and a reference to HR_negc, which makes me think that when you say "it didn't run" you actually mean it couldn't run because it didn't link!

Step 1 - Put some comments in, particularly around the syscalls

Step 2 - Get it to actually execute

Step 3 - Now you can start to debug

There are a couple of areas that you could look at:

How much room is .space giving you, is it enough?

Is the bltu instruction that you are using to evaluate +ve and -ve correct?

How does your program end - looks like some stuff missing?

LATER COMMENT:

Hey, from the problem description of one of your previous questions I suspect that some of the code you wrote then has survived into this project. I am referring to the numbers 15 and 50.

You know, it's very hard to provide useful help when we have to guess how much you know and don't know. The more detailed the question, the more directed the answer can be. And some of the advice in answer to that other question obviously still applies.

Tony van der Peet