比较MIPS中的字符串

时间:2015-10-28 05:37:07

标签: converter mips roman-numerals

到目前为止,有人能告诉我我的代码有什么问题。我正在尝试创建一个程序,从用户(罗马数字)获取输入,然后将其转换为整数。到目前为止,这就是我所拥有的:

.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

loop:
lb $t0, 0($a0)   # Save $v0 value to $t0
beqz $t4, done   # if it is equal to zero end the loop
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, $t1, dCheck  # move to see if equals D

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

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

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

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

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

iCheck:
beq $t0, 'I', iChar  # if $t0 equal I go to iChar
bne $t0, $t1, 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 

我的问题是如何从用户那里获取输入并将其放入$a0,然后使用while循环?我无法将字节转到下一个位置(即MXXM转到X。)目前程序读取M,但不是X。最后,我将切换程序以对这些数字求和,并检查以前的数字是否较少(即IV)以考虑那些罗马数字,但我首先需要帮助while循环。

0 个答案:

没有答案