GIDForums  

Go Back   GIDForums > Computer Programming Forums > Assembly Language
User Name
Password
Register FAQ Members List Calendar Search Today's Posts Mark Forums Read

 
 
Thread Tools Search this Thread Rate Thread
  #1  
Old 02-Nov-2009, 17:01
Noliving Noliving is offline
New Member
 
Join Date: Nov 2009
Posts: 4
Noliving is on a distinguished road

Can someone please run my mips code?


Hello everyone! I'm currently using pcSpim to run my mips code

Basically what my program does is this, you input a string, it counts out the number of characters in that string, it also counts the number of upper case and lower case letters, it also counts the number of spaces and digits. It is also suppose to count the number of other characters which would be !@#$%^&*()_-+=><,.?/\|{}[] etc.

The issue I'm having is that when I try to get the number of othercharacters it displays a number much larger then the number of characters input. Not only that it will no longer display the number of characters of the string entered.

So for example lets say you input ABCabc 123

The output will look like this:

Uppercase is 3
lowercase is 3
space is 3
digits is 3
othercharacters is 268501317

but it is also missing the output that shows how many characters there are, if you comment out the othercharacters loop or section of the code and in the main part.

the out put will look like this:

Uppercase is 3
lowercase is 3
space is 3
digits is 3
total number of characters entered is 12

So what I don't understand is why my othercharacters output isn't working correctly and what I don't understand is why my totalnumber of characters output stops being displayed if I run the othercharacters code.

Thanks for any help!

Code:
## 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
  #2  
Old 02-Nov-2009, 17:41
Noliving Noliving is offline
New Member
 
Join Date: Nov 2009
Posts: 4
Noliving is on a distinguished road

Re: Can someone please run my mips code?


I was able to get my:

This is how many characters you entered output back, I forgot to put:

jr $ra

at the end, I'm still having problems though with my othercharacters.
  #3  
Old 02-Nov-2009, 18:39
Noliving Noliving is offline
New Member
 
Join Date: Nov 2009
Posts: 4
Noliving is on a distinguished road

Re: Can someone please run my mips code?


I also have another question too.

When I enter a string, how do I not count the 0x0a and null characters?

Because if I enter in 80 characters it says I only entered in 78.
  #4  
Old 02-Nov-2009, 21:04
Noliving Noliving is offline
New Member
 
Join Date: Nov 2009
Posts: 4
Noliving is on a distinguished road

Re: Can someone please run my mips code?


Ok good news, I pretty much solved all my problems with my code.

My only question remaining though is still this:

When I enter a string, how do I not count the 0x0a and null characters?

Because if I enter in 80 characters it says I only entered in 78.
 
 

Recent GIDBlogAccepted for Ph.D. program by crystalattice

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Trouble integrating console code into GUI Barman007 Java Forum 18 15-May-2008 14:05
Request code for a non-recursive binary search in MIPS ks_100 Assembly Language 0 15-Feb-2008 12:10
How to sort random access file? wmmccoy0910 C Programming Language 12 04-Sep-2006 04:40
Here it is again! 35% - 40% off For Life! my-e-space Web Hosting Advertisements & Offers 0 20-Apr-2006 15:48
Guidelines for posting requests for help - UPDATED! WaltP C Programming Language 0 21-Apr-2005 03:44

Network Sites: GIDNetwork · GIDWebHosts · GIDSearch · Learning Journal by J de Silva, The

All times are GMT -6. The time now is 22:44.


vBulletin, Copyright © 2000 - 2009, Jelsoft Enterprises Ltd.