Better to test carry in stead of p/m, otherwise if de is large you will not get the result expected:
ld hl,4000
ld de,3000
or a ; this resets carry so sbc doesn’t deduct one extra
sbc hl,de
jr z,hl_equals_de
jr c,hl_lessthan_de
jr nc,hl_greaterthan_de
To test >=, simply remove the jr z and use the jr nc (as nc includes zero).
To test <=, you can replace the or a by scf (deducts 1 more) and then jr c.
Why the "or a", SBC does not "clean" the flags by its own?
It is used to reset the carry flag. Also and a is often used for the same purpose (I usually do). Please refer to the Z80 user manual on SBC for the reason to reset the carry flag :).
Why the "or a", SBC does not "clean" the flags by its own?
SBC means "subtract with carry". So, SBC HL,DE -> HL = HL - DE - CY. Unfortunately there's no SUB HL,DE instruction, so if you just want to get HL=HL-DE then you have to use SBC HL,DE with a non-set (i.e. 0) carry. Using the OR A instruction before clears the carry flag.