EASy68K
http://www.easy68k.com/EASy68Kforum/

I JUST TRIED A THING...
http://www.easy68k.com/EASy68Kforum/viewtopic.php?f=5&t=992
Page 1 of 1

Author:  chevi [ Thu Apr 07, 2011 2:09 am ]
Post subject:  I JUST TRIED A THING...

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

:?: :?: :(

Author:  lee [ Thu Apr 07, 2011 2:53 am ]
Post subject: 

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.

Author:  clive [ Thu Apr 07, 2011 3:07 am ]
Post subject: 

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

Author:  lee [ Thu Apr 07, 2011 3:13 am ]
Post subject: 

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.

Author:  clive [ Thu Apr 07, 2011 1:59 pm ]
Post subject: 

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

Author:  chevi [ Thu Apr 07, 2011 4:48 pm ]
Post subject: 

Thanks so much clive

Page 1 of 1 All times are UTC
Powered by phpBB® Forum Software © phpBB Group
http://www.phpbb.com/