Need help with a mips program

Please support our Assembly advertiser: Programming Forums - DaniWeb Sister Site
Reply

Join Date: Sep 2007
Posts: 58
Reputation: Noliving is an unknown quantity at this point 
Solved Threads: 0
Noliving Noliving is offline Offline
Junior Poster in Training

Need help with a mips program

 
0
  #1
Oct 31st, 2009
Hello everyone, I'm trying to create a program that will accept a string and output how many characters are in that string. The input can be a mixture of upper/lowercase letters, digits, spaces, and other cases such as .%^& etc.

This is my first time use any type of assembly language so please understand if I have trouble

This is what I have so far, the only thing it does right now is just output what I input, so if I input '"hello" the output will be "hello". Thanks for your help.

  1. .data
  2.  
  3. Q1:
  4. .asciiz "Please enter a string that is up to eighty characters: "
  5.  
  6. ans1:
  7. .asciiz "\nThe length of the string you entered contains this many characters: "
  8.  
  9.  
  10.  
  11. buffer: .space 80 # create space for string input
  12.  
  13. .text
  14. .globl main #must be global
  15.  
  16. main:
  17. li $v0, 4 # system call code for print_str
  18. la $a0, Q1 # address of string to print
  19. syscall # print the Q1
  20.  
  21.  
  22. li $v0, 8 # code for syscall read_string
  23. la $a0, buffer # tell syscall where the buffer is
  24. li $a1, 80 # tell syscall how big the buffer is
  25. syscall
  26.  
  27.  
  28. li $v0, 8 # code for syscall read_string
  29. la $t0, buffer # place address of buffer in $t0
  30. lb $t1, 0($t0) # read byte located at address in $t0
  31. addi $t0, $t0, 0 # increment address in $t0
  32. #sbrk $a0, 9 # the amount of how long the string is from the address
  33.  
  34.  
  35. li $v0, 4
  36. la $a0, ans1
  37. syscall
  38.  
  39. li $v0, 4
  40. move $a0, $t0
  41. syscall
  42.  
  43. jr $ra # return to system
Reply With Quote Quick reply to this message  
Join Date: Sep 2007
Posts: 58
Reputation: Noliving is an unknown quantity at this point 
Solved Threads: 0
Noliving Noliving is offline Offline
Junior Poster in Training
 
0
  #2
Oct 31st, 2009
Good news I pretty much was able to get it to count the characters, except it only counts up to 78 instead of like 80 characters.
Reply With Quote Quick reply to this message  
Join Date: Jun 2009
Posts: 830
Reputation: wildgoose is a name known to all wildgoose is a name known to all wildgoose is a name known to all wildgoose is a name known to all wildgoose is a name known to all wildgoose is a name known to all 
Solved Threads: 94
wildgoose's Avatar
wildgoose wildgoose is offline Offline
Practically a Posting Shark
 
0
  #3
Nov 4th, 2009
????
addi $t0, $t0, 0 # increment address in $t0

N = N + 0

Did you cut'n'paste improperly?

Is code missing?
Reply With Quote Quick reply to this message  
Reply

Message:



Other Threads in the Assembly Forum


Views: 463 | Replies: 2
Thread Tools Search this Thread



Tag cloud for Assembly
About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC