Other Programming Languages
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me

The Shed is going Social! Join us on FaceBook and Twitter and chime in on the conversation.

Go Back   Dev Shed ForumsProgramming Languages - MoreOther Programming Languages

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old December 4th, 2012, 01:49 PM
akerman akerman is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Oct 2012
Posts: 2 akerman User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 8 m 5 sec
Reputation Power: 0
Assembly - Words

Hi, guys I'm trying to calculate number of words inside the string however I'm not sure how to structure and loop and how to write it to detect the empty spaces.
I'm using Mars Assembly here is the structure I would like to use:
Code:
     
        .data
text_input: .asciiz "Two words"
word_count: .word 0
        .text
        .globl main
main:
        la $a0, text_input    # Load address of string.
        addi $t1, $a0, 0         
        nop 
Loop:
   lbu $t0, 0($t1) #go through string one by one

I'm at this stage however not sure what to do next...

Reply With Quote
  #2  
Old December 4th, 2012, 09:44 PM
OmegaZero OmegaZero is offline
Contributing User
Dev Shed Novice (500 - 999 posts)
 
Join Date: May 2007
Posts: 737 OmegaZero User rank is General (90000 - 100000 Reputation Level)OmegaZero User rank is General (90000 - 100000 Reputation Level)OmegaZero User rank is General (90000 - 100000 Reputation Level)OmegaZero User rank is General (90000 - 100000 Reputation Level)OmegaZero User rank is General (90000 - 100000 Reputation Level)OmegaZero User rank is General (90000 - 100000 Reputation Level)OmegaZero User rank is General (90000 - 100000 Reputation Level)OmegaZero User rank is General (90000 - 100000 Reputation Level)OmegaZero User rank is General (90000 - 100000 Reputation Level)OmegaZero User rank is General (90000 - 100000 Reputation Level)OmegaZero User rank is General (90000 - 100000 Reputation Level)OmegaZero User rank is General (90000 - 100000 Reputation Level)OmegaZero User rank is General (90000 - 100000 Reputation Level)OmegaZero User rank is General (90000 - 100000 Reputation Level)OmegaZero User rank is General (90000 - 100000 Reputation Level)OmegaZero User rank is General (90000 - 100000 Reputation Level) 
Time spent in forums: 3 Weeks 4 Days 22 h 50 m 16 sec
Reputation Power: 928
Where exactly are you stuck? Do you understand how to find word boundaries in the abstract (i.e. could you draw a flow chart or state machine of what you're trying to implement)? Do you understand how to write a loop over the characters in a string? Do you understand how to test the value of a character?
__________________
sub{*{$::{$_}}{CODE}==$_[0]&& print for(%:: )}->(\&Meh);

Reply With Quote
  #3  
Old December 5th, 2012, 01:37 AM
akerman akerman is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Oct 2012
Posts: 2 akerman User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 8 m 5 sec
Reputation Power: 0
I'm not sure how to write a loop and detect that the is chacater and space next to each other...

Reply With Quote
  #4  
Old December 5th, 2012, 09:34 AM
OmegaZero OmegaZero is offline
Contributing User
Dev Shed Novice (500 - 999 posts)
 
Join Date: May 2007
Posts: 737 OmegaZero User rank is General (90000 - 100000 Reputation Level)OmegaZero User rank is General (90000 - 100000 Reputation Level)OmegaZero User rank is General (90000 - 100000 Reputation Level)OmegaZero User rank is General (90000 - 100000 Reputation Level)OmegaZero User rank is General (90000 - 100000 Reputation Level)OmegaZero User rank is General (90000 - 100000 Reputation Level)OmegaZero User rank is General (90000 - 100000 Reputation Level)OmegaZero User rank is General (90000 - 100000 Reputation Level)OmegaZero User rank is General (90000 - 100000 Reputation Level)OmegaZero User rank is General (90000 - 100000 Reputation Level)OmegaZero User rank is General (90000 - 100000 Reputation Level)OmegaZero User rank is General (90000 - 100000 Reputation Level)OmegaZero User rank is General (90000 - 100000 Reputation Level)OmegaZero User rank is General (90000 - 100000 Reputation Level)OmegaZero User rank is General (90000 - 100000 Reputation Level)OmegaZero User rank is General (90000 - 100000 Reputation Level) 
Time spent in forums: 3 Weeks 4 Days 22 h 50 m 16 sec
Reputation Power: 928
You could keep track of the previous character from the string (or look at the characters stored at $t1 and $t1+1) then determine if you have a space/not-space pair.

Or since you don't actually care what the last characters are, just store if you are currently inside of a word. Then update your state according to the next character (in-word & space -> not-in-word; in-word & not-space -> in-word; not-in-word & space -> not-in-word; not-in-word & no-space -> in-word).

(FYI, It's easier for us to help (and we can provide better responses) if you are as detailed as possible about what you're trying to do and what is giving you difficulty. Also a good tool for solving programming problems is to write down exactly what you're trying to accomplish breaking it down into as small steps as possible. It has been a while so we may not recall where the pitfalls are until we understand what is giving you trouble.)

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming Languages - MoreOther Programming Languages > Assembly - Words

Developer Shed Advertisers and Affiliates



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

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump

Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 


Powered by: vBulletin Version 3.0.5
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.

© 2003-2013 by Developer Shed. All rights reserved. DS Cluster - Follow our Sitemap