在MARS中打印到MIPS程序的屏幕

时间:2014-03-15 21:14:13

标签: sorting mips system-calls mars-simulator

您好我必须在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 

1 个答案:

答案 0 :(得分:0)

如果&#34;无法让它执行&#34;,你的意思是它对.include文件很奇怪,那么你可能没有在MARS中检查所需的选项。转到“设置”菜单,然后选中&#34;将程序计数器初始化为全局Main(如果已定义&#34; )框。这似乎必须对包含的文件有效 - 并且出于某种原因,它默认情况下不会启用。