0

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.

Riccardo
  • 289
  • 2
  • 5
  • 17
  • 1
    It seems strange to me that you could have written this but can't modify it to achieve what you want to. The case of `es'ame` should already be covered. `l'esame` is not, however. Simply look back one memory address and check for the presence of a quote. If there is one, skip the term. Similarly, look ahead one address for `esame'` checking for the quote. – David Hoelzer Feb 13 '15 at 14:12
  • @DavidHoelzer Ok but which instructions? exactly? I wrote this code years ago and I'm not an expert of the Assembly language – Riccardo Feb 13 '15 at 14:16
  • @Riccardo: So you're asking someone else to do your work, without demonstrating *any* effort to even try to do it yourself. That's not how SO works. – Scott Hunter Feb 13 '15 at 14:18
  • @Scott I simply asked for help. – Riccardo Feb 13 '15 at 14:22
  • @Riccardo: No, you did not: after David Hoelzer described what needed to be done (that is, provided help), you asked him to write the code for you, all after demonstrating no attempt on your part to solve the problem. – Scott Hunter Feb 13 '15 at 16:55

0 Answers0