Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ;;Inputs:
- ;; HL=16-bit number to check palindrome status
- ;; IX=pointer to end of string buffer
- ;;Outputs:
- ;; Condition NZ if number is not a palindrome, Z otherwise.
- isPalindrome:
- ld b,5
- _hl2String:
- push bc ;Save loop counter
- call divideHL10
- ld a,l
- add a,'0'
- ld (ix),a ;Write char
- dec ix
- ld l,c
- ld h,b ;Result of division
- pop bc ;Recover counter
- djnz _hl2String
- ld b,5
- _palChk:
- dec b
- ld a,b
- ld (_palChk_offs+2),a ;SMC magic
- ld a,4
- sub a,b
- ld (_palChk_offs2+2),a ;SMC magic
- _palChk_offs2:
- ld a,(ix+0) ;SMC
- _palChk_offs:
- cp (ix+0) ;SMC
- ret nz
- inc ix
- djnz _palChk
- ret
- ;;divideHL10: divides HL by 10
- ;;Inputs:
- ;; HL=divisor
- ;;Outputs:
- ;; HL=HL%10
- ;; BC=HL/10
- ;;Modifies:
- ;; BC,DE,HL
- divideHL10:
- ld bc,0
- or a ;Reset carry for sbc
- _divHL10l:
- ld de,10
- sbc hl,de
- jr c,_divHL10r
- inc bc
- jr _divHL10l
- _divHL10r:
- add hl,de
- ret
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement