我的MIPS代码有点问题,因为这不适用于“a”,我解释得更好......如果我写的话:
有人可以给我一个解决方案吗?这是我的代码:
.data
m1: .asciiz "Give me a string: "
m2: .asciiz "\nThe letter '"
m3: .asciiz "' has the biggest number of occurrences, is present "
m4: .asciiz " times."
.align 2
myArray: .space 104
.text
.globl main
main:
li $v0, 4
la $a0, m1
syscall
addi $sp, $sp, -256
move $s0, $sp
move $a0, $sp
li $a1, 255
li $v0, 8
syscall
move $a0, $s0
jal check_case
move $a0, $v0
move $a1, $v1
jal analizza_stringa
move $a0, $v0
move $a1, $v1
jal stampa_risultato
end_program:
li $v0, 10
syscall
check_case:
move $t0, $a0
while:
lb $t1, ($t0)
beq $t1, 32, ignore_value_and_continue
beq $t1, 10, exit_check_case
bge $t1, 97, continue_check_case
bge $t1, 65, change_case
change_case:
addi $t2, $t1, 32
sb $t2, ($t0)
ignore_value_and_continue:
continue_check_case:
addi $t2, $t2, 1
addi $t0, $t0, 1
j while
exit_check_case:
move $v0, $t0
move $v1, $t2
jr $ra
analizza_stringa:
li $t1, 0
li $t2, 0
li $t3, 0
li $t4, 0
move $t7, $a0
sub $a0, $a0, $v1
sub $t7, $t7, $v1
while_string:
lb $t0, ($a0)
beq $t0, $zero, check_best
beq $t1, 32, ignore_value_and_continue2
ignore_value_and_continue2:
beq $t0, 10, check_best
subi $t3, $t0, 97
mul $t4, $t3, 4
move $t6, $t7
while_occorrenza:
beq $t1, 10, continue
lb $t1,($t6)
bne $t1, $t0, continue2
addi $t5, $t5, 1
continue2:
addi $t6, $t6, 1
j while_occorrenza
continue:
sw $t5, myArray($t4)
li $t5, 0
li $t3, 0
li $t1, 0
addi $a0, $a0, 1
j while_string
check_best:
li $t0, 0
lw $t1, myArray($t0)
addi $t0, $t0, 4
while_check_best:
beq $t0, 104, exit_check
addi $t5, $t5, 1
lw $t4, myArray($t0)
bge $t4, $t1, scambia
j continue_check
scambia:
blt $t4, $t2, continue_check
move $t2, $t4
add $t3, $t5, 97
continue_check:
addi $t0, $t0, 4
j while_check_best
exit_check:
move $v0, $t3
move $v1, $t2
jr $ra
stampa_risultato:
move $t0, $a0
li $v0, 4
la $a0, m2
syscall
li $v0, 11
move $a0, $t0
syscall
li $v0, 4
la $a0, m3
syscall
li $v0, 1
move $a0, $a1
syscall
li $v0, 4
la $a0, m4
syscall
jr $ra