Guest User

Untitled

a guest
Feb 19th, 2018
108
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.05 KB | None | 0 0
  1. # Coursework One
  2. #
  3. # Keith Robertson 0940608
  4.  
  5. .data
  6. # .data starts the data segment of the program,
  7. # where all the global variables are held.
  8. prompt:.asciiz "Enter text, followed by $:\n"
  9. countmsg:.asciiz "Count: "
  10. count:.word 0 #create a single integer variable with initial 0
  11. input:.space 40 #array that can store 40 characters
  12.  
  13. # "msg" is a label, a name followed by colon, ":".
  14. # It must start at the beginning of the line.
  15. # In contrast, all assembly directives (e.g. ".data")
  16. # must *not* start at the beginning of the line.
  17. # .asciiz stores a string (ending with NULL) in memory
  18.  
  19. .globl main # declare the global symbols of this program
  20. # SPIM requires a "main" symbol, (think of symbol
  21. # as another name for label), which declares
  22. # where our program starts
  23.  
  24. .text
  25. # .text starts the text segment of the program,
  26. # where the assembly program code is placed.
  27.  
  28. main: # This is the entry point of our program
  29.  
  30. la $a0, prompt # make $a0 point to where the prompt is
  31. li $v0, 4 # $v0 <- 4
  32. syscall # Call the OS to print the message
  33.  
  34.  
  35. la $a0, input
  36. li $v0, 8
  37. syscall
  38.  
  39. li $s0, '$'
  40. la $t0, input
  41.  
  42. loop: #This is where I will be looping across the array
  43.  
  44. beq $t0, $s0, print
  45. la $t0, 4($t0) # move the index along by one
  46. beq $t0, 0x20, loop
  47. beq $t0, 0x09, loop # if its whitespace we dont add one
  48. beq $t0, 0x0a, loop
  49. beq $t0, 0x0d, loop
  50. lw $t1, count
  51. add $t1, $t1, 1 # fetching count from RAM, adding 1 #storing it again
  52. sw $t1, count
  53. j loop
  54.  
  55. print: # Printing our answer
  56. la $a0, countmsg
  57. li $v0, 4
  58. syscall
  59.  
  60. la $a0, input
  61. li $v0, 4
  62. syscall
  63.  
  64. # This is the standard way to end a program
  65. li $v0, 10
  66. syscall # end the program
Add Comment
Please, Sign In to add comment