我有一个程序,它接受10个整数,然后列出所有大于或等于输入的最后一个整数的整数。我必须更改它,以便它接受浮点数而不是整数。我怎么能这样做?
.data
.align 0
array:
.space 40
messageOne:
.asciiz "Please enter 10 integers. IF you wish to stop before 10 numbers, enter '-1'."
messageTwo:
.asciiz "Enter an integer:\n "
messageThree:
.asciiz "Integers greater or equal to the last integer entered (In the order they were entered). \nThis list also includes the last number entered (bottom of list).\n"
return:
.asciiz "\n"
.text
.globl main
main:
# message one
la $a0, messageOne # Load string address of messageOne
li $v0, 4 # syscall code - print string
syscall
addi $s0, $zero, -1 # $s0 = -1
addi $s4, $zero, 10 # $s4 = 10
la $s1, array # Load array into $s1
j intake # go to intake loop
syscall
intake:
beq $s3, $s4, last # Check if input counter is a 10 stored in $s4, if so jump to "final" subroutine
# Bring in integers
la $a0, messageTwo # Load address of messageTwo
li $v0, 4 # syscall code - print string
syscall
# Integer input into temp register
# Read int from user
li $v0, 5 # syscakk code - read integer
syscall
move $t0, $v0 # move to temp at $t0
beq $t0, $s0, last # if value is -1, jump to end
sw $t0, ($s1) # store in array
move $s2, $t0 # store as last entered in $s2
addi $s1, $s1, 4 # offset address
addi $s3, $s3, 1 # increment counter
j intake # Loop intake
last:
# Print new line
la $a0, return # new line
li $v0, 4 # syscall code - print string
syscall
la $a0, messageThree # final message
li $v0, 4 # syscall code - print
syscall
# Reset a registers
la $s1, array # load array into $s1
loop:
beq $s3, $zero, quit # exit if no more intake
lw $t0, ($s1)
# use set less than to determine integers greater than last integer entered
slt $t1, $t0, $s2 # Use slt to determine ints greater than last
beq $t1, $zero, print # print if $t1 = $zero
addi $s1, $s1, 4 # offset address
addi $s3, $s3, -1 # educe from counter by 1
j loop # Loop loop
print:
# Print the value in the current offset
lw $a0, ($s1) # load current value from array
li $v0, 1 # syscall code - print
syscall
addi $s1, $s1, 4 # offset address
addi $s3, $s3, -1 # increment by -1
# Print new line
la $a0, return # new line
li $v0, 4 # syscall code - print
syscall
j loop # go back to the beginning of loop
quit:
li $v0, 10 # service code for exit
syscall
答案 0 :(得分:1)
一般来说:
$f0
到$f31
)其余的应该不难理解。