1、題目是這樣的:要求輸入乙個短字串,與事先存好的乙個長字串比較,看輸入字串是否為該字串的子串。
2、要點:字串的儲存方式。mips中字串按照byte方式儲存,字串的結束標誌是00,所以判斷乙個字串結束是可以利用$zero來判斷。但是本題比較特殊,因為主串結尾處沒有加'\n'(0a),而從鍵盤輸入的子串最後面必然會有'\n'。如果把$zero當做迴圈結束的標誌的話會造成子串永遠不會匹配,所以本題應該用0a來當做子串的結束標記。
3、程式:
.datanames:.asciiz "abedc john jack niu jop mike judy belle lucy wang"
tip:.asciiz "please input name:\n"
tip1:.asciiz "find it!\n"
tip2:.asciiz "not find!\n"
key: .space 60
.text
main:
li $v0, 4
la $a0, tip
syscall
li $v0, 8
la $a0, key
li $a1, 60
syscall
la $s1, key
la $s2, names
li $s3, 10
loop:
lb $s4, 0($s1)
lb $s5, 0($s2)
beq $s4, $s3, find
beqz $s5, nfind
bne $s4, $s5, forward
addi $s1, $s1, 1
addi $s2, $s2, 1
j loop
forward:
la $s1, key
addi $s2, $s2, 1
j loop
find:
li $v0, 4
la $a0, tip1
syscall
j end
nfind:
li $v0, 4
la $a0, tip2
syscall
end:li $v0,10
syscall
python學習筆記1 字串
小點總結 sentence input input the sentence words sentence.split 同樣適用於任何其它分隔符 9.letters list word 可以直接將word變成乙個list,其中每個元素都是乙個字母 判斷一句話中是否有正讀反讀都一樣的單詞 senten...
Python 3 7 字串 str 學習
定義字串string string1 this is a string string2 r this is a raw string 原始字串,轉義字元等均不轉義原樣輸出獲取字串長度length len string1 print length 16字串判斷if is in string1 prin...
python學習筆記1 字串拼接
較為常用的字串拼接手法主要為兩種 1.通過format函式,形如 name input 姓名 age input 年齡 salary input 工資 info information1 of 姓名 n 年齡 n 工資 n format name name age age salary salary...