Can someone run my mips code? I'm using pcSpim as my simulator
The issue I'm having is that it doesn't correctly output the number of othercharacters.
Other characters would be like !@#$%^&*()_+-=.,<>?/ \
The other problem I'm having is that it doesn't output the number of characters there are in the string inputted. If I get rid of the othercharacters loop then it will output or display the number of characters or the length of the string inputted.
Thank you to anyone who can help me!
## This program prints out the length of characters, digits, upper and lower case characters that are inputted through the user
## t0 holds each byte from input
## t1 contains the count of characteters
## t2 points to the input of characters
.data
input: .asciiz "Please enter up to eighty characters "
ans: .asciiz "\nThis is how many characters your input has "
anstwo: .asciiz "\nThis is how many uppercase characters your input has "
ansthree: .asciiz "\nThis is how many lowercase characters your input has "
ansfour: .asciiz "\nThis is how many digits your input has "
ansfive: .asciiz "\nThis is how many spaces your input has "
anssix: .asciiz "\nThis is how many othercharacters your input has "
buffer: .space 80
.text
.globl main
main:
li $v0, 4 # system call code for print_str
la $a0, input # address of string to print
syscall # print the input
li $v0, 8 # code for syscall read_string
la $a0, buffer # tell syscall where the buffer is
li $a1, 80 # tell syscall how big the buffer is
syscall
la $t2, buffer # t2 points to the input
li $t1, 0 # t1 holds the count
la $a0, buffer
jal uppercasecount # call uppercasecount
la $t2, buffer # t2 points to the input
li $t3, 0 # t3 holds the count for how many uppercase
la $a0, buffer
jal lowercasecount # call lowercasecount
la $t2, buffer # t2 points to the input
li $t4, 0 # t4 holds the count for how many lowercase
la $t2, buffer # t2 points to the input
li $t5, 0 # t5 holds the count for how many digits
jal digitcount # call digitcount
la $t2, buffer # t2 points to the input
li $t6, 0 # t6 holds the count for how many spaces
jal spacecount # call spacecount
la $t2, buffer
#li $t7, 0
jal Othercharacters
nextcharacter:
lb $t0,($t2) # get a byte from the input
beqz $t0, characterend # zero means it is the end of the input
addi $t1, $t1, 1 # increment the count
addi $t2,1 # move the pointer to the next character
j nextcharacter # go through the next character loop again
characterend:
la $a0, ans # system call to print
li $v0, 4 # out a message
sub $t1, $t1, 1 # subtract 1 from count of characters to get correct number
syscall
move $a0, $t1 # system call to print
li $v0, 1 # out the length worked out
syscall
li $v0,10 # exit
syscall
#
#------------------------------------------------
# uppercase - takes a single character as a
# parameter and returns 1 if the character
# is a uppercase otherwise return 0.
# a0 - holds character
# v0 - returns 0 or 1
#------------------------------------------------
uppercase:
li $v0, 0 #
beq $a0,'A',ucyes #beq means branch is equal to
beq $a0,'B',ucyes
beq $a0,'C',ucyes
beq $a0,'D',ucyes
beq $a0,'E',ucyes
beq $a0,'F',ucyes
beq $a0,'G',ucyes
beq $a0,'H',ucyes
beq $a0,'I',ucyes
beq $a0,'J',ucyes
beq $a0,'K',ucyes
beq $a0,'L',ucyes
beq $a0,'M',ucyes
beq $a0,'N',ucyes
beq $a0,'O',ucyes
beq $a0,'P',ucyes
beq $a0,'Q',ucyes
beq $a0,'R',ucyes
beq $a0,'S',ucyes
beq $a0,'T',ucyes
beq $a0,'U',ucyes
beq $a0,'V',ucyes
beq $a0,'W',ucyes
beq $a0,'X',ucyes
beq $a0,'Y',ucyes
beq $a0,'Z',ucyes
jr $ra # return (to the operating system)
ucyes:
li $v0,1 # this is the code perform print_int
jr $ra # return (to the operating system)
jr $ra
#------------------------------------------------
# uppercasecount - use vowelp to count the vowels in a
# string.
# a0 - holds buffer address
# t3 - holds number of uppercasecharacters
# v0 - returns number of uppercasecharacters
#------------------------------------------------
uppercasecount:
sub $sp,$sp,16 # save registers on stack
sw $a0,0($sp)
sw $t3,4($sp)
sw $s1,8($sp)
sw $ra,12($sp)
li $t3,0 # count of vowels
move $s1,$a0 # address of string
nextcharacter2:
lb $a0,($s1) # get each character
beqz $a0,uppercasedone # zero marks end
jal uppercase # call uppercase
add $t3,$t3,$v0 # add 0 or 1 to count
add $s1,$s1,1 # move along string
j nextcharacter2
uppercasedone:
la $a0, anstwo
li $v0, 4
syscall
move $a0, $t3 # system call to print
li $v0, 1 # out the length worked out
syscall
lw $a0,0($sp) # restore registers
lw $s0,4($sp)
lw $t3,8($sp)
lw $ra,12($sp)
add $sp,$sp,16
jr $ra
#
#------------------------------------------------
# lowercase - takes a single character as a
# parameter and returns 1 if the character
# is a uppercase otherwise return 0.
# a0 - holds character
# v0 - returns 0 or 1
#------------------------------------------------
lowercase:
li $v0, 0 #
beq $a0,'a',lcyes #beq means branch is equal to
beq $a0,'b',lcyes
beq $a0,'c',lcyes
beq $a0,'d',lcyes
beq $a0,'e',lcyes
beq $a0,'f',lcyes
beq $a0,'g',lcyes
beq $a0,'h',lcyes
beq $a0,'i',lcyes
beq $a0,'j',lcyes
beq $a0,'k',lcyes
beq $a0,'l',lcyes
beq $a0,'m',lcyes
beq $a0,'n',lcyes
beq $a0,'o',lcyes
beq $a0,'p',lcyes
beq $a0,'q',lcyes
beq $a0,'r',lcyes
beq $a0,'s',lcyes
beq $a0,'t',lcyes
beq $a0,'u',lcyes
beq $a0,'v',lcyes
beq $a0,'w',lcyes
beq $a0,'x',lcyes
beq $a0,'y',lcyes
beq $a0,'z',lcyes
jr $ra # return (to the operating system)
lcyes:
li $v0,1 # this is the code perform print_int
jr $ra # return (to the operating system)
#------------------------------------------------
# lowercasecount - use lowercase to count the lowercase characters in a
# string.
# a0 - holds buffer address
# t4 - holds number of lowercasecharacters
# v0 - returns number of lowercasecharacters
#------------------------------------------------
lowercasecount:
sub $sp,$sp,16 # save registers on stack
sw $a0,0($sp)
sw $t4,4($sp)
sw $s1,8($sp)
sw $ra,12($sp)
li $t4,0 # count of lowercase
move $s1,$a0 # address of string
nextcharacter3:
lb $a0,($s1) # get each character
beqz $a0,lowercasedone # zero marks end
jal lowercase # call lowercase
add $t4,$t4,$v0 # add 0 or 1 to count
add $s1,$s1,1 # move along string
j nextcharacter3
lowercasedone:
la $a0, ansthree
li $v0, 4
syscall
move $a0, $t4 # system call to print
li $v0, 1 # out the length worked out
syscall
lw $a0,0($sp) # restore registers
lw $t4,4($sp)
lw $s1,8($sp)
lw $ra,12($sp)
add $sp,$sp,16
jr $ra # return (to the operating system)
digit:
li $v0, 0
beq $a0,'1',dyes
beq $a0,'2',dyes
beq $a0,'3',dyes
beq $a0,'4',dyes
beq $a0,'5',dyes
beq $a0,'6',dyes
beq $a0,'7',dyes
beq $a0,'8',dyes
beq $a0,'9',dyes
beq $a0,'0',dyes
jr $ra # return (to the operating system)
dyes:
li $v0,1
jr $ra
digitcount:
sub $sp, $sp, 16
sw $a0,0($sp)
sw $t5,4($sp)
sw $s1,8($sp)
sw $ra,12($sp)
li $t5,0 # count of digits
move $s1,$a0 # address of string
nextdigit:
lb $a0,($s1) # get each character
beqz $a0,digitdone # zero marks end
jal digit # call digit
add $t5,$t5,$v0 # add 0 or 1 to count
add $s1,$s1,1 # move along string
j nextdigit
digitdone:
la $a0, ansfour
li $v0, 4
syscall
move $a0, $t5 # system call to print
li $v0, 1 # out the length worked out
syscall
lw $a0,0($sp) # restore registers
lw $t5,4($sp)
lw $s1,8($sp)
lw $ra,12($sp)
add $sp,$sp,16
jr $ra
space:
li $v0, 0
beq $a0,' ',syes
jr $ra # return (to the operating system)
syes:
li $v0,1
jr $ra
spacecount:
sub $sp, $sp, 16
sw $a0,0($sp)
sw $t6,4($sp)
sw $s1,8($sp)
sw $ra,12($sp)
li $t6,0 # count of space
move $s1,$a0 # address of string
nextspace:
lb $a0,($s1) # get each character
beqz $a0,spacedone # zero marks end
jal space # call space
add $t6,$t6,$v0 # add 0 or 1 to count
add $s1,$s1,1 # move along string
j nextspace
spacedone:
la $a0, ansfive # how many spaces are in the characters
li $v0, 4
syscall
move $a0, $t6 # system call to print
li $v0, 1 # out the length worked out
syscall
lw $a0,0($sp) # restore registers
lw $t6,4($sp)
lw $s1,8($sp)
lw $ra,12($sp)
add $sp,$sp,16
jr $ra
Othercharacters:
add $t7, $t3, $t4
add $t8, $t5, $t6
add $t9, $t8, $t7
sub $t9, $t2, $t9
li $v0, 4
la $a0, anssix
syscall
li $v0, 1
move $a0, $t9
syscall