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.