使用MIPS汇编中的输入变量填充数组

时间:2016-04-19 17:29:26

标签: arrays assembly mips

我正在尝试在MIPS中创建一个整数数组,其中用户可以选择将要存储的大小和数字。出于某种原因,当数组已满时,我的程序不会跳转到结束循环。

如果解决方案显而易见,我道歉。这是家庭作业,所以我不打算抄袭完整的代码答案,而是如果我可以指向正确的方向,我会非常感激。谢谢你的期待。

    .text
        .globl __start     # for PCSPIM //main for qtspim instead of __start
__start:
        la $a0,pr1          # Ask user for amount of integers desired to be entered
        li $v0,4            # a0 = address of string
        syscall            # v0 = 4, indicates display a string

        li $v0,5            # Command to read an integer
        syscall

        sw $v0,count        # Store int read into count

        lw $t0,array        # Point t0 to array
        lw $t1,count        # Point t1 to count

M_LOOP:
        la $a0,pr2          # Prompt for integer
        li $v0,4            # a0 = address of string
        syscall            # v0 = 4 

        li $v0,5            # Command to read an integer
        syscall

        beqz $v0, E_LOOP
        sw $v0, array($t0)  # Move the integer into the array
        addi $t0,$t0,4      # Increment count by 4
        sub $t1,$t1,1           # Subtract 1 from $t1

        bnez $t0,M_LOOP

E_LOOP:
        li $v0,10              # End Of Program 
        syscall               # Call to system

        .data
array:  .space      100
pr1:    .asciiz     "Amount of integers to be entered: "
pr2:    .asciiz     "Integer to be inserted into array: "
newl:   .asciiz     "\n"
count:  .word       0

0 个答案:

没有答案