Guest User

Untitled

a guest
Feb 21st, 2018
77
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. countersArray:  .space          104     # 104 bytes/4(32 bits) = 26 integers
  5. presult:    .asciiz     "\n"        
  6. presult2:   .asciiz     " : "
  7. regards:    .asciiz     "The program has finished and will exit now."        
  8.         .globl      main
  9.         .text
  10.        
  11. main:   # sets the program up
  12.  
  13.     la      $a0,    prompt1
  14.     li      $v0,    4  
  15.     syscall                     # Asks user for sequence
  16.    
  17.     # Declares s0 as '$'
  18.     li      $s0,    36          # Assign 0x24 to s1 (36 in decimal)
  19.    
  20.     # Jamp to the loop
  21.     j       readloop            # Jumping to readloop
  22.    
  23. readloop:                           # Reading the char from the terminal
  24.  
  25.     # Reads a char
  26.     li      $v0,    12         
  27.     syscall                     # Reading a character
  28.     add     $s1,    $zero,  $v0     # Receive the character in v0 & move to s1
  29.                    
  30.     beq     $s1,    $s0,    endreadloop
  31.  
  32.     # Processing the relative counter
  33.     la      $t3,    countersArray
  34.     sll     $t2,    $t1,    2       # from words to bytes, multiply by 4
  35.     add     $t2,    $t2,    $t3
  36.     lw      $t0,    0($t2)          # getting counter
  37.     add     $t0,    $t0,    1       # adding one
  38.     sw      $t0,    0($t2)          # storing counter
  39.  
  40.     # If the char is '$' the loop finishes
  41.     bne     $s0,    $s1,    readloop    # Branching when char is different from '$'
  42.        
  43.  
  44. loop:  
  45.     # Reads a char
  46.     li      $v0,    12
  47.     syscall                     # Reading a char
  48.     add     $s1,    $zero,  $v0     # Receive the char in v0 and moving it to s1
  49.                    
  50.     beq     $s1,    $s0,    endreadloop
  51.    
  52. endreadloop:
  53.        
  54.     # Cleanning up the values, just in case
  55.     li      $t0,    0
  56.     li      $t1,    0
  57.     li      $t2,    0
  58.     li      $s1,    0
  59.     # Jump to the resolution
  60.    
  61.     # /n
  62.     la      $a0,    presult
  63.     li      $v0,    4          
  64.     syscall                     # Writing '\n'
  65.  
  66.     j       resloop             # Going to the ending
  67.  
  68. resloop:
  69.    
  70.    
  71.     # Reinitializing s1
  72.     add     $s1,    $t1,    96 
  73.    
  74.     # Letter
  75.     move        $s1,    $a0
  76.     li      $v0,    11
  77.     syscall                     # Writing the char
  78.  
  79.     # :
  80.     la      $a0,    presult2   
  81.     li      $v0,    4          
  82.     syscall                     # Writing ': '
  83.    
  84.     # Counter
  85.     sll     $t2,    $t1,    2
  86.     li      $v0,    1
  87.     lw      $a0,    countersArray+0($t2)
  88.     syscall
  89.  
  90.     # /n
  91.     la      $a0,    presult
  92.     li      $v0,    4          
  93.     syscall                     # Writing '\n'
  94.    
  95.     add     $t1,    $t1,    1
  96.     bne     $t1,    26  resloop     # After the last letter we exit
  97.  
  98.     j       exit
  99.  
  100. exit:
  101.     # Print regards
  102.     la      $a0,    regards
  103.     li      $v0,    4
  104.     syscall
  105.    
  106.     li      $v0,    10
  107.     syscall
Add Comment
Please, Sign In to add comment