0

基本的な「はいの場合はこれを行い、いいえの場合は終了する」アルゴリズムを mips で考えようとしています (spim シミュレーターを使用)。ただし、yes または no (この場合は y または n) が指定されているかどうかにかかわらず、bne は常に分岐します。私は mips に非常に慣れていないので、おそらく何か大きなものを見逃している...または小さなものがわからない. ここに私が持っているものがあります:

.data
    welcome:   .asciiz "Hello World!\n"
    begin: .asciiz "\nEnter a mathematical operator: "
    question: .asciiz "\nWould you like to solve a problem (y/n)? "
    back: .asciiz "You wrote "
    buffer: .space 2
    yes: .asciiz "y"
    exiting: .asciiz "exiting"

.text
.globl main
 main:   
       li $v0, 4       # syscall 4 (print_str)        
       la $a0, welcome # argument: string        
       syscall         # print the string

Loop:
    # ASK IF WANT TO SOLVE A QUESTION
    li $v0, 4     # syscall 4 (print_str)
    la $a0, question  # argument: string
    syscall

     # GET INPUT FROM USER
    li   $v0, 8   # get input
    la   $a0, buffer    # load byte space into address
    li   $a1, 2         # allot the byte space for string
    move $t0,$a0      # save string to t0
    syscall
#EDIT
  lb $t1, yes     #previously la $t1, yes
      lb $t0, 0($t0)  #new

#END EDIT

bne $t0, $t1, Exit

########IF YES, PRINT MESSAGE
########this code is only for testing and doesn't really mean anything
########so you can ignore it

    li $v0, 4       # syscall 4 (print_str)
    la $a0, begin   # argument: string
    syscall


    li $v0, 8   #get input
    la $a0, buffer  #load byte space into address
    li $a1, 20      # allot the byte space for string
    move $t0,$a0    #save string to t0
    syscall


    la $a0,back     #load and print "you wrote" string
    li $v0,4
    syscall


    la $a0, buffer  #reload byte space to primary address
    move $a0,$t0    # primary address = t0 address (load pointer)
    li $v0,4        # print string
    syscall

    j Loop

########### END IF YES

Exit:
    li $v0, 4
    la $a0, exiting
    syscall

    li $v0, 10
    syscall
    jr $ra          # return to caller

したがって、問題は、ユーザーが何を入力したかに関係なく、$t0 と $t1 が決して等しくないことです。2 つの値を正しく比較するにはどうすればよいですか?

4

1 に答える 1

1

行を変更する必要があると思います:

la $t1, yes

lb $t1, yes

于 2013-09-27T03:39:22.757 に答える