我是MIPS的新用户,我在打印我从用户那里获取的浮点数数组时遇到问题,而且我在找到最重复的浮点数方面遇到了问题。
以下是我可以接受用户输入但无法打印数组的代码。
#data declarations: declare variable names used in program, storage allocated in RAM
.data
max: .word 12
temp: .word 1
num: .space 96
input1: .asciiz "Enter a number:\n" #prints the statement
output1: .asciiz "The number that is repeated more often than any other is "
output2: .asciiz " with "
output3: .asciiz " repititions.\n"
output4: .asciiz "The array contains the following: \n"
.text
.globl main
main:
lw $t1, temp
lw $t2, max
Loop:
la $a0, input1 # $a0 = address of input1
li $v0, 4 # $v0 = 4 --- this is to call print_string()
syscall
li $v0, 6
syscall
la $t0, num
s.s $f0, 0($t0)
addi $t0, $t0, 8
addi $t1, $t1, 1
ble $t1, $t2, Loop
la $a0, output4
li $v0, 4
syscall
l.s $f12, 0($t0)
li $v0, 2
syscall
jr $ra
答案 0 :(得分:0)
.data
max: .word 3
temp: .word 1
num: .space 96
input1: .asciiz "Enter a number:\n" #prints the statement
output1: .asciiz "The number that is repeated more often than any other is "
output2: .asciiz " with "
output3: .asciiz " repititions.\n"
output4: .asciiz "The array contains the following: \n"
.text
.globl main
main:
lw $t1, temp # loop counter
lw $t2, max # upper bound
la $t0, num # address of array
Loop:
# print input prompt
la $a0, input1
li $v0, 4
syscall
# get value from the user
li $v0, 6
syscall
# move user provided value from $f0 to array
s.s $f0, 0($t0)
# move to the next position in the array, increment loop counter
addi $t0, $t0, 4
addi $t1, $t1, 1
ble $t1, $t2, Loop
# restore loop counter, and array address for printing
lw $t1, temp
la $t0, num
# print output prompt
la $a0, output4
li $v0, 4
syscall
print_loop:
# print number from the array
l.s $f12, 0($t0)
li $v0, 2
syscall
# print space
la $a0, 32
li $v0, 11
syscall
# increment loop counter and move to next value
addi $t1, $t1, 1
addi $t0, $t0, 4
ble $t1, $t2, print_loop
以下是它的工作原理:
Enter a number:
2.3
Enter a number:
3.14
Enter a number:
5.55
The array contains the following:
2.3 3.14 5.55