Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- *-----------------------------------------------------------
- * Program :
- * Written by :
- * Date :
- * Description:
- *-----------------------------------------------------------
- ORG $1000
- START: ; first instruction of program
- move.l #$7FFE,SP ; initialise stack pointer
- move.b #0,d1 ; Turn off the auto echo
- move.b #12,d0
- trap #15
- move.l #$2000,a1 ; move address $2000 into a1
- move.l #string1,a0 ;Print user promt1
- prompt1:
- move.b (a0)+,d1
- beq input
- move.b #6,d0
- trap #15
- bra prompt1
- input:
- move.b #5,d0 ; take character input
- trap #15
- move.b #6,d0 ; print the charactrer input
- trap #15
- cmp.b #cr,d1 ; escape loop if a cr entered
- beq length
- move.b d1,(a1)+ ; increment array
- add.b #1,d2 ; add to length counter
- bra input ; branch to start of loop
- length:
- move.b #cr,d1 ; Print a carriage return
- move.b #6,d0
- trap #15
- move.b #lf,d1 ; Print a line feed
- move.b #6,d0
- trap #15
- move.b d2,d1 ; Print the sting length
- move.b #3,d0
- trap #15
- move.l #string2,a0 ; Print user promt2
- prompt2:
- move.b (a0)+,d1
- beq output
- move.b #6,d0
- trap #15
- bra prompt2
- output: ; Print the users input
- move.l #$2000,a0
- next:
- cmp.b d3,d2
- beq palcheck
- move.b (a0)+,d1
- move.b #6,d0
- trap #15
- add.b #$1,d3
- bra next
- palcheck: ; Check for palindrome
- move.l #$2000,a2 ; Set up two arrays
- move.l #$2000,a3
- sub.b #$1,d3 ; minus one for second array reference
- add.l d3,a3
- palloop:
- cmp.b d6,d2 ; compare loop iteration to array size
- beq ispal
- move.b (a2),d4
- move.b (a3),d5
- add.l #$1,a2 ; increment a2
- sub.l #$1,a3 ; decrement a3
- cmp.b d4,d5
- bne notpal
- add.b #$1,d6 ; increment loop interation
- bra palloop
- ispal: ; Print string3
- move.b #cr,d1 ; Print a carriage return
- move.b #6,d0
- trap #15
- move.b #lf,d1 ; Print a line feed
- move.b #6,d0
- trap #15
- move.l #string3,a0
- ispaloutput:
- move.b (a0)+,d1
- beq reinit
- move.b #6,d0
- trap #15
- bra ispaloutput
- notpal: ; Print string4
- move.b #cr,d1 ; Print a carriage return
- move.b #6,d0
- trap #15
- move.b #lf,d1 ; Print a line feed
- move.b #6,d0
- trap #15
- move.l #string4,a0
- notpaloutput:
- move.b (a0)+,d1
- beq reinit
- move.b #6,d0
- trap #15
- bra notpaloutput
- reinit: ; reinitilise the registers
- move.b #$0,d0
- move.b #$0,d1
- move.b #$0,d2
- move.b #$0,d3
- move.b #$0,d4
- move.b #$0,d5
- move.b #$0,d6
- move.l #$0,a0
- move.l #$0,a1
- move.l #$0,a2
- move.l #$0,a3
- move.b #cr,d1 ; Print a carriage return
- move.b #6,d0
- trap #15
- move.b #lf,d1 ; Print a line feed
- move.b #6,d0
- trap #15
- move.b #6,d0
- trap #15
- bra start ; Loop back to start
- MOVE.B #9,D0
- TRAP #15 ; halt simulator
- * Variables and Strings
- ORG $2500
- string1 dc.b 'Please enter a string and press return: ',null
- string2 dc.b ' characters entered: ',null
- string3 dc.b 'It was a palindrome',null
- string4 dc.b 'It was not a palindrome',null
- null equ $00
- cr equ $0D
- lf equ $0A
- END START ; last line of source
- *~Font name~Courier New~
- *~Font size~10~
- *~Tab type~1~
- *~Tab size~8~
Add Comment
Please, Sign In to add comment