Advertisement
foreverfugazi

palindrome check

Sep 18th, 2024 (edited)
63
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.62 KB | None | 0 0
  1. #palindrome
  2. .data
  3. str: .string "madam" # string to check
  4. .text
  5. la x3,str
  6. li sp,0x500 # initialize stack pointer
  7.  
  8. # block below loads string to stack (LIFO)
  9. rpt:
  10. lbu x4,0(x3)
  11. beq x4,x0,retr
  12. addi x8,x8,1
  13. sb x4,-1(sp)
  14. addi x3,x3,1
  15. addi sp,sp,-1
  16. j rpt
  17. retr:
  18. la x3,str
  19. addi x1,x0,1 # set result to 1
  20. next:
  21. lbu x6,0(sp)
  22. lbu x4,0(x3)
  23. bne x4,x6,exit # exits if palindrome check fails
  24. addi sp,sp,1
  25. addi,x3,x3,1
  26. addi x8,x8,-1
  27. beq x8,x0, last # check loop counter
  28. j next
  29. exit:
  30. addi x1,x0,0 # sets result to 0l
  31. j last
  32. last:
  33. nop
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement