2016-03-30 4 views
0

誰も火星SPIMシミュレータを使用していますか?私は学校で小さなMIPS 32プログラムのために使ってきました。私は火星でデバッグするのが好きです。しかし、私はQtSPIMシミュレータで動作するプログラムを持っていますが、火星シミュレータはロックされています。私は以下のコードから無関係のコードを削除しました。 Marsでは、ユーザが文字列の入力を求められると、シミュレータは文字列の1文字を受け入れて停止します。 QtSPIMは文字列全体を受け入れます。 (注:いくつかの初期化が奇妙に思える場合は、無視してください。削除されたコードで他のデバッグ用に使用していました)。この時点で、私は火星の記憶限界を超えているのだろうかと疑問に思っていますか?誰にも解決策がありますか?火星MIPSシミュレータ4.5は、ユーザ入力にロックする

############################################################### 
# 
# 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 

答えて

2

システムコール8は適切に使用されていません。 the documentationから:userStringに文字列を読み込むとき

引数

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

だから、前syscallli $a1, 16を必要としています。

+0

マイケルさん、ありがとうございました。私は難しい方法を学ぶことに驚いている。私は完全にそれを忘れてしまった。 –

関連する問題