Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- .data # .data starts the data segment of the program, where all the global variables are held.
- prompt1: .asciiz "Enter text, followed by $:\n"
- outmsg: .asciiz "Count: "
- countersArray: .space 104 # 104 bytes/4(32 bits) = 26 integers
- presult: .asciiz "\n"
- presult2: .asciiz " : "
- regards: .asciiz "The program has finished and will exit now."
- .globl main
- .text
- main: # sets the program up
- la $a0, prompt1
- li $v0, 4
- syscall # Asks user for sequence
- # Declares s0 as '$'
- li $s0, 36 # Assign 0x24 to s1 (36 in decimal)
- # Jamp to the loop
- j readloop # Jumping to readloop
- readloop: # Reading the char from the terminal
- # Reads a char
- li $v0, 12
- syscall # Reading a character
- add $s1, $zero, $v0 # Receive the character in v0 & move to s1
- beq $s1, $s0, endreadloop
- # Processing the relative counter
- la $t3, countersArray
- sll $t2, $t1, 2 # from words to bytes, multiply by 4
- add $t2, $t2, $t3
- lw $t0, 0($t2) # getting counter
- add $t0, $t0, 1 # adding one
- sw $t0, 0($t2) # storing counter
- # If the char is '$' the loop finishes
- bne $s0, $s1, readloop # Branching when char is different from '$'
- loop:
- # Reads a char
- li $v0, 12
- syscall # Reading a char
- add $s1, $zero, $v0 # Receive the char in v0 and moving it to s1
- beq $s1, $s0, endreadloop
- endreadloop:
- # Cleanning up the values, just in case
- li $t0, 0
- li $t1, 0
- li $t2, 0
- li $s1, 0
- # Jump to the resolution
- # /n
- la $a0, presult
- li $v0, 4
- syscall # Writing '\n'
- j resloop # Going to the ending
- resloop:
- # Reinitializing s1
- add $s1, $t1, 96
- # Letter
- move $s1, $a0
- li $v0, 11
- syscall # Writing the char
- # :
- la $a0, presult2
- li $v0, 4
- syscall # Writing ': '
- # Counter
- sll $t2, $t1, 2
- li $v0, 1
- lw $a0, countersArray+0($t2)
- syscall
- # /n
- la $a0, presult
- li $v0, 4
- syscall # Writing '\n'
- add $t1, $t1, 1
- bne $t1, 26 resloop # After the last letter we exit
- j exit
- exit:
- # Print regards
- la $a0, regards
- li $v0, 4
- syscall
- li $v0, 10
- syscall
Add Comment
Please, Sign In to add comment