0 Replies - 1101 Views - Last Post: 26 June 2008 - 02:00 PM Rate Topic: -----

#1 scorpionviolinist  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 36
  • Joined: 29-February 08

68K

Post icon  Posted 26 June 2008 - 02:00 PM

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:
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:

	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.

Is This A Good Question/Topic? 0
  • +

Page 1 of 1