尝试在火星问题中使用MMIO模拟器工具显示(汇编语言错误)

时间:2018-11-16 21:35:04

标签: assembly mips32 mars

进行了一些搜索,但还没有找到确切的答案。我正在尝试以汇编语言(Mars 4.5 IDE)在MMIO仿真器上显示文本字符串。因此,在代码中,我要求用户输入一个字符串,然后跳转到一个函数,该函数将访问相应的寄存器以实现此目的。到目前为止,这是我的代码

.data

# Do an inputted string text.
    input1: .asciiz "Please enter a string: "
# Make enough space for the array.
    array1: .space 101
# Resulting string.
    output1 :.asciiz "\nInputted string from MMIO: "

.text

# Display the first input and the resulting string.
    li $v0, 4
    la $a0, input1
    syscall
    li $v0, 8
    la $a0, array1
    la $a1, 101
    syscall
# Move the address of the first element in a temporary register.
    la $t0, ($a0)

# Now store some items on the stack.
    addiu $sp, $sp, -12
    sw $ra, ($sp)
    sw $t0, 4($sp)


# Then call the function to print that output back using a mock syscall
    jal print_line

# Restore whats on the stack.
    lw $ra, ($sp)
    lw $t0, 4($sp)
    addiu $sp, $sp, 12


# Terminate the program.
    li $v0, 10
    syscall

# Define the key_getter function.
print_line:

# Now load some stuff from the stack into this area.
    lw $a1, 4($sp)

# Then gather the hard coded memory address of the display terminal
    li $a2, 0xffff0000

# At this point, $a1 holds the memory address of the first element in the string.
# And $a2 holds the memory address of the display register for the MMIO.

loop:
#####
display_not_ready:

# Load the word from our display terminal with an offset of 8.
    lw $t0, 8($a2)
# Then isolate the bit at the very end.
    andi $t0, $t0, 1
# This means if the bit is 1, then the display is ready, if not branch
# until it is ready.
    beqz $t0, loop

# Check it the 12th offset is a new line if it is branch to done.
    lw $t1, 12($a2)
    beq $t1, 10, done

# If we've reached this far then there is a character ready to print.
    sw $t1, 12($a2)
# Move to the next character in the array.
    addi $a1, $a1, 1 
# Then branch back up to loop.
    b loop
# Have our done ready.
done:
jr $ra

问题:每当我汇编代码并输入字符串时,我的程序都会陷入无限循环,围绕“ display_not_ready”的内存地址和beqz $ t0循环。

它永远不会在显示字段中将字符串显示给MMIO模拟器。

注意:在阅读了本网站上的一些答案后,是的,我始终确保已激活“连接到mips”按钮。这不是问题。

0 个答案:

没有答案