Does anyone use the Mars SPIM simulator ? I have used it for small MIPS 32 programs in school and I like to debug with Mars. However, I have an program that works on the QtSPIM simulator, but locks up the Mars simulator. 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. QtSPIM accepts an entire string. (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. 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
.