
;BCMP.ASM
;
;   If both source and dest are on longword boundries, and if the byte
;   count is a multiple of 4, then use longword operations.
;
;   if byte count < 16 then just use byte operations
;
;   BCMP(p1,p2,n)   return 0=failed, 1=compare ok

     xdef  _bcmp

_bcmp:
movem.l 4(A7),A0/A1;A0 = ptr1, A1 = ptr2
move.l12(A7),D1;# bytes
andi.b#3,15(A7);# bytes multiple of 4?
bneonbyte
andi.b#3,7(A7);ptr1 on lwb?
bneonbyte
andi.b#3,11(A7);ptr2 on lwb?
bneonbyte
lsr.l#2,D1;YES, LONG COMPARE LOOP
clr.lD0;default return. Also sets Z flag
bradropl
looplcmpm.l(A0)+,(A1)+
dropldbne.wD1,loopl
bneend
sub.l#$10000,D1
bplloopl
addq.l#1,D0;return TRUE
rts

onbyteclr.lD0;default return. Also sets Z flag
bradropb
loopbcmpm.b(A0)+,(A1)+;BYTE COMPARE
dropbdbne.wD1,loopb;until count exhausted or compare failed
bneend
sub.l#$10000,D1;for buffers >65535
bplloopb;branch to loop because D0.W now is FFFF
addq.l#1,D0;return TRUE
endrts


