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: "
- ending: .asciiz "Quitting..."
- .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, endloop
- # Process counter
- la $t3, countersArray
- lw $t0, 0($t2) # getting counter
- add $t0, $t0, 1 # adding one
- sw $t0, 0($t2) # storing counter
- # If the character is '$' the loop finishes
- bne $s0, $s1, readloop # Branching when char is different from '$'
- endloop:
- # Cleanning up the values, just in case
- li $t0, 0
- li $t1, 0
- li $t2, 0
- li $s1, 0
- j exit # Going to the ending
- exit:
- # End the program
- la $a0, ending
- li $v0, 4
- syscall
- li $v0, 10
- syscall
Add Comment
Please, Sign In to add comment