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

PROGRAM TO REVERSE SIX NUMBERS
http://www.easy68k.com/EASy68Kforum/viewtopic.php?f=6&t=1005
Page 1 of 1

Author:  lokmanwar [ Sat Apr 23, 2011 5:35 pm ]
Post subject:  PROGRAM TO REVERSE SIX NUMBERS

.A

Author:  lee [ Sat Apr 23, 2011 5:59 pm ]
Post subject: 

Between outputting the numbers you need to output something, such as a newline or space, to separate them.

Also, the code to stop the simulator should be at the end of the program, not at the end of the page.

Lee.

Author:  lokmanwar [ Sat Apr 23, 2011 6:13 pm ]
Post subject: 

lee wrote:
Between outputting the numbers you need to output something, such as a newline or space, to separate them.

Also, the code to stop the simulator should be at the end of the program, not at the end of the page.

Lee.


M TRYING TO PUT A NEW LINE BUT "CR,LF" DONT WORK IN MIDDLE OF THE PROGRAMME

Author:  clive [ Sat Apr 23, 2011 7:56 pm ]
Post subject: 

Code:
CR      EQU     $0D             *ASCII code for carriage return

LF      EQU     $0A             *ASCII code for line feed


        ORG     $1000           *The program will load into address $1000

START:

*INPUT SIX NUMBERS FROM KEYBOARD

        LEA     MESSAGE1,A1     *Loads message into address register A1
        MOVE.B  #14,D0          *Moves number 14 into data regiter D0
        TRAP    #15             *Displays Message

        BSR     get_num         *Branch to subroutine to get Number1

        MOVE.W  D1,-(SP)        *Push d1 on SP

        BSR     get_num         *Branch to subroutine to get Number2

        MOVE.W  D1,-(SP)        *Push d1 on stack

        BSR     get_num         *Branch to subroutine to get Number3

        MOVE.W  D1,-(SP)        *Push d1 on SP

        BSR     get_num         *Branch to subroutine to get Number4

        MOVE.W  D1,-(SP)        *Push d1 on stack

        BSR     get_num         *Branch to subroutine to get Number5

        MOVE.W  D1,-(SP)        *Push d1 on SP

        BSR     get_num         *Branch to subroutine to get Number6

        MOVE.W  D1,-(SP)        *Push d1 on stack

*DISPLAY REVERSED ORDER OF THE SIX NUMBERS

        LEA     MESSAGE2,A1     *Loads message into address register A1
        MOVE.B  #14,D0          *Moves number 14 into data regiter D0
        TRAP    #15             *Displays Message

        MOVE.W  (SP)+,D1        *Recover value from stack

        BSR     put_num         *Display the Number6

        MOVE.W  (SP)+,D1        *Recover value from stack

        BSR     put_num         *Display the Number5

        MOVE.W  (SP)+,D1        *Recover value from stack

        BSR     put_num         *Display the Number4

        MOVE.W  (SP)+,D1        *Recover value from stack

        BSR     put_num         *Display the Number3

        MOVE.W  (SP)+,D1        *Recover value from stack

        BSR     put_num         *Display the Number2

        MOVE.W  (SP)+,D1        *Recover value from stack

        BSR     put_num         *Display the Number1

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

*--------------------------------------------------------------------

*Subroutine to get number from the keyboard

get_num MOVE.B  #4,D0           *Select number input
        TRAP    #15             *Move number to D1
        RTS                     *Return from subroutine to programme

*--------------------------------------------------------------------

*Subroutine to output number to screen, and CR,LF

put_num MOVE.B  #3,D0           *Select number output
        TRAP    #15

*--------------------------------------------------------------------

crlf    LEA     MSG_CRLF,A1     *Loads message into address register A1
        MOVE.B  #14,D0          *Moves number 14 into data regiter D0
        TRAP    #15             *Displays Message
        RTS

*--------------------------------------------------------------------

MESSAGE1 DC.B   'ENTER SIX NUMBERS:',CR,LF,0

MESSAGE2 DC.B   'REVERSE ORDER IS:'

MSG_CRLF DC.B   CR,LF, 0

*---------------------------------------------------------------------

        END    START      ; last line of source

Author:  profkelly [ Sat Apr 23, 2011 8:01 pm ]
Post subject: 

Notice in Clive's example the put_num subroutine does NOT have an RTS at the end so it falls through into the crlf subroutine and runs that also.

Author:  lokmanwar [ Sun Apr 24, 2011 6:08 pm ]
Post subject: 

@.

Author:  clive [ Sun Apr 24, 2011 8:12 pm ]
Post subject: 

lokmanwar wrote:
thank you clieve for solving my problems but can you please remove the codes from your post

If submitting my code as the answer to your assignment without citation is problematic, Caveat emptor.

Author:  clive [ Mon Apr 25, 2011 5:06 pm ]
Post subject: 

An alternate solution using looping.
Code:
CR      EQU     $0D             *ASCII code for carriage return

LF      EQU     $0A             *ASCII code for line feed

        ORG     $1000           *The program will load into address $1000

START:

*INPUT SIX NUMBERS FROM KEYBOARD

        LEA     MESSAGE1,A1     *Loads message into address register A1
        MOVE.B  #14,D0          *Moves number 14 into data regiter D0
        TRAP    #15             *Displays Message

        MOVE.W  #6-1,D4         *Get 6 numbers

get_loop
        BSR     get_num         *Branch to subroutine to get number

        MOVE.W  D1,-(SP)        *Push D1 on SP/stack

        DBRA    D4,get_loop     *Iterate

*DISPLAY REVERSED ORDER OF THE SIX NUMBERS

        LEA     MESSAGE2,A1     *Loads message into address register A1
        MOVE.B  #14,D0          *Moves number 14 into data regiter D0
        TRAP    #15             *Displays Message

        MOVE.W  #6-1,D4         *Put 6 numbers

put_loop
        MOVE.W  (SP)+,D1        *Recover value from SP/stack to D1

        BSR     put_num         *Display the Number

        DBRA    D4,put_loop     *Iterate

*DONE

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

*--------------------------------------------------------------------

*Subroutine to get number from the keyboard

get_num MOVE.B  #4,D0           *Select number input
        TRAP    #15             *Move number to D1
        RTS                     *Return from subroutine to programme

*--------------------------------------------------------------------

*Subroutine to output number to screen, and CR,LF

put_num MOVE.B  #3,D0           *Select number output
        TRAP    #15

*--------------------------------------------------------------------

crlf    LEA     MSG_CRLF,A1     *Loads message into address register A1
        MOVE.B  #14,D0          *Moves number 14 into data regiter D0
        TRAP    #15             *Displays Message
        RTS

*--------------------------------------------------------------------

MESSAGE1 DC.B   'ENTER SIX NUMBERS:',CR,LF,0

MESSAGE2 DC.B   'REVERSE ORDER IS:'

MSG_CRLF DC.B   CR,LF, 0

*---------------------------------------------------------------------

        END    START      ; last line of source

BEng (Hons), Electrical and Electronic Engineering, University of Portsmouth (Portsmouth Polytechnic), UK

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