-1

嗨,我必须在 MIPS 中编写一个程序来进行冒泡排序,然后打印排序后的数组并播放音符。我无法让它在火星上执行,我想知道我需要在我的程序中添加什么:

.include "ec2_data.asm"      # load values into array

add $s0, $zero, 0x10010000
add $t0, $zero, 0x10010000 #how many times to loop


addi $t1, $zero, 0 #initilize the counter
addi $t2, $zero ,0 #initilize position x
addi $t3, $zero, 4 #initilize position y


lw $s2, $t3($s0) #get second position of $s0=y

LOOP:
addi $t0, $t0, -1 #subtract one from the counter
slt $t4, $s1, $s2 #t4 set to 1 if x > y
beqz $t4, BREAK #if t0 is zero (x<y) we dont' have to sort, so go to break

# sort:

add $t5, $zero, $s1 #temp. stores the value of x in t5
add $s1, $zero, $s2 #moves the value of y into x
add $s2, $zero, $t5 #moves the value of x into y

sw $s1, $t2($s0) #save the new x to register
sw $s2, $t3($s0) #save the new y to register

j BREAK

BREAK:
#in here: check to see if we have reached the end
#if not, increment t2 and t3 by 4 to get the next values and jump back to loop to go again

beq $t0, $zero, END #if we are done with the array, go to end
addi $t2, $t2, 4
addi $t3, $t3, 4
j LOOP #jump back to loop again

END: 

li  $v0, 1                      # print integer
syscall                      

addi $a0, $0, 0xA       # load line code into register
addi $v0, $0, 0xB       # print new line
syscall

addi $v0, $zero, 33         # midi out synchronous
addi $a0, $zero, 60         # Middle-C
addi $a1, $zero, 250        # ms
addi $a2, $zero, 120        # some instrument
addi $a3, $zero, 64     # some volume 
add $a0, $t7, $zero     # load value into $a0
syscall             # play note!


addi $t6, $t6, 4        # shift memory location by 32 bits
addi $s1, $s1, 1        # increment counter ++
j loop              # loop

Exit:

li $v0, 10                      # load exit code
syscall                         # exit 
4

1 回答 1

1

如果“无法执行”,您的意思是它对.include文件的行为很奇怪,那么您可能没有在 MARS 中选中所需的选项。转到“设置”菜单并选中“将程序计数器初始化为全局 Main(如果已定义)”复选框。这似乎是包含文件必须生效的东西 - 出于某种原因,默认情况下它没有打开。

于 2014-03-16T00:08:20.563 回答