Guest User

Untitled

a guest
Feb 21st, 2018
78
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     "Quitting..."        
  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          # Assign 0x24 to s1 (36 in decimal)
  16.    
  17.     # Jamp to the loop
  18.     j       readloop            # Jumping to readloop
  19.    
  20. readloop:                           # Reading the char from the 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.     la      $t3,    countersArray
  30.     lw      $t0,    0($t2)          # getting counter
  31.     add     $t0,    $t0,    1       # adding one
  32.     sw      $t0,    0($t2)          # storing counter
  33.    
  34.     # If the character is '$' the loop finishes
  35.     bne     $s0,    $s1,    readloop    # Branching when char is different from '$'
  36.        
  37.  
  38. endloop:
  39.        
  40.     # Cleanning up the values, just in case
  41.     li      $t0,    0
  42.     li      $t1,    0
  43.     li      $t2,    0
  44.     li      $s1,    0
  45.  
  46.     j       exit                # Going to the ending
  47.  
  48. exit:
  49.     # End the program
  50.     la      $a0,    ending
  51.     li      $v0,    4
  52.     syscall
  53.    
  54.     li      $v0,    10
  55.     syscall
Add Comment
Please, Sign In to add comment