Xref: utzoo comp.sys.ibm.pc:22782 comp.sys.intel:642 Path: utzoo!utgpu!watmath!mks!egisin From: egisin@mks.UUCP (Eric Gisin) Newsgroups: comp.sys.ibm.pc,comp.sys.intel Subject: Re: correct code for pointer subtraction Summary: shorter code Keywords: C pointer math DAMN WELL IS A BUG!!!! Message-ID: <631@mks.UUCP> Date: 5 Jan 89 20:46:23 GMT References: <597@mks.UUCP> <3845@pt.cs.cmu.edu> <18123@santra.UUCP> <51@rpi.edu> <147@bms-at.UUCP> Organization: Mortice Kern Systems, Waterloo, Ont. Lines: 17 In article <147@bms-at.UUCP>, stuart@bms-at.UUCP (Stuart Gathman) writes: < < xor dx,dx < mov ax,ptr1 < sub ax,ptr2 < sbb dx,0 ; carry extend < mov bx,n < idiv < < For the most common (2^n, 2*n) cases, this takes exactly as many bytes < and is just as fast as the wrong code. The general case is just 3 extra < bytes (and won't occur with word alignment). You can replace the xor and sbb with one sbb: sbb dx,dx That's only one byte longer than the incorrect code and it is just as fast.