Guest User

Untitled

a guest
Jan 19th, 2018
87
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. # Mulawski, Evan
  2. # Program 2
  3. # Weighted String Output
  4. # 2011-10-11
  5.  
  6. .data
  7.  
  8. inBuf:
  9.     .space 80
  10.  
  11. st_prompt:
  12.     .asciiz "Enter a new input line: "
  13.  
  14. newLine:
  15.     .asciiz "\n"
  16.  
  17. Tabchar:
  18.     .word ' ', 5
  19.     .word '#', 6
  20.     .word '(', 4
  21.     .word ')', 4
  22.     .word '*', 3
  23.     .word '+', 3
  24.     .word ',', 4
  25.     .word '-', 3
  26.     .word '.', 4
  27.     .word '/', 3
  28.  
  29.     .word '0', 1
  30.     .word '1', 1
  31.     .word '2', 1
  32.     .word '3', 1
  33.     .word '4', 1
  34.     .word '5', 1
  35.     .word '6', 1
  36.     .word '7', 1
  37.     .word '8', 1
  38.     .word '9', 1
  39.  
  40.     .word ':', 4
  41.  
  42.     .word 'A', 2
  43.     .word 'B', 2
  44.     .word 'C', 2
  45.     .word 'D', 2
  46.     .word 'E', 2
  47.     .word 'F', 2
  48.     .word 'G', 2
  49.     .word 'H', 2
  50.     .word 'I', 2
  51.     .word 'J', 2
  52.     .word 'K', 2
  53.     .word 'L', 2
  54.     .word 'M', 2
  55.     .word 'N', 2
  56.     .word 'O', 2
  57.     .word 'P', 2
  58.     .word 'Q', 2
  59.     .word 'R', 2
  60.     .word 'S', 2
  61.     .word 'T', 2
  62.     .word 'U', 2
  63.     .word 'V', 2
  64.     .word 'W', 2
  65.     .word 'X', 2
  66.     .word 'Y', 2
  67.     .word 'Z', 2
  68.  
  69.     .word 'a', 2
  70.     .word 'b', 2
  71.     .word 'c', 2
  72.     .word 'd', 2
  73.     .word 'e', 2
  74.     .word 'f', 2
  75.     .word 'g', 2
  76.     .word 'h', 2
  77.     .word 'i', 2
  78.     .word 'j', 2
  79.     .word 'k', 2
  80.     .word 'l', 2
  81.     .word 'm', 2
  82.     .word 'n', 2
  83.     .word 'o', 2
  84.     .word 'p', 2
  85.     .word 'q', 2
  86.     .word 'r', 2
  87.     .word 's', 2
  88.     .word 't', 2
  89.     .word 'u', 2
  90.     .word 'v', 2
  91.     .word 'w', 2
  92.     .word 'x', 2
  93.     .word 'y', 2
  94.     .word 'z', 2
  95.  
  96. weights:
  97.     .space 80
  98.  
  99.     .text
  100.     .globl main
  101.  
  102. main:
  103.         la $a0, newLine
  104.         li $v0, 4
  105.         syscall
  106.  
  107.         jal getline
  108.    
  109.     # > print what was entered
  110.     li $v0, 4
  111.         la $a0, inBuf
  112.         syscall
  113.     # <
  114.  
  115.         li $t1, 80 # total characters
  116.  
  117.         li $t0, 0 # inBuf array index
  118.  
  119. next_char:
  120.         lb $a3, inBuf($t0) # save inBuf element into $a3
  121.         beq $a3, 10, exit
  122.         jal lin_srch # call linear search
  123.  
  124.         addi $t0, $t0, 1 # increment inBuf index
  125.         b next_char
  126.  
  127. # non-terminating exit to print the weighted output
  128. exit:
  129.         la $a0, weights
  130.         la $t8, ($a0)
  131.         li $v0, 4
  132.         syscall
  133.  
  134.         b main # return to main to present the input prompt again
  135.    
  136. getline:
  137.         la $a0, st_prompt # prompt to enter a new line
  138.         li $v0, 4
  139.         syscall
  140.         la $a0, inBuf # read a new line
  141.         li $a1, 80
  142.         li $v0, 8
  143.         syscall
  144.         jr $ra
  145.  
  146. lin_srch:
  147.         li $s6, 0 # tabchar index
  148.        
  149.         rept:
  150.         lb $t4, Tabchar($s6) # loads what's in Tabchar[s6] into $t4
  151.         beq $a3, $t4, done  # if character == tabchar[i], goto done
  152.         addi $s6, $s6, 8 # incremement i 8 bytes
  153.         blt $s6, 608, rept # if counter < end of tabchar goto rept
  154.  
  155.         done:
  156.         lw $t4, Tabchar+4($s6) # load value of the weight
  157.         addi $t4, $t4, 48 # modifying it to be an ascii value
  158.         sb $t4, weights($t0) # puts weight into weights[t0]
  159.         jr $ra
  160.  
  161. #termination
  162. fin:   
  163.     move    $a0, $t1
  164.     li  $v0, 1
  165.     syscall
  166.     li  $v0, 10
Add Comment
Please, Sign In to add comment