Advertisement
Guest User

Untitled

a guest
Apr 16th, 2019
376
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. ;;; Name: Shreyas Vaidya
  2. ;;; UID: 115415522
  3. ;;; Directory ID: shreyasv
  4.  
  5. ;;; Implementation that computes a palindrome with a given array
  6.  
  7.     .global is_palindrome       ; exposes is_palindrome as a label
  8. is_palindrome:                  ; the next instruction starts is_palindrome()
  9.         ;; Add your code here
  10.     mov r27, r25        ; copies argument to X pointer
  11.     mov r26, r24
  12.     push r30
  13.     push r31
  14.     mov r31, r25        ; copies argument to Z pointer
  15.     mov r30, r24
  16.     clr r20
  17.     clr r21
  18.     clr r22
  19.     clr r23
  20.     push r26
  21.     push r27
  22.     push r30
  23.     push r31
  24.     call strlen
  25.     mov r20, r24        ; r20 now contains string length
  26.     pop r31
  27.     pop r30
  28.     pop r27
  29.     pop r26
  30.     add r30, r16
  31.  
  32. 2:
  33.     ld r16, -Z      ; gets Z to the end of the string
  34.     subi r20, 1
  35.     add r26, r20   
  36.  
  37. 3:  ld r22, X+      ; loops through data-1/2 times & checks
  38.     lsr r20         ; divides r14 by 2
  39.    
  40. 6:  ldi r18, 0
  41.     cp r16, r22
  42.     brne 5f
  43.     cp r20, r18
  44.     breq 4f
  45.     add r18, 1
  46.     jmp 6b
  47.    
  48. 4:  ldi r24, 1
  49.     clr r25
  50.     jmp 1f
  51.    
  52. 5:  ldi r24, 0
  53.     clr r25
  54.     jmp 1f
  55.    
  56. 1:
  57.     pop r31
  58.     pop r30
  59.     ret
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement