while循环MIPS

时间:2015-10-29 18:18:52

标签: while-loop mips roman-numerals

想看看有人能告诉我我的while循环有什么问题。我试图让程序读取用户输入的字符串(罗马数字),然后比较我的if语句到最后总结金额并将其打印为整数。现在它读取了第一个字母M(MXXI),但是当它到达X时就开始了。

.data
buffer: .space 20
onlyCaps: .asciiz "Please enter only Capital Numbers\n"
enter1: .asciiz "Number out of range. Please enter another number\n"
enter2: .asciiz "Please enter your roman numeral: "
debug:  .asciiz "reach"
M:  .asciiz "1000"
D: .asciiz "500"
C: .asciiz "100"
L:  .asciiz "50"
X: .asciiz "10"
V:  .asciiz "5"
I: .asciiz "1"

.text

main:
la  $a0, onlyCaps   # "Enter Only Capital numbers"
li  $v0, 4
syscall

la  $a0, enter2     #prompt user with "Please enter a roman numeral:"
li  $v0, 4
syscall

la $a0, buffer      #load byte space into address
li $a1, 3           # allot the byte space for string

li $v0, 8           #read user input, j
syscall

li $t4, 1           #initialized at 1 for the loop

loop:
lb $t0, 0($a0)   # Save $v0 value to $t0
add $a0, $a0, $t4   #increment the address
j mCheck

#while loop ends here

mCheck:
beq $t0, 'M', mChar  # if $t0 equal M go to mChar
bne $t0, 'M', dCheck  # move to see if equals D

dCheck:
beq $t0, 'D', dChar  # if $t0 equal D go to dChar
bne $t0, 'D', cCheck

cCheck:
beq $t0, 'C', cChar  # if $t0 equal C go to cChar
bne $t0, 'C', lCheck

lCheck:
beq $t0, 'L', lChar  # if $t0 equal L go to lChar
bne $t0, 'L', xCheck

xCheck:
beq $t0, 'X', xChar  # if $t0 equal X go to xChar
bne $t0, 'X', vCheck

vCheck:
beq $t0, 'V', vChar  # if $t0 equal V go to vChar
bne $t0, 'V', iCheck

iCheck:
beq $t0, 'I', iChar  # if $t0 equal I go to iChar
bne $t0, 'I', error

mChar:   
la  $a0, M      #puts one hundred in $t3          
li  $v0, 4
syscall
j   loop

dChar:   
la  $a0, D      # prints out 500          
li  $v0, 4
syscall
j   loop

cChar:   
la  $a0, C      # prints out 500          
li  $v0, 4
syscall
j   loop

lChar:   
la  $a0, L      # prints out 500          
li  $v0, 4
syscall
j   loop

xChar:   
la  $a0, X      # prints out 500          
li  $v0, 4
syscall
j   loop

vChar:   
la  $a0, V      # prints out 500          
li  $v0, 4
syscall
j   loop

iChar:   
la  $a0, I      # prints out 500          
li  $v0, 4
syscall
j   loop

error:  
la  $a0, enter1     # Print error meg. then back to main
li  $v0, 4
syscall
j   done

done:   
li  $v0, 10         # Exit
syscall 

0 个答案:

没有答案
相关问题