汇编语言打印更大,没有数组

时间:2020-04-28 02:42:38

标签: assembly mips mars

.data 
    prompt: .asciiz "Enter a number: "
    newLine: .asciiz "\n"
    max: .asciiz "\nYour max is: "
    min: .asciiz "\nYour min is: "
    theNumber: .asciiz "Entered \n"
    average: .asciiz "\nThe average of max and min is: "
    nums: .asciiz "\nNumbers >= than average: "

.text
main: 
    li $s1, 10
    li $s0, 0
    li $t0, -10000
    li $t2, 10000

    #while loop prompt for 10 numbers
    while: 
        bgt $s0, $s1, out
        li $v0, 4
        la $a0, prompt
        syscall
        li $v0, 5
        syscall
        move $t1, $v0
        jal compareMax
        jal compareMin

        addi $s0, $s0, 1
        j while

    #prints the max and min
    out: 
        li $v0, 4
        la $a0, max
        syscall
        li $v0, 1
        move $a0, $t0
        syscall
        li $v0, 4
        la $a0, min
        syscall
        li $v0, 1
        move $a0, $t2
        syscall
        jal getAverage

    #calculate the average
    getAverage:
        li $v0, 4
        la $a0, average
        syscall
        add $t3, $t0, $t2
        div $t3, $t3, 2
        li $v0, 1
        move $a0, $t3
        syscall

    #print all numbers greater or equal to average
    GreaterEqualAvg:
        li $v0, 4
        la $v0, nums
        jal compareAverage



#exit/end program                                       
exit:
    li $v0, 10
    syscall

    #print number
    print: 
        li $v0, 4 
        la $a0, theNumber
        syscall
        li $v0, 1
        move $a0, $t1
        syscall
        jr $ra      

    #compare and get max    
    compareMax:
        bgt $t0, $t1, done
        move $t0, $t1

    #compare and get min
    compareMin:
        blt $t2, $t1, done
        move $t2, $t1   


    done:
        jr $ra

我完成了获得10个数字,打印最小值和最大值,计算平均值的汇编代码的90%的工作。唯一缺少的是打印所有大于或等于平均值​​的数字。如果有人可以帮助,那就太好了!

0 个答案:

没有答案