Guest User

Untitled

a guest
Feb 21st, 2018
111
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1.             .data       #  .data starts the data segment of the program, where all the global variables are held.
  2. prompt1:        .asciiz     "Enter text, followed by $:\n"
  3. outmsg:     .asciiz     "Count: "
  4. ending:     .asciiz     "End of program"        
  5.         .globl      main
  6.         .text
  7.        
  8. main:   # Sets the program up
  9.  
  10.     la      $a0,    prompt1
  11.     li      $v0,    4  
  12.     syscall                     # Asks user for sequence
  13.    
  14.     # Declares s0 as $
  15.     li      $s0,    36           
  16.    
  17.     # Reset the loop
  18.     li      $t0, 0
  19.    
  20. readloop:                           # Reading the character from terminal
  21.  
  22.     # Reads a char
  23.     li      $v0,    12         
  24.     syscall                     # Reading a character
  25.     add     $s1,    $zero,  $v0     # Receive the character in v0 & move to s1
  26.     beq     $s1,    $s0,    endloop
  27.  
  28.     # Process counter
  29.     add     $t0,    $t0,    1       # Add 1 to counter
  30.        
  31.     # If the character is $ the loop finishes
  32.     bne     $s0,    $s1,    readloop    # Branch when the character is not $
  33.    
  34. endloop:
  35.        
  36.     # Shows result
  37.     add $a0, $t0, $zero
  38.     li $v0, 1
  39.     syscall
  40.    
  41.     # End the program
  42.     la      $a0,    ending
  43.     li      $v0,    4
  44.     syscall
  45.    
  46.     li      $v0,    10
  47.     syscall
Add Comment
Please, Sign In to add comment