MIPS Input and output help Floating point

2019-09-13 17:25发布

问题:

Could someone help me get the odds of my lottery program to output the answer. my program is supposed to take two inputs: one being the amount of balls in the basket (i.e. 59 balls) and two being the amount of balls picked (i.e. 4 balls picked out of 59). The while loop is supposed to run until all balls are picked (i.e. 4 times) and then take the odds (1/59)*(1/58)*etc.. to print out. I think i got most of it to work i just can't figure out how to get the odds to print out. any help will be much appreciated. thank you.

.data
     prompt: .asciiz "Enter the max number: "
     message: .asciiz "\nYour max number is: "
     picksPrompt: .asciiz "Enter your amount of picks: "
     picksMessage: .asciiz "\nYour number of picks number is: "
     finalOdds: .asciiz "Your odds are: "

.text
    # prompt the use to enter max number 
    li $v0, 4
    la  $a0, prompt
    syscall


    # get integer from the keyboard
    li, $v0, 5
    syscall


    #store the max in $t0 (ie. 59 balls)
    move $t0, $v0

    # prompt the user to enter number of picks 
    li $v0, 4
    la  $a0, picksPrompt
    syscall


    # get integer from the keyboard
    li, $v0, 5
    syscall

    #store the number of picks in $t1 (ie 3 picks)
    move $t1, $v0


    # display the max number
    li $v0, 4
    la $a0, message
    syscall


    #print or show the max number
    li $v0, 1
    move $a0, $t0
    syscall

    # display the max number
    li $v0, 4
    la $a0, picksMessage
    syscall


    #print or show the max number
    li $v0, 1
    move $a0, $t1
    syscall

#li $t0 , 59    # values assignment to temporary registers
    #li $t1 , 3

    mtc1 $t0,$f0    # move from int register to float-point register
    cvt.s.w $f0,$f0   #Convert int values to float-point values

        mtc1 $t1,$f1 
        cvt.s.w $f1,$f1 # Convert int values to float-point values

    li $t2 , 1
        li $t3 , 1

    mtc1 $t2, $f2
        cvt.s.w $f2,$f2

    mtc1 $t3, $f3
        cvt.s.w $f3,$f3

    li $t6 , 1
        mtc1 $t6, $f6
        cvt.s.w $f6,$f6

        #Start of the while loop
    li $t5, 0
        mtc1 $t5, $f5
        cvt.s.w $f5,$f5

    while: c.lt.s $f1, $f5  
    bc1f endwhile 
        #checks the intital condition and if it's false jump to endwhile
    div.s $f4,$f2,$f0           # $f4 = $f2/$f0
        mul.s $f3, $f3 ,$f4         # $f3 = $f3 * $f4

        sub.s $f0, $f0, $f6
        sub.s $f1, $f1, $f6

    b while # jump to label while
    endwhile: # your code

    # display the odds
    li $v0, 4
    la $f12, finalOdds
    syscall


    #print or show the odds
    li $v0, 2
    mov.s $f12, $f3   # Move contents of register $f3 to register $f12
    syscall