简体   繁体   English

Mars MIPS Simulator 4.5 锁定用户输入读取字符串系统调用

[英]Mars MIPS Simulator 4.5 Locks up on User Input read-string syscall

Does anyone use the Mars SPIM simulator ?有人用 Mars SPIM 模拟器吗? I have used it for small MIPS 32 programs in school and I like to debug with Mars.我曾在学校将它用于小型 MIPS 32 程序,并且我喜欢使用 Mars 进行调试。 However, I have an program that works on the QtSPIM simulator, but locks up the Mars simulator.但是,我有一个可以在 QtSPIM 模拟器上运行的程序,但会锁定 Mars 模拟器。 I have removed the irrelevant code from the code below.我已经从下面的代码中删除了不相关的代码。 In Mars, when the user is prompted for a string, the simulator accepts one character of the string and stops.在 Mars 中,当提示用户输入字符串时,模拟器接受字符串中的一个字符并停止。 QtSPIM accepts an entire string. QtSPIM 接受整个字符串。 (NOTE: If some of the initialization seems odd, please ignore that, I was using that for other debug purposes in the removed code). (注意:如果某些初始化看起来很奇怪,请忽略它,我在删除的代码中将其用于其他调试目的)。 At this point, I am wondering if I have exceeded a Mars memory limit ?在这一点上,我想知道我是否超过了火星内存限制? Does anyone have a solution ?有没有人有办法解决吗 ?

###############################################################
# 
#  Runninng on Windows 7 64-bit 
# 
#  Works fine on QtSPIM v9.1.17 
# 
#  Locks up on user input in Mars 4.5 
# 
#  Program Start.  
# 
###############################################################
.data
banner1:    .asciiz "          From Rome to Arabia            " 
banner2:    .asciiz "Roman Numeral to Arabic Numeral Converter" 
prompt1:    .asciiz "Enter the Roman Numeral : "
newline:    .asciiz "\n"
output1:    .asciiz "\nThe Arabic  equivalent is " 
remind1:    .asciiz "Uppercase characters IVXLCDM are valid."
terminate:  .asciiz "Program terminated.\n"

userString:
    .space 16                          # Def 16 bytes for user input string 

stack:
    .space 16                          # Def 16 bytes for the stack 

    .globl main

    .text

###############################################################
#
# Begin program execution. 
# 
###############################################################
main:
    li      $v0,    4                  # Load Syscall to print string 
    la      $a0,    banner1            # Print the program title banner 
    syscall                            # Execute the syscall instruction 

    li      $v0,    4                  # Load Syscall to print string 
    la      $a0,    newline            # Print blank line for aesthetics 
    syscall                            # Execute the syscall instruction 

    li      $v0,    4                  # Load Syscall to print string 
    la      $a0,    newline            # Print blank line for aesthetics 
    syscall                            # Execute the syscall instruction 

    li      $v0,    4                  # Load Syscall to print string 
    la      $a0,    remind1            # Remind user of valid int values 
    syscall                            # Execute the syscall instruction 

    li      $v0,    4                  # Load Syscall to print string 
    la      $a0,    newline            # Print blank line for aesthetics 
    syscall                            # Execute the syscall instruction 

###############################################################
# 
# Initialize the variables used throughout this program. 
# 
###############################################################

    move    $t0,    $0                 # Initialize the newline character 
                                       # value to zero (0) 

    move    $t1,    $0                 # Init the initial stack pointer 
                                       # address value to zero (0) 

    move    $t2,    $0                 # Init the initial stack pointer 
                                       # address value to zero (0) 

    move    $t3,    $0                 # Init the address of the user 
                                       # input string value to zero (0) 

    move    $t4,    $0                 # Init the current character 
                                       # address byte value to zero (0) 

    move    $t5,    $0                 # Init the previous decimal 
                                       # equivalent value to zero (0) 

    move    $t6,    $0                 # Init the sum of the decimal  
                                       # equivalent values to zero (0) 

    move    $t7,    $0                 # Init the procedure variable 
                                       # for the decimal value to zero (0) 

    move    $t7,    $0                 # Init the procedure variable   
                                       # for the character value to zero (0) 

    move    $a0,    $0                 # Init the storage variable 
                                       # for the return value to zero (0)  

    move    $v0,    $0                 # Init the storage variable   
                                       # for the syscal values to zero (0) 

###############################################################
# 
# Get Roman Numeral string from the user.  
# 
###############################################################

    li      $v0,    4                  # Load Syscall to print string 
    la      $a0,    newline            # Print blank line for aesthetics 
    syscall                            # Execute the syscall instruction 

    li      $v0,    4                  # Load Syscall to print string 
    la      $a0,    prompt1            # Prompt for Roman Numeral string  
    syscall                            # Execute the syscall instruction 

    addi    $t0,    $zero,       10    # Store the ASCII newline character 

    la      $t1,    stack              # Load stack pointer address to $t1 
    move    $t2,    $t1                # Load init stack pointer address to 
                                       # $t2 for reference. 

    la      $t3,    userString         # Load address of user input string 

    li      $v0,    8                  # Load Syscall to read string 
    move    $a0,    $t3                # Move input address to syscall var 
    syscall                            # Execute the syscall instruction 

    lb      $t4,    0($t3)             # Load current character address and  
                                       # sign extend to $t4 

    bne     $t3,    $t0,       PUSH    # Check for newline terminator before 
                                       # evaluating string. If user entered 
                                       # some characters then jump to the 
                                       # PUSH label 

    j       DONE                       # User entered a blank string so end 
                                       # the program 

###############################################################
# 
# NOTE: 
#       In my opinion, the algorithm to convert from Roman Numerals to 
#       their Arabic (or, decimal ) equivalents is better accomplished 
#       once the string value of the Roman Numeral is reversed.  This 
#       is a design decision that was followed below.  
# 
###############################################################
###############################################################
# 
# Push the characters of the user string on to a stack until the 
# newline character is encounterd. 
# 
###############################################################
PUSH:
    sb      $t4,   0($t1)              # Add current character to the stack 

    addi    $t1,    $t1,          1    # Increment the stack pointer 

    addi    $t3,    $t3,          1    # Get  current character address 

    lb      $t4,    0($t3)             # Load current character value 

    bne     $t4,    $t0,       PUSH    # If the current character value is 
                                       # the newline character then all of 
                                       # the Roman Numerals are on the 
                                       # stack and ready for evaluation 

###############################################################
# 
# Initialize the sum of the decimal equivalent values and the previous 
# decimal equivalent value to zero (0) 
# 
###############################################################
    move    $t6,    $0                 # Initialize the sum of the decimal  
                                       # equivalent values to zero (0) 

    move    $t5,    $0                 # Initialize the previous decimal 
                                       # equivalent value to zero (0) 

###############################################################
# 
#  Display a message to the user and terminate the program.  
# 
###############################################################
DONE:

    li      $v0,    4                  # Load Syscall to print string 
    la      $a0,    newline            # Print a blank line for aesthetics 
    syscall                            # Execute the syscall instruction 

    li      $v0,    4                  # Load Syscall to print string 
    la      $a0,    terminate          # Program termination string  
    syscall                            # Execute the syscall instruction 

    li      $v0,    10                 # Syscall 10 for program exit 
    syscall                            # Execute the syscall instruction 

You're not using system call 8 properly.您没有正确使用系统调用 8。 From the documentation :文档中

Arguments论据

$a0 = address of input buffer $a1 = maximum number of characters to read

So you need an li $a1, 16 prior to syscall when reading the string into userString .因此,在将字符串读入userString时,在syscall之前需要一个li $a1, 16

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM