0
我提示用戶輸入最多40個字符的字符串。如何計算用戶輸入的字符數?當我計算每個字符時,我需要存儲數字,大寫和小寫字母,空格以及其他任何字符的數量。我應該如何認識這些類型的角色之間的差異?如何計算使用MIPS輸入的字符數?
.text # beginning of code
.globl main # beginning of main
main: # main procedure
li $v0, 4 # print_string service number
la $a0, prompt00 # load address of prompt
syscall # print prompt
li $v0, 8 # read_string service number
la $a0, buffer # load address of buffer
la $a1, 40 # max length of 40
syscall # read_string
li $v0, 4 # print_string service number
la $a0, buffer # load address of buffer
syscall # print buffer
li $v0, 10 # using service 10, terminate
syscall # terminate
.data # beginning of data area
buffer: # container for input string
.space 40 # max length of 40 characters
newline: # variable to represent a newline
.asciiz "\n" # a newline character
prompt00: .asciiz "Enter up to 40 characters: "
謝謝。你讓我朝着正確的方向前進。這也有幫助: http://zeta.albion.edu/~dreimann/Spring2012/courses/cs354/projects/palindrome.php – taylorp0994 2015-04-02 07:58:29