Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # Coursework One
- #
- # Keith Robertson 0940608
- .data
- # .data starts the data segment of the program,
- # where all the global variables are held.
- prompt:.asciiz "Enter text, followed by $:\n"
- countmsg:.asciiz "Count: "
- count:.word 0 #create a single integer variable with initial 0
- input:.space 40 #array that can store 40 characters
- # "msg" is a label, a name followed by colon, ":".
- # It must start at the beginning of the line.
- # In contrast, all assembly directives (e.g. ".data")
- # must *not* start at the beginning of the line.
- # .asciiz stores a string (ending with NULL) in memory
- .globl main # declare the global symbols of this program
- # SPIM requires a "main" symbol, (think of symbol
- # as another name for label), which declares
- # where our program starts
- .text
- # .text starts the text segment of the program,
- # where the assembly program code is placed.
- main: # This is the entry point of our program
- la $a0, prompt # make $a0 point to where the prompt is
- li $v0, 4 # $v0 <- 4
- syscall # Call the OS to print the message
- la $a0, input
- li $v0, 8
- syscall
- li $s0, '$'
- la $t0, input
- loop: #This is where I will be looping across the array
- beq $t0, $s0, print
- la $t0, 4($t0) # move the index along by one
- beq $t0, 0x20, loop
- beq $t0, 0x09, loop # if its whitespace we dont add one
- beq $t0, 0x0a, loop
- beq $t0, 0x0d, loop
- lw $t1, count
- add $t1, $t1, 1 # fetching count from RAM, adding 1 #storing it again
- sw $t1, count
- j loop
- print: # Printing our answer
- la $a0, countmsg
- li $v0, 4
- syscall
- la $a0, input
- li $v0, 4
- syscall
- # This is the standard way to end a program
- li $v0, 10
- syscall # end the program
Add Comment
Please, Sign In to add comment