I wrote a very simple program for mips that counts how many times a default word (in this case the word is "esame") appears in a default phrase that is "Esame: Programma di riconoscimento parole, realizzato per l'esame orale di calcolatori elettronici".
Here is the code:
.data # 0x10000000 (indirizzo di partenza)
frase: .asciiz "Esame: Programma di riconoscimento parole, realizzato per l'esame orale di calcolatori elettronici"
param: .asciiz "esame"
out1: .asciiz "Programma per il riconoscimento di una parola in una frase \n\n"
out2: .asciiz "La parola inserita come parametro appare "
out3: .asciiz " volta/e \n"
.text # 0x00400000 (indirizzo di partenza)
la $s0, frase
la $s1, param
li $t0, 0x20 # backspace
li $t8, 0x27 # apostrophe
add $s5, $zero, $zero
li $v0, 4
syscall
la $a0, out1
syscall
car1:
lbu $t1, 0($s0)
lbu $t2, 0($s1)
ori $t1, $t1, 0x20
ori $t2, $t2, 0x20
beq $t1, $t2, ok
bne $t1, $t2, dive
ok:
addi $s0, $s0, 1
addi $s1, $s1, 1
lbu $t1, 0($s0)
lbu $t2, 0($s1)
beq $t1, $zero, stamp
ori $t1, $t1, 0x20
beq $t2, $zero, ctrl
ori $t2, $t2, 0x20
ctrl:
beq $t1, $t2, ok
beq $t1, $t0, risul
bgt $t1, 0x7a, risul
blt $t1, 0x61, risul
bne $t1, $t2, dive
#beq $t1, $zero, stamp
dive:
addi $s0, $s0, 1
lbu $t1, 0($s0)
beq $t1, $t0, nuova
beq $t1, $zero, stamp
beq $t1, $t8, nuova
j dive
nuova:
la $s1, param
addi $s0, $s0, 1
#beq $s0, $s1, stamp
j car1
risul:
addi $s5, $s5, 1
j nuova
stamp:
li $v0, 4
la $a0, out2
syscall
li $v0, 1
move $a0, $s5
syscall
li $v0, 4
la $a0, out3
syscall
j fine
fine:
j fine
In this case the word "esame" appears twice within the sentence. Now I would like to add a control like this: if the default word is formed by an apostrophe, as es'ame or esame', this word should not be counted. In this second case the word "esame" would appear only once in the sentence. What instructions should I write to implement this control? Thank You.