Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #palindrome
- .data
- str: .string "madam" # string to check
- .text
- la x3,str
- li sp,0x500 # initialize stack pointer
- # block below loads string to stack (LIFO)
- rpt:
- lbu x4,0(x3)
- beq x4,x0,retr
- addi x8,x8,1
- sb x4,-1(sp)
- addi x3,x3,1
- addi sp,sp,-1
- j rpt
- retr:
- la x3,str
- addi x1,x0,1 # set result to 1
- next:
- lbu x6,0(sp)
- lbu x4,0(x3)
- bne x4,x6,exit # exits if palindrome check fails
- addi sp,sp,1
- addi,x3,x3,1
- addi x8,x8,-1
- beq x8,x0, last # check loop counter
- j next
- exit:
- addi x1,x0,0 # sets result to 0l
- j last
- last:
- nop
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement