Welcome to Dream.In.Code
Getting Help is Easy!

Join 118,660 Programmers for FREE! Ask your question and get quick answers from experts. There are 856 online right now! We've got more than 500 tutorials and 2,000 snippets. Join and find out why Dream.In.Code is the #1 programming help community on the internet! Registration is fast and FREE... Join Now!



68K

 
Reply to this topicStart new topic

68K

scorpionviolinist
post 26 Jun, 2008 - 02:00 PM
Post #1


New D.I.C Head

*
Joined: 29 Feb, 2008
Posts: 36

Hi. I have to write and demonstrate a subroutine whose job is accept a sentence typed by the user, and return another text string with the words in reverse order. For instance, if I call your program and give you the text string “you are great”, your subroutine would return the text string “great are you”.
This is the code that will call the subroutine:
CODE
ORG $400
START LEA $4000,SP Set the stack location
*
* Code to read keyboard input goes here. User types in a string.
* User’s code stores the string at INDATA and its length at INDL
*
PEA INDATA This is where I stored the typed sentence
PEA INDL This is the address of the length of the
sentence (in bytes)
PEA OUTDATA This is where the subroutine will put its
reversed sentence.
BSR REVERSE Call the subroutine
LEA 12(SP),SP Clean up the stack (3 addresses: 12 bytes)
*
* The user’s code to print the string returned by the subroutine
* would go here as needed.
*
MOVE.W #5,D0 Code to stop execution
TRAP #15 End of execution
*
INDATA DS.B 100 Set aside 100 bytes for input
INDL DS.W Set aside a word to store text length
OUTDATA DS.B 100 Set aside 100 bytes to store output
*
* I will insert your subroutine here.
* Make sure your subroutine starts with a ORG $1000 and
* that it does not include any code to do I/O or halt execution!
*
END START



and this is what I have thus far:

CODE
    ORG    $1000
REVERSE MOVE.W    SR,-(SP)        
    MOVEM.L    D0-D7/A0-A6,-(SP)    Save working registers
    
SNTNC    MOVEA.L    70(A7),A0        Get address of length of sentence
    MOVEA.L    74(A7),A1        Get stored sentence

    MOVE.L    A1,BEGPTR        Save beginning of word
SCAN    MOVE.B    (A1)+,D1        Get current byte and index
    CMP.B    #$20,D1            Is the byte a space?
    BNE    SCAN            If not, go to SCAN

REVRSD    MOVE.L

RETURN    MOVEM.L (SP)+,D0-D7/A0-A6
    RTS


The problem is, I do not know where to go after the scan finds a blank(end of the first word). I need to store it at the end (so the word 'you' would start where the word 'great' ended originally).
I am confused on where to go from the first scan.
Please help.
User is offlineProfile CardPM

Go to the top of the page

Fast ReplyReply to this topicStart new topic
Time is now: 10/12/08 04:04AM

Live Help!

Tutorials

Programming

Web Development

Reference Sheets

Code Snippets

Bye Bye Ads

Free DIC T-Shirt

T-Shirt Example

Related Sites

Monthly Drawing

Thumb Drive

Partners

Top Contributors

Top 10 Kudos This Month