MIPS readint syscall无法接收输入

时间:2018-10-02 14:46:53

标签: assembly mips qtspim

我有一项工作要在QTSpim中写出一个最小的int函数。似乎当我尝试放入2个用户输入(即0和4)时,它会完全绕开我的输入,并且由于我的功能严重依赖于我的用户输入,因此我无法测试我的代码是否有效。有人可以帮我解决这个问题吗?我的代码和正确的预期输出如下所示。

# arrayFunction.asm
       .data 
array: .word 8, 2, 1, 6, 9, 7, 3, 5, 0, 4
newl:  .asciiz "\n"

       .text
main:
    addi $a1, $zero, 10
    li $v0, 4 # Print the original content of array
    la $a0, array
    la $a3, array #to store so that we can modify a0 later
    jal printArray # prints integer array


    # setup the parameter(s)
    # call the printArray function

    # Ask the user for two indices
    #li   $v0, 5            # System call code for read_int
    #syscall           
    #addi $t0, $v0, 0       # first user input in $t0

    #li   $v0, 5            # System call code for read_int
    #syscall           
    #addi $t1, $v0, 0       # second user input in $t1

    addi $t0, $zero, 0      # simulate first input
    addi $t1, $zero, 4.     # simulate 2nd input

    # Call the findMin function
    # setup the parameter(s)

    sll $t0, $t0, 2     #multiply by 4 to increment first pointer
    sll $t1, $t1, 2     #multiply by 4 to increment 2nd pointer
    add $a1, $t1, $a0   #make final address for larger pointer
    add $a0, $t0, $a0   #make final address for smaller pointer
    addi $t4, $zero, 99 #set the first lowest element to 99, magic number
    #modify arguments before sending in but actually its mutation

    jal findMin # call the function


    # Print the min item
    # place the min item in $t3 for printing

    # Print an integer followed by a newline
    li   $v0, 1         # system call code for print_int
    addi $a0, $t3, 0    # print $t3
    syscall             # make system call

    li   $v0, 4         # system call code for print_string
    la   $a0, newl      # 
    syscall             # print newline

    #Calculate and print the index of min item


    # Place the min index in $t3 for printing   
    sub $t3, $v0, $a3 
    srl $t3, $t3, 2

这是我应该在控制台上看到的输出:

8216973504 #original array
0 #first user input
4 #2nd user input
1 #Min element
2 #index of element

0 个答案:

没有答案