Want to share this again because I think it's a work of art; in #Z80 detect if a 16-bit number in HL is outside a signed 8-bit range. "Just check if the hi-byte is non-zero!" you say, but what if the number is negative? -1 ($FFFF) is still the same number when clamped to 8-bits ($FF).
I like the way the A register is used even though whatever number is in the A register is irrelevant. It could be $00 or $42, the result is the same. We also only branch for errors, not for handling positive vs. negative separately.
(NB: your client might not render the markdown code included below)
```
sbc HL, BC ; do 'destination - PC'
; check for 8-bit signed bounds:
;-----------------------------------------------------------------------
; the carry-flag indicates if the jump is forward (clear) or backward
; (set). we set A to 0 or -1 ($FF) depending on carry-flag: any value
; minus itself is 0, but the carry-flag is an additional -1 (note that
; the initial value of A is meaningless here, the result is the same)
sbc A, A
; detect 8-bit overflow in either direction: if the distance is > 255
; then the hi-byte will not be all 1s (negative) or all 0s (positive)
; therefore we expect A = H. compare sets flags without changing A,
; allowing us to do two tests using the same A value!
cp H
jp nz, errRangeParam ; err if hi-byte is not 'empty'
; because the relative-distance byte is signed, we expect its sign
; to match that of the result -- a forward jump can only produce
; a positive distance; if the lo-byte is negative it's a positive
; distance that's too large (>127, i.e. hi-bit set)
xor L
jp m, errRangeParam ; if sign bits differ, error
; output relative-distance byte:
;-----------------------------------------------------------------------
ld [IY+0], L ; write relative distance byte
inc IY ; move to next byte in code-segment
inc IX ; increment virtual program-counter
ex DE, HL ; restore heap-addr to HL
ret
```