有没有人使用Mars SPIM模拟器?我在学校里用它来制作小型MIPS 32程序,我喜欢用火星调试。但是,我有一个可以在QtSPIM模拟器上运行的程序,但锁定了火星模拟器。我已从以下代码中删除了不相关的代码。在Mars中,当提示用户输入字符串时,模拟器接受该字符串的一个字符并停止。 QtSPIM接受整个字符串。 (注意:如果某些初始化看起来很奇怪,请忽略它,我在删除的代码中将其用于其他调试目的)。在这一点上,我想知道我是否超过了火星内存限制?有没有人有办法解决吗 ?
###############################################################
#
# 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
答案 0 :(得分:2)
您没有正确使用系统调用8。来自the documentation:
<强>参数强>
$a0 = address of input buffer $a1 = maximum number of characters to read
因此,在将字符串读入li $a1, 16
时,您需要在syscall
之前userString
。