Ask a question to Desklib · AI bot


MIPS Assembly Code: Replacing Characters in a String

Added on -2019-09-23

This text appears to be MIPS assembly code for a program that prompts the user to input a string, then processes the string by replacing certain characters with other characters or sequences of characters. For example, if the input string contains a `#` followed by a number `n`, the program replaces this sequence with `n` occurrences of the character `A`. Similar replacements are performed for the characters `%`, `$`, and `&`. The processed string is then outputted.

| 5 pages
| 571 words

Trusted by 2+ million users,
1000+ happy students everyday

.data str: .space 40 fstr: .space 150 prompt: .asciiz "Input a string:" output: .asciiz "Output string:" newline: .asciiz "\n" .text .globl mainmain: # display prompt li $v0, 4 la $a0, prompt syscall # accept input string li $v0, 8 la $a0, str li $a1, 64 syscall li $t1, 0 # initiate index li $t7, 0 # output indexloop: li $t6 , 0 lb $t0 str($t1) beqz $t0 exit # check if "#" li $t2, '#' beq $t0, $t2, hash_to_a nop # check if "%" li $t2, '%' beq $t0, $t2, percent_to_g nop # check if "$"

Found this document preview useful?

You are reading a preview
Upload your documents to download
Become a Desklib member to get accesss

Students who viewed this