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 "End of program"
- .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
- # Reset the loop
- li $t0, 0
- readloop: # Reading the character from 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
- add $t0, $t0, 1 # Add 1 to counter
- # If the character is $ the loop finishes
- bne $s0, $s1, readloop # Branch when the character is not $
- endloop:
- # Shows result
- add $a0, $t0, $zero
- li $v0, 1
- syscall
- # End the program
- la $a0, ending
- li $v0, 4
- syscall
- li $v0, 10
- syscall
Add Comment
Please, Sign In to add comment