从我的MIPS阵列中读取

时间:2016-03-30 22:44:01

标签: arrays assembly mips

我正在尝试在MIPS中编写一个简短的程序,仅用于个人开发,目标是提示用户输入10个整数值,将它们存储到数组中,然后在自己的行上打印所有10个值。我能够正确地将用户输入的所有整数写入数组,但是我无法正确地从数组中读取代码。

我将输入整数值1,2,3,4,5,6,7,8,9,10。打印值时,将打印10,然后打印0总共9次。

感谢您的帮助

.data
    array: .space 40
    prompt: .asciiz "Please enter a value: "
    space: .asciiz "\n"

.text
    addi $t0, $zero, 0 #Writting Array Location
    addi $t3, $zero, 0 #Printing Array Location
    la $s0, array

    loop:
        #Prompt user for a value
        la $v0, 4
        la $a0, prompt
        syscall

        #Store the value into T1
        add $v0, $zero, 5
        syscall
        add $t1, $v0, $zero

        #Store the contents of T1 into the array
        sll $t2, $t0, 2
        add $t2, $t2, $s0
        sw $t1, ($s0)

        beq $t0, 9, endLoop #After 10 entries, we want to export the list
        addi $t0, $t0, 1 #If it's not at 10 entries, we want to loop this section
    j loop

    endLoop:
        #Resetting the counters
        addi $t0, $zero, 0
        addi $t2, $zero, 0

        j printArray

    printArray:
        #Read the value from the array
        sll $t2, $t0, 2
        add $t2, $t2, $s0
        lw $t1, ($t2)

        #print the value found
        la $v0, 1
        la $a0, ($t1)
        syscall

        #Add a newline
        la $v0, 4
        la $a0, space
        syscall


        beq $t0, 9, quitProgram #After 10 entries, we will quit program
        addi $t0, $t0, 1 #If it's not at 10 entries, we want to loop this section
    j printArray

    quitProgram:
        li $v0, 10
        syscall`

0 个答案:

没有答案