Я пытаюсь сортировать список целых чисел с плавающей запятой в MIPS, что, я думаю, я смогу выяснить, однако каждая из этих точек с плавающей точкой соответствует счету игрока в игра. Я пытаюсь понять способ запомнить это, например, оценка Бобби составляла 12,3, после того как я отсортировал поплавки в порядке убывания, чтобы я мог вернуть что-то вроде: «Бобби 12.3, Джонни 10.2, Карл 8,8».Значения ссылок в MIPS
В настоящее время я храню поплавки в F-регистрах, когда я их читаю, и имена в блоке динамически распределенной памяти, размер которой генерируется в зависимости от того, сколько игроков пользователь рассматривает.
.data
Prompt1: .asciiz "Please enter number of players.\n"
Prompt2: .asciiz "Please enter name of a player. (Max len 21 characters).\n"
Prompt3: .asciiz "Enter player's points per game.\n"
Prompt4: .asciiz "Enter player's minutes per game.\n"
numPlayers: .space 4
.text
.align 2
.globl main
main:
subu $sp, $sp, 32
sw $ra, 0($sp)
li $v0, 4
la $a0, Prompt1
syscall
li $v0, 5
la $a0, numPlayers
syscall
move $a0, $v0
jal collect
collect:
subu $sp, $sp, 32
sw $ra, 0($sp)
sw $a0, 4($sp)#number of players
addi $t1, $zero, 21 #21 is max length of player name in characters; 21 bytes
mult $t0, 4($sp), $t1 #number of bytes you're going to need for strings for x players
lw $a0, $t0 #a0 now has number of bytes you want for all of the strings
li $v0, 9
syscall
la $t2, $v0 #store memory allocated address into t2
la $t9, $t2 #remember the head you started at for strings
#memory has been made for strings
#make memory for floats now
addi $t0, $zer0, 32 #bits for a floating int, 1 calculation per player
mult $t0, $t0, 4($sp) #number of players times floating point space
lw $a0, $t0 #a0 now has number of bytes for all the floats
li $v0, 9
syscall
la $t8, $v0 #store memory allocated address into $t8 for floats
la $t7, $t8 #remember head you started at for floats
loop:
beq $t0, $zero, sort
la $a0, Prompt2 #print string asking for a player name
la $v0, 4
syscall
la $a0, $t2 #load address of huge memory space
la $a1, 21 #max characters to read is 21
la $v0, 8 #read string and store into address supplied by $a0
syscall
addi $t2, $t2, 21 #move up 21 places in the memory for t2
#so that you're sure you're at an empty space in memory for the next string
#time to read floats
#ask for the points per game
la $a0, Prompt3 #load string to ask points per game
li $v0, 4
syscall
li $v0, 6
syscall #f0 has the float
mov.s $f1, $f0 #f1 has points per game for player 1
la $a0, Prompt5 #load string to ask minutes per game
li $v0, 4
syscall
li $v0, 6
syscall #f0 has the float
mov.d $f2, $f0 #f2 has minutes per game
div.d $f3, $f1, $f2 #divide f1 by f2 store in f3
mov.d $t8, $f3 #t8 now has the points per minute for player
addi $t8, $t8, 32 #move up 32 spots in memory
#how to associate name and player?
addi $t0, $t0, -1 #decrement counter of how many more players you need to do
b loop
sort:
#to be figured out later
Я буду помнить об этом, спасибо, я думаю, что я попытаюсь приблизиться к этому, как если бы это была структура, вроде, и поместить поплавки и строки во всю память, а затем создать указатели на следующий игрок. –