Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ;;; Name: Shreyas Vaidya
- ;;; UID: 115415522
- ;;; Directory ID: shreyasv
- ;;; Implementation that computes a palindrome with a given array
- .global is_palindrome ; exposes is_palindrome as a label
- is_palindrome: ; the next instruction starts is_palindrome()
- ;; Add your code here
- mov r27, r25 ; copies argument to X pointer
- mov r26, r24
- push r30
- push r31
- mov r31, r25 ; copies argument to Z pointer
- mov r30, r24
- clr r20
- clr r21
- clr r22
- clr r23
- push r26
- push r27
- push r30
- push r31
- call strlen
- mov r20, r24 ; r20 now contains string length
- pop r31
- pop r30
- pop r27
- pop r26
- add r30, r16
- 2:
- ld r16, -Z ; gets Z to the end of the string
- subi r20, 1
- add r26, r20
- 3: ld r22, X+ ; loops through data-1/2 times & checks
- lsr r20 ; divides r14 by 2
- 6: ldi r18, 0
- cp r16, r22
- brne 5f
- cp r20, r18
- breq 4f
- add r18, 1
- jmp 6b
- 4: ldi r24, 1
- clr r25
- jmp 1f
- 5: ldi r24, 0
- clr r25
- jmp 1f
- 1:
- pop r31
- pop r30
- ret
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement