Guest User

Untitled

a guest
Aug 4th, 2018
115
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. *-----------------------------------------------------------
  2. * Program    :
  3. * Written by :
  4. * Date       :
  5. * Description:
  6. *-----------------------------------------------------------
  7.     ORG $1000
  8. START:              ; first instruction of program
  9.     move.l  #$7FFE,SP   ; initialise stack pointer
  10.     move.b  #0,d1       ; Turn off the auto echo
  11.     move.b  #12,d0
  12.     trap    #15
  13.    
  14.     move.l  #$2000,a1   ; move address $2000 into a1
  15.    
  16.     move.l  #string1,a0 ;Print user promt1
  17. prompt1:
  18.     move.b  (a0)+,d1
  19.     beq input
  20.     move.b  #6,d0
  21.     trap    #15
  22.     bra prompt1
  23.            
  24. input:
  25.     move.b  #5,d0       ; take character input
  26.     trap    #15
  27.     move.b  #6,d0       ; print the charactrer input
  28.     trap    #15
  29.    
  30.     cmp.b   #cr,d1      ; escape loop if a cr entered
  31.     beq length
  32.    
  33.     move.b  d1,(a1)+    ; increment array
  34.     add.b   #1,d2       ; add to length counter
  35.     bra input       ; branch to start of loop
  36.    
  37. length:        
  38.     move.b  #cr,d1      ; Print a carriage return
  39.     move.b  #6,d0
  40.     trap    #15
  41.     move.b  #lf,d1      ; Print a line feed
  42.     move.b  #6,d0
  43.     trap    #15
  44.    
  45.     move.b  d2,d1       ; Print the sting length
  46.     move.b  #3,d0
  47.     trap    #15
  48.    
  49.     move.l  #string2,a0 ; Print user promt2
  50. prompt2:
  51.     move.b  (a0)+,d1
  52.     beq output
  53.     move.b  #6,d0
  54.     trap    #15
  55.     bra prompt2
  56.    
  57. output:             ; Print the users input
  58.     move.l  #$2000,a0
  59. next:
  60.     cmp.b   d3,d2
  61.     beq palcheck
  62.     move.b  (a0)+,d1
  63.     move.b  #6,d0
  64.     trap    #15
  65.     add.b   #$1,d3
  66.     bra next
  67.                
  68. palcheck:           ; Check for palindrome
  69.     move.l  #$2000,a2   ; Set up two arrays
  70.     move.l  #$2000,a3
  71.     sub.b   #$1,d3      ; minus one for second array reference
  72.     add.l   d3,a3
  73. palloop:
  74.     cmp.b   d6,d2       ; compare loop iteration to array size
  75.     beq ispal
  76.     move.b  (a2),d4
  77.     move.b  (a3),d5
  78.     add.l   #$1,a2      ; increment a2
  79.     sub.l   #$1,a3      ; decrement a3
  80.     cmp.b   d4,d5
  81.     bne notpal
  82.     add.b   #$1,d6      ; increment loop interation
  83.     bra palloop
  84.    
  85. ispal:              ; Print string3
  86.     move.b  #cr,d1      ; Print a carriage return
  87.     move.b  #6,d0
  88.     trap    #15
  89.     move.b  #lf,d1      ; Print a line feed
  90.     move.b  #6,d0
  91.     trap    #15
  92.     move.l  #string3,a0
  93. ispaloutput:
  94.     move.b  (a0)+,d1
  95.     beq reinit
  96.     move.b  #6,d0
  97.     trap    #15
  98.     bra ispaloutput
  99.    
  100. notpal:             ; Print string4
  101.     move.b  #cr,d1      ; Print a carriage return
  102.     move.b  #6,d0
  103.     trap    #15
  104.     move.b  #lf,d1      ; Print a line feed
  105.     move.b  #6,d0
  106.     trap    #15
  107.     move.l  #string4,a0
  108. notpaloutput:
  109.     move.b  (a0)+,d1
  110.     beq reinit
  111.     move.b  #6,d0
  112.     trap    #15
  113.     bra notpaloutput   
  114.    
  115. reinit:             ; reinitilise the registers
  116.     move.b  #$0,d0
  117.     move.b  #$0,d1
  118.     move.b  #$0,d2
  119.     move.b  #$0,d3
  120.     move.b  #$0,d4
  121.     move.b  #$0,d5
  122.     move.b  #$0,d6
  123.    
  124.     move.l  #$0,a0
  125.     move.l  #$0,a1
  126.     move.l  #$0,a2
  127.     move.l  #$0,a3
  128.    
  129.     move.b  #cr,d1      ; Print a carriage return
  130.     move.b  #6,d0
  131.     trap    #15
  132.     move.b  #lf,d1      ; Print a line feed
  133.     move.b  #6,d0
  134.     trap    #15
  135.     move.b  #6,d0
  136.     trap    #15
  137.    
  138.     bra start       ; Loop back to start
  139.        
  140.     MOVE.B  #9,D0
  141.     TRAP    #15     ; halt simulator
  142.  
  143.  
  144.  
  145. * Variables and Strings
  146.    
  147.     ORG $2500
  148. string1 dc.b    'Please enter a string and press return: ',null
  149. string2 dc.b    ' characters entered: ',null
  150. string3 dc.b    'It was a palindrome',null
  151. string4 dc.b    'It was not a palindrome',null
  152. null    equ $00
  153. cr  equ $0D
  154. lf  equ $0A
  155.  
  156.     END START       ; last line of source
  157.  
  158. *~Font name~Courier New~
  159. *~Font size~10~
  160. *~Tab type~1~
  161. *~Tab size~8~
Add Comment
Please, Sign In to add comment