CodeGuru Forums -
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic Newsletters VB Forums Developer.com


Newest CodeGuru.com Articles:

  • Installing SQL Server 2008
  • Writing UDFs for Firebird Embedded SQL Server
  • [Updated] Shutdown Manager
  • Building Windows Azure Cloud Service Applications with Azure Storage and the Azure SDK

  • Search CodeGuru:
     



    Go Back   CodeGuru Forums > Other Programming > Assembly
    FAQ Members List Calendar Search Today's Posts Mark Forums Read

    Assembly Questions and Answers for Assembly here!

    Reply
     
    Thread Tools Search this Thread Rate Thread Display Modes
      #1    
    Old April 18th, 2005, 05:10 PM
    flamik flamik is offline
    Junior Member
     
    Join Date: Apr 2005
    Posts: 3
    flamik is an unknown quantity at this point (<10)
    MIPS program need some help please :)

    Hi Guys,
    So I started writing this program where i want the user to input a string
    of numbers and letters and then i want to print out just the letters from
    the sting ignoring all the letters and other characters such as , ; : * &...
    I got it to take the string no problem and then i did the bgt and blt 's so
    that it skips all the ascii characters i don't want it to use but when it prints out
    the resulting string I'm still getting the original string ;( I have no idea
    where I made the mistake Please give me some ideas thx

    Code:
    .data 
    ask:     .asciiz "Type a character string (<31 chars long): " 
    count: 	.asciiz "number: "
    maxlen:  .word 31 
    buffer:  .space 31            # allocates 31 bytes of memory in the data segment 
    str:     .space 31 
    	
    
    .text 
            .globl main
    
    main: 	
    	 li $v0, 4 
             la $a0, ask          	# Print "Type a character string: " 
             syscall 
    
             la $a0, buffer       	# $a0 holds the address of the read buffer 
             lw $a1, maxlen       	# Max number of chars (including the end of string char) 
             li $v0, 8            	# Load the service number 
             syscall              	# Call the operating system 
    
    # Copy the buffer into str and replace lower case letters with upper case letters 
    
             li $t2, 58           	# the ASCII code of ":" 
    	 li $t3, 47		# the ASCII code of "/" 
             li $t0, 0            	# $t0 is the index
    	 li $t4, 0
    
    	
    loop:	 
    	 lb $t1, buffer($t0)  	# fetch a char from the buffer 
    	 blt $t1, $t2, skip   	# the char is before ":", skip it Branch on Less Than
             bgt $t1, $t3, skip   	# the char is after "/", skip it  Branch on Greater Than
    	 
    
    skip:    
    	 addi $t4, $t4, 1           
    	 sb $t1, str($t0)     	# and store it into str 
    	 addi $t0, $t0, 1     	# increment index 
    	 bne $t1, $0, loop    	# if $t1 <> "end of string" then goto loop 
    
    	 
    
    	 li $v0, 4 
             la $a0, str          	# Print str 
             syscall 
    
    	 sub $t4, $t4, 2
    	 li $v0, 4
    	 la $a0, count
    	 syscall
    	 move $a0, $t4
    	 li $v0, 1
    	 syscall
    Reply With Quote
      #2    
    Old April 19th, 2005, 11:10 AM
    NigelQ's Avatar
    NigelQ NigelQ is offline
    Elite Member
     
    Join Date: Sep 2001
    Location: San Diego
    Posts: 2,147
    NigelQ has a spectacular aura about (150+)NigelQ has a spectacular aura about (150+)
    Re: MIPS program need some help please :)

    It looks like your branch to skip is not skipping anything, maybe skip needs to be moved like below?

    Code:
    loop:	 
    	 lb $t1, buffer($t0)  	# fetch a char from the buffer 
    	 blt $t1, $t2, skip   	# the char is before ":", skip it Branch on Less Than
             bgt $t1, $t3, skip   	# the char is after "/", skip it  Branch on Greater Than
    	 
    #from here
    	 addi $t4, $t4, 1           
    	 sb $t1, str($t0)     	# and store it into str 
    #to here...
    skip:    
    	 addi $t0, $t0, 1     	# increment index 
    	 bne $t1, $0, loop    	# if $t1 <> "end of string" then goto loop
    You should also ensure that the result string is correctly null terminated if that's what you need. The code here assumes that there is a null terminator in the source string (and you may now be skipping the null).

    The easiest way to acheive this might be to fill str will nulls before the loop.

    Hope this helps,

    - Nigel
    Reply With Quote
      #3    
    Old April 20th, 2005, 08:12 AM
    flamik flamik is offline
    Junior Member
     
    Join Date: Apr 2005
    Posts: 3
    flamik is an unknown quantity at this point (<10)
    Re: MIPS program need some help please :)

    HI,
    THank you for replying
    I tried doing as you said but now I am getting no answer at all for the
    resulting string ;(
    I don't know what other approach i can come up with
    Reply With Quote
      #4    
    Old April 20th, 2005, 11:43 AM
    NigelQ's Avatar
    NigelQ NigelQ is offline
    Elite Member
     
    Join Date: Sep 2001
    Location: San Diego
    Posts: 2,147
    NigelQ has a spectacular aura about (150+)NigelQ has a spectacular aura about (150+)
    Re: MIPS program need some help please :)

    I would re-check the logic of what you are testing for in your branch jumps.

    Jump to skip on less than ':' and also greater than '/'

    So, with '/' being less than ':' it will always branch.

    You said you want to just collect letters from the string. You will need to modify the code to branch to skip if less than 'A' and branch if greater than 'z'

    You would also need to branch if greater than 'Z' AND less than 'a'

    Hope this helps,

    - Nigel
    Reply With Quote
      #5    
    Old April 20th, 2005, 02:48 PM
    flamik flamik is offline
    Junior Member
     
    Join Date: Apr 2005
    Posts: 3
    flamik is an unknown quantity at this point (<10)
    Talking Re: MIPS program need some help please :)

    AHHHHH :O) I FOUND MY MISTAKE :O) so silly so silly :O) i just added another sb in the skip label for my index and moved the label as you suggested and WORKS
    thanks a bunch ;O)
    Reply With Quote
    Reply

    Bookmarks
    Go Back   CodeGuru Forums > Other Programming > Assembly


    Thread Tools Search this Thread
    Search this Thread:

    Advanced Search
    Display Modes 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

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


    All times are GMT -5. The time now is 02:51 AM.



    Acceptable Use Policy

    internet.comMediabistrojusttechjobs.comGraphics.com

    WebMediaBrands Corporate Info


    Advertise | Newsletters | Feedback | Submit News

    Legal Notices | Licensing | Permissions | Privacy Policy


    Powered by vBulletin® Version 3.7.3
    Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
    Copyright WebMediaBrands Inc. 2002-2009