944,118 Members | Top Members by Rank

Ad:
  • Assembly Discussion Thread
  • Unsolved
  • Views: 714
  • Assembly RSS
Oct 31st, 2009
0

Need help with a mips program

Expand Post »
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.

assembly Syntax (Toggle Plain Text)
  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
Reputation Points: 10
Solved Threads: 0
Junior Poster in Training
Noliving is offline Offline
62 posts
since Sep 2007
Oct 31st, 2009
0
Re: Need help with a mips program
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.
Reputation Points: 10
Solved Threads: 0
Junior Poster in Training
Noliving is offline Offline
62 posts
since Sep 2007
Nov 4th, 2009
0
Re: Need help with a mips program
????
addi $t0, $t0, 0 # increment address in $t0

N = N + 0

Did you cut'n'paste improperly?

Is code missing?
Reputation Points: 546
Solved Threads: 99
Practically a Posting Shark
wildgoose is offline Offline
891 posts
since Jun 2009

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in Assembly Forum Timeline: Setting string colors in NASM
Next Thread in Assembly Forum Timeline: An os whith a menu.





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC