EASy68K  
It is currently Wed Sep 19, 2018 5:37 am

All times are UTC




Post new topic Reply to topic  [ 6 posts ] 
Author Message
 Post subject: I JUST TRIED A THING...
PostPosted: Thu Apr 07, 2011 2:09 am 
Offline

Joined: Mon Mar 21, 2011 11:44 pm
Posts: 5
Location: Jamaica
WELL I AM VERY NEW TO THIS EASY68K BUT I HAVE BEEN TRYING THIS ALL DAY AND I REALLY DON'T KNOW WHERE I AM GOING WRONG. SOME1 PLEASE HELP,I'M JUST GETTING AN EARLY START TO PREPARING FOR MY FINALS. ANY HELP IS GREATLY APPRECIATED!
Code:
*-----------------------------------------------------------
* Program    :
* Written by : CHEVI
* Date       : APRIL 2,2011
* Description: REVERSING A STRING
*-----------------------------------------------------------
   ORG   $2000
START:            ; first instruction of program

   MOVE.B   #14,D0      ; Prompt user to enter string
   LEA   Prompt,A1
   TRAP   #15
   
   MOVE.B   #2,D0      ;Accept string
   LEA   S1,A0
   TRAP    #15
   
REV:   MOVE.B   #14,D0
   LEA   IT,A1      ;Display text 'Reversed string is:'
   TRAP   #15
   CMPA.L   #S1,A0      ;Is a0 back to pointing at the start of the string
   BEQ   END      ;if yes,branch to 'END'
   MOVE.B   -(A0),D1   ;if no,copy the next last character into D1 ready for display
   MOVE.B   #6,D0      ;display the character
   TRAP   #15
   BRA   REV
   
END:   MOVE.L   #$0A,D1      
   MOVE.B   #6,D0
   TRAP   #15
   MOVE.L   #$0D,D1
   MOVE.B   #6,D0
   TRAP   #15
   
   
;CHAR:   MOVE.B   #6,D0
   ;TRAP   #15
   ;RTS
   
DONE:   MOVE.B   #9,D0
   TRAP   #15      ; halt simulator

* Variables and Strings
   ORG   $4000
   
CR:   EQU   $0D         ;Carriage Return
LF:   EQU   $0A         ;Line Feed
NULL:   EQU   $00         ;String Terminator

S1:   DS.B   80
Prompt: DC.B   'Enter a string',CR,LF,0
IT:   DC.B   'REVERSED STRING: ',0



   END   START      ; last line of source

:?: :?: :(

_________________
:) Thank You


Top
 Profile  
 
 Post subject:
PostPosted: Thu Apr 07, 2011 2:53 am 
Offline

Joined: Mon Dec 27, 2004 11:40 pm
Posts: 318
To get the string the pointer to the space in memory needs to be in a1 not a0.

After you get the string you need to add the string length to the pointer to the string and put that in a0.

The outputting of the 'REVERSED STRING: ' string needs to be before the output loop not in it.

Lee.


Top
 Profile  
 
 Post subject:
PostPosted: Thu Apr 07, 2011 3:07 am 
Offline

Joined: Mon Jul 26, 2010 11:43 pm
Posts: 198
Location: Aurora, IL
Code:
CR:   EQU   $0D         ;Carriage Return
LF:   EQU   $0A         ;Line Feed
NULL:   EQU   $00         ;String Terminator

   ORG   $2000
START:            ; first instruction of program

   MOVE.B   #14,D0      ; Prompt user to enter string
      LEA   Prompt,A1
      TRAP   #15
   
   MOVE.B   #2,D0      ;Accept string
   LEA   S1,A1      ; A1 = buffer
   TRAP    #15
   
   MOVE.B   #14,D0
   LEA   IT,A1         ;Display text 'Reversed string is:'
   TRAP   #15

      LEA   S1,A0      ; Find end of string
LEN:   MOVE.B   (A0)+,D0
   BNE   LEN
   SUBA.L   #1,A0      ;point back to NUL

   ; Now work backward printing one character at a time
   
REV:   MOVE.B   -(A0),D1      ;copy the next last character into D1 ready for display

      MOVE.B  #6,D0         ;display the character
      TRAP      #15

      CMPA.L  #S1,A0         ;Is a0 back to pointing at the start of the string
      BNE   REV        ; no      
   
END:   MOVE.L   #CR,D1     
      MOVE.B   #6,D0
      TRAP   #15
      MOVE.L   #LF,D1
      MOVE.B   #6,D0
      TRAP   #15
   
DONE:   MOVE.B  #9,D0
   TRAP   #15      ; halt simulator

* Variables and Strings
   ORG   $4000
   
S1:   DS.B   80
Prompt: DC.B   'Enter a string',CR,LF,0
IT:   DC.B   'REVERSED STRING: ',0

   END   START      ; last line of source


Top
 Profile  
 
 Post subject:
PostPosted: Thu Apr 07, 2011 3:13 am 
Offline

Joined: Mon Dec 27, 2004 11:40 pm
Posts: 318
You don't need to find the end of the string, you can calculate the initial value for a0 by adding d1.w to the string pointer.

Lee.


Top
 Profile  
 
 Post subject:
PostPosted: Thu Apr 07, 2011 1:59 pm 
Offline

Joined: Mon Jul 26, 2010 11:43 pm
Posts: 198
Location: Aurora, IL
Interesting side effect, I just skimmed the documentation.

Code:
CR:     EQU     $0D             ;Carriage Return
LF:     EQU     $0A             ;Line Feed
NULL:   EQU     $00             ;String Terminator

        ORG     $2000
START:            ; first instruction of program

        MOVE.B  #14,D0          ; Prompt user to enter string
        LEA     Prompt,A1
        TRAP    #15

        MOVE.B  #2,D0           ;Accept string
        LEA     S1,A1           ; A1 = buffer
        TRAP    #15

        LEA     (A1,D1.W),A0    ;Compute address of NUL from length in D1.W, A0 preseved across next trap

        MOVE.B  #14,D0
        LEA     IT,A1           ;Display text 'Reversed string is:'
        TRAP    #15

        ; Now work backward printing one character at a time

REV:    MOVE.B  -(A0),D1        ;copy the next last character into D1 ready for display

        MOVE.B  #6,D0           ;display the character
        TRAP    #15

        CMPA.L  #S1,A0          ;Is a4 back to pointing at the start of the string
        BNE     REV             ; no

END:    MOVE.L  #CR,D1
        MOVE.B  #6,D0
        TRAP    #15
        MOVE.L  #LF,D1
        MOVE.B  #6,D0
        TRAP    #15

DONE:   MOVE.B  #9,D0
        TRAP    #15      ; halt simulator

* Variables and Strings
        ORG     $4000

S1:     DS.B    80
Prompt: DC.B    'Enter a string',CR,LF,0
IT:     DC.B    'REVERSED STRING: ',0

        END     START      ; last line of source


Top
 Profile  
 
 Post subject:
PostPosted: Thu Apr 07, 2011 4:48 pm 
Offline

Joined: Mon Mar 21, 2011 11:44 pm
Posts: 5
Location: Jamaica
Thanks so much clive

_________________
:) Thank You


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 6 posts ] 

All times are UTC


Who is online

Users browsing this forum: No registered users and 2 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB® Forum Software © phpBB Group