Doubt in replacing character in string assembly (MIPS)
I have to make a code in assembly mips that requests a sentence and if the sentence contains the character -
it is replaced by the character *
. So far I have only been able to get to this code:
.data
buffer: .space 256 # Aloca 256 bytes de espaço
msg1: .asciiz "Digite uma frase (máximo de 256 caracteres): "
check: .asciiz "*"
result: .asciiz "Você digitou: "
.text
main:
la $a0, msg1 # Carrega no endereço $a0 o conteúdo de msg1
li $v0, 4 # Imprimi o conteúdo de msg1
syscall
li $v0, 8 # Pega a entrada
la $a0, buffer
li $a1, 256
move $t0, $a0 # Salva a string digitada em $t0
syscall
la $a0, result # Carrega e mostra "sua resposta" que é uma string
li $v0, 4 # Imprimi a string
syscall
la $a0, buffer
move $a0, $t0
li $v0, 4 # Imprimi a string
syscall
end:
li $v0, 10 # Encerra o programa
syscall
6
Author: Diego Souza, 2016-12-13
1 answers
I hope this is what you are looking for
.data
buffer: .space 256 # Aloca 256 bytes de espaço
msg1: .asciiz "Digite uma frase (máximo de 256 caracteres): "
check: .asciiz "*"
result: .asciiz "Você digitou: "
.text
main:
la $a0, msg1 # Carrega no endereço $a0 o conteúdo de msg1
li $v0, 4 # Imprimi o conteúdo de msg1
syscall
li $v0, 8 # Pega a entrada
la $a0, buffer
li $a1, 256
move $t0, $a0 # Salva a string digitada em $t0
syscall
li $t1,45
li $t2,42
altera:
lb $a0, ($t0)
beq $a0,0,termina
bne $a0,$t1,proximo
sb $t2, ($t0)
proximo:
add $t0,$t0,1
j altera
termina:
la $a0, result # Carrega e mostra "sua resposta" que é uma string
li $v0, 4 # Imprimi a string
syscall
la $a0, buffer
li $v0, 4 # Imprimi a string
syscall
end:
li $v0, 10 # Encerra o programa
syscall
1
Author: Carlos Rabelo, 2017-03-24 20:35:29