简体   繁体   中英

MIPS Assembly creating character checker

I am looking for help on how to take a string from the user and then output the number of times each letter was used in the string.

Pseudo code string "Please enter a string:" take string and save into an array, check for ascii duplicates of character values and then output when corresponding letter is output.

example: Hello World

A: 
B:
C:
D: 1
E: 1
...
H: 1
...
W: 1

code

.data
intro: .asciiz "Letter Checker Program" 
question: .asciiz "\nPlease enter a string for evaluation: "

string: .space 1024
alphabet: .space 26


.text 

main:
jal setup
#jal analyze
#jal results

li $v0, 10
syscall 

setup:
li $v0, 4   # outputing name and program information
la $a0, intro
syscall

li $v0, 4   # asksing for string input
la $a0, question
syscall 

li $v0, 8
la $a0, string
li $a1, 1024
syscall

jr $ra      # return

analyze:

loop:   

loop:

results:

What you want to do is:

  1. Create some space (26 * 4 bytes) to store the results and fill with 0
  2. Loop over every letter in the string and load with lb
  3. Determine the numerical value of the letter, and thus the memory location (of step 1). Don't forget about lower and upper case letters.
  4. Load that memory location (4 bytes, use lw ), increase the value with 1, and store again with sw
  5. Stop when you encounter 0 (not the letter '0')
  6. In analyze, loop over every letter in the alphabet, load the corresponding memory location from step 1, and print results

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM